-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2865 from sveltejs/less-invalidation
only invalidate referenced values
- Loading branch information
Showing
11 changed files
with
152 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
test/js/samples/reactive-values-non-writable-dependencies/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
<script> | ||
let a = 1; | ||
let b = 2; | ||
export let a = 1; | ||
export let b = 2; | ||
|
||
let max; | ||
$: max = Math.max(a, b); | ||
$: console.log('max', Math.max(a, b)); | ||
</script> |
78 changes: 78 additions & 0 deletions
78
test/js/samples/unreferenced-state-not-invalidated/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* generated by Svelte vX.Y.Z */ | ||
import { | ||
SvelteComponent, | ||
append, | ||
detach, | ||
element, | ||
init, | ||
insert, | ||
noop, | ||
safe_not_equal, | ||
set_data, | ||
text | ||
} from "svelte/internal"; | ||
import { onMount } from "svelte"; | ||
|
||
function create_fragment(ctx) { | ||
var p, t; | ||
|
||
return { | ||
c() { | ||
p = element("p"); | ||
t = text(ctx.y); | ||
}, | ||
|
||
m(target, anchor) { | ||
insert(target, p, anchor); | ||
append(p, t); | ||
}, | ||
|
||
p(changed, ctx) { | ||
if (changed.y) { | ||
set_data(t, ctx.y); | ||
} | ||
}, | ||
|
||
i: noop, | ||
o: noop, | ||
|
||
d(detaching) { | ||
if (detaching) { | ||
detach(p); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
function instance($$self, $$props, $$invalidate) { | ||
let a, b, c; | ||
|
||
onMount(() => { | ||
const interval = setInterval(() => { | ||
$$invalidate('b', b += 1); | ||
c += 1; | ||
|
||
console.log(b, c); | ||
}, 1000); | ||
|
||
return () => clearInterval(interval); | ||
}); | ||
|
||
let x, y; | ||
|
||
$$self.$$.update = ($$dirty = { a: 1, b: 1 }) => { | ||
if ($$dirty.a) { x = a * 2; } | ||
if ($$dirty.b) { $$invalidate('y', y = b * 2); } | ||
}; | ||
|
||
return { y }; | ||
} | ||
|
||
class Component extends SvelteComponent { | ||
constructor(options) { | ||
super(); | ||
init(this, options, instance, create_fragment, safe_not_equal, []); | ||
} | ||
} | ||
|
||
export default Component; |
21 changes: 21 additions & 0 deletions
21
test/js/samples/unreferenced-state-not-invalidated/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script> | ||
import { onMount } from 'svelte'; | ||
|
||
let a, b, c; | ||
|
||
onMount(() => { | ||
const interval = setInterval(() => { | ||
b += 1; | ||
c += 1; | ||
|
||
console.log(b, c); | ||
}, 1000); | ||
|
||
return () => clearInterval(interval); | ||
}); | ||
|
||
$: x = a * 2; | ||
$: y = b * 2; | ||
</script> | ||
|
||
<p>{y}</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,35 @@ | ||
export default { | ||
immutable: true, | ||
|
||
html: `<div><h3>Called 1 times.</h3></div>`, | ||
html: ` | ||
<div> | ||
<h3>Called 1 times.</h3> | ||
<p>baz true</p> | ||
</div> | ||
`, | ||
|
||
ssrHtml: `<div><h3>Called 0 times.</h3></div>`, | ||
ssrHtml: ` | ||
<div> | ||
<h3>Called 0 times.</h3> | ||
<p>baz false</p> | ||
</div>`, | ||
|
||
test({ assert, component, target, window }) { | ||
test({ assert, component, target }) { | ||
var nested = component.nested; | ||
|
||
assert.htmlEqual(target.innerHTML, `<div><h3>Called 1 times.</h3></div>`); | ||
assert.htmlEqual(target.innerHTML, ` | ||
<div> | ||
<h3>Called 1 times.</h3> | ||
<p>baz true</p> | ||
</div> | ||
`); | ||
|
||
nested.foo = nested.foo; | ||
assert.htmlEqual(target.innerHTML, `<div><h3>Called 1 times.</h3></div>`); | ||
assert.htmlEqual(target.innerHTML, ` | ||
<div> | ||
<h3>Called 1 times.</h3> | ||
<p>baz true</p> | ||
</div> | ||
`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,5 @@ | |
</script> | ||
|
||
<div> | ||
<Nested bind:this={nested} /> | ||
<Nested bind:this={nested} /> | ||
</div> |