fix store reactivity in reactive declarations

pull/6559/head
Tan Li Hau 5 years ago
parent b2260bc2e3
commit 46d5c3865a

@ -666,8 +666,13 @@ 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 sorted_globals = Array.from(globals.keys()).sort().reverse();
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 storeContainer;
$: ({ store } = storeContainer);
$: 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.updateValue('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 storeContainer = { store: writable('Hello World') }
export function updateValue(value) {
storeContainer.store = writable(value);
}
</script>
<Child {storeContainer} />
Loading…
Cancel
Save