Skip to content

Commit ee40146

Browse files
committed
[fix] allow $store to be used with changing values including nullish values
1 parent bb83edd commit ee40146

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/runtime/internal/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ export function validate_store(store, name) {
6666

6767
export function subscribe(store, ...callbacks) {
6868
if (store == null) {
69+
for (const callback of callbacks) {
70+
callback(store);
71+
}
6972
return noop;
7073
}
7174
const unsub = store.subscribe(...callbacks);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { writable } from '../../../../store';
2+
3+
export default {
4+
html: `
5+
<p>undefined</p>
6+
`,
7+
async test({ assert, component, target }) {
8+
component.store = writable('foo');
9+
await Promise.resolve();
10+
assert.htmlEqual(target.innerHTML, `
11+
<p>foo</p>
12+
`);
13+
component.store = undefined;
14+
await Promise.resolve();
15+
assert.htmlEqual(target.innerHTML, `
16+
<p>undefined</p>
17+
`);
18+
}
19+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
export let store;
3+
</script>
4+
5+
<p>{$store}</p>

0 commit comments

Comments
 (0)