Skip to content

Commit

Permalink
handle destructure to a store value
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed Sep 24, 2020
1 parent 4c135b0 commit f09c47a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/compiler/compile/render_dom/invalidate.ts
Expand Up @@ -46,6 +46,7 @@ export function invalidate(renderer: Renderer, scope: Scope, node: Node, names:
const extra_args = tail.map(variable => get_invalidated(variable)).filter(Boolean);

const pass_value = (
!is_store_value &&
!main_execution_context &&
(
extra_args.length > 0 ||
Expand All @@ -62,7 +63,7 @@ export function invalidate(renderer: Renderer, scope: Scope, node: Node, names:
}

let invalidate = is_store_value
? x`@set_store_value(${head.name.slice(1)}, ${node}, ${head.name})`
? x`@set_store_value(${head.name.slice(1)}, ${node}, ${head.name}, ${extra_args})`
: !main_execution_context
? x`$$invalidate(${renderer.context_lookup.get(head.name).index}, ${node}, ${extra_args})`
: extra_args.length
Expand Down
@@ -0,0 +1,9 @@
// destructure to store value
export default {
skip_if_ssr: true,
html: `<h1>2 2 xxx 5 6 9 10 2</h1>`,
async test({ assert, target, component }) {
await component.update();
assert.htmlEqual(target.innerHTML, `<h1>11 11 yyy 12 13 14 15 11</h1>`);
}
};
@@ -0,0 +1,29 @@
<script>
import { writable } from 'svelte/store';
let eid = writable(1);
let foo;
let u = writable(2);
let v = writable(3);
let w = writable(4);
let x = writable(5);
let y = writable(6);
[$u, $v, $w] = [
{id: eid = writable(foo = 2), name: 'xxx'},
5,
6
];
({ a: $x, b: $y } = { a: 9, b: 10 });
$: z = $u.id;
export function update() {
[$u, $v, $w] = [
{id: eid = writable(foo = 11), name: 'yyy'},
12,
13
];
({ a: $x, b: $y } = { a: 14, b: 15 });
}
</script>

<h1>{foo} {$eid} {$u.name} {$v} {$w} {$x} {$y} {$z}</h1>
@@ -1,3 +1,9 @@
// destructure to store
export default {
html: `<h1>2 2 xxx 5 6</h1>`
html: `<h1>2 2 xxx 5 6 9 10 2</h1>`,
skip_if_ssr: true,
async test({ assert, target, component }) {
await component.update();
assert.htmlEqual(target.innerHTML, `<h1>11 11 yyy 12 13 14 15 11</h1>`);
}
};
Expand Up @@ -6,11 +6,24 @@
let u;
let v;
let w;
let x;
let y;
[u, v, w] = [
{id: eid = writable(foo = 2), name: 'xxx'},
5,
writable(6)
];
({ a: x, b: y } = { a: writable(9), b: writable(10) });
$: z = u.id;
export function update() {
[u, v, w] = [
{id: eid = writable(foo = 11), name: 'yyy'},
12,
writable(13)
];
({ a: x, b: y } = { a: writable(14), b: writable(15) });
}
</script>

<h1>{foo} {$eid} {u.name} {v} {$w}</h1>
<h1>{foo} {$eid} {u.name} {v} {$w} {$x} {$y} {$z}</h1>

0 comments on commit f09c47a

Please sign in to comment.