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 16, 2022
1 parent bb83edd commit 88ef883
Show file tree
Hide file tree
Showing 3 changed files with 29 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
21 changes: 21 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,21 @@
import { writable } from '../../../../store';

export default {
html: `
<p>undefined</p>
`,
async test({ assert, component, target }) {
component.store = writable('foo');
assert.htmlEqual(target.innerHTML, `
<p>foo</p>
`);
component.store = undefined;
assert.htmlEqual(target.innerHTML, `
<p>undefined</p>
`);
component.store = writable('bar');
assert.htmlEqual(target.innerHTML, `
<p>bar</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 88ef883

Please sign in to comment.