[fix] store reactivity in reactive declarations (#6559)

pull/6563/head
Tan Li Hau 4 years ago committed by GitHub
parent d487254beb
commit 365b5e300c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -666,8 +666,17 @@ export default class Component {
this.node_for_declaration.set(name, node);
});
globals.forEach((node, name) => {
// NOTE: add store variable first, then only $store value
// as `$store` will mark `store` variable as referenced and subscribable
const global_keys = Array.from(globals.keys());
const sorted_globals = [
...global_keys.filter(key => key[0] !== '$'),
...global_keys.filter(key => key[0] === '$')
];
sorted_globals.forEach(name => {
if (this.var_lookup.has(name)) return;
const node = globals.get(name);
if (this.injected_reactive_declaration_vars.has(name)) {
this.add_var({

@ -0,0 +1,8 @@
<script>
export let store_container;
$: ({ store } = store_container);
$: value = $store;
</script>
<div>{value}</div>
<div>{$store}</div>

@ -0,0 +1,15 @@
export default {
html: `
<div>Hello World</div>
<div>Hello World</div>
`,
async test({ assert, component, target, window }) {
await component.update_value('Hi Svelte');
assert.htmlEqual(target.innerHTML, `
<div>Hi Svelte</div>
<div>Hi Svelte</div>
`);
}
};

@ -0,0 +1,12 @@
<script>
import { writable } from 'svelte/store';
import Child from './App.svelte';
const store_container = { store: writable('Hello World') };
export function update_value(value) {
store_container.store = writable(value);
}
</script>
<Child {store_container} />
Loading…
Cancel
Save