Skip to content

Commit 88ef883

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

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
assert.htmlEqual(target.innerHTML, `
10+
<p>foo</p>
11+
`);
12+
component.store = undefined;
13+
assert.htmlEqual(target.innerHTML, `
14+
<p>undefined</p>
15+
`);
16+
component.store = writable('bar');
17+
assert.htmlEqual(target.innerHTML, `
18+
<p>bar</p>
19+
`);
20+
}
21+
};
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)