[fix] allow $store to be used with changing values including nullish values

pull/7947/head
Ramon Snir 4 years ago
parent bb83eddfc6
commit 88ef883f6a

@ -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);

@ -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>
`);
}
};

@ -0,0 +1,5 @@
<script>
export let store;
</script>
<p>{$store}</p>
Loading…
Cancel
Save