Skip to content

Commit

Permalink
[fix] allow $store to be used with changing values including nullish …
Browse files Browse the repository at this point in the history
…values
  • Loading branch information
ramonsnir committed Oct 14, 2022
1 parent bb83edd commit ee40146
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/runtime/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export function validate_store(store, name) {

export function subscribe(store, ...callbacks) {
if (store == null) {
for (const callback of callbacks) {
callback(store);
}
return noop;
}
const unsub = store.subscribe(...callbacks);
Expand Down
19 changes: 19 additions & 0 deletions test/runtime/samples/store-auto-subscribe-removed-store/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { writable } from '../../../../store';

export default {
html: `
<p>undefined</p>
`,
async test({ assert, component, target }) {
component.store = writable('foo');
await Promise.resolve();
assert.htmlEqual(target.innerHTML, `
<p>foo</p>
`);
component.store = undefined;
await Promise.resolve();
assert.htmlEqual(target.innerHTML, `
<p>undefined</p>
`);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
export let store;
</script>

<p>{$store}</p>

0 comments on commit ee40146

Please sign in to comment.