-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
more conservative if block updates
- Loading branch information
Showing
10 changed files
with
211 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { sleep } from './sleep.js'; | ||
|
||
export default { | ||
html: ` | ||
<p>loading...</p> | ||
`, | ||
|
||
test({ assert, component, target }) { | ||
return sleep(50).then(() => { | ||
assert.htmlEqual(target.innerHTML, ` | ||
<p>the answer is 42</p> | ||
<p>count: 1</p> | ||
`); | ||
}); | ||
} | ||
}; |
19 changes: 19 additions & 0 deletions
19
test/runtime/samples/await-conservative-update/main.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,19 @@ | ||
<script> | ||
import { sleep } from './sleep.js'; | ||
let count = 0; | ||
const get_promise = () => { | ||
return sleep(10).then(() => { | ||
count += 1; | ||
return 42; | ||
}); | ||
}; | ||
</script> | ||
|
||
{#await get_promise()} | ||
<p>loading...</p> | ||
{:then value} | ||
<p>the answer is {value}</p> | ||
<p>count: {count}</p> | ||
{/await} |
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,11 @@ | ||
export let stopped = false; | ||
|
||
export const stop = () => stopped = true; | ||
|
||
export const sleep = ms => new Promise(f => { | ||
if (stopped) return; | ||
setTimeout(() => { | ||
if (stopped) return; | ||
f(); | ||
}, ms); | ||
}); |
22 changes: 22 additions & 0 deletions
22
test/runtime/samples/if-block-conservative-update/_config.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,22 @@ | ||
let count = 0; | ||
|
||
export default { | ||
props: { | ||
foo: 'potato', | ||
fn: () => { | ||
count += 1; | ||
return true; | ||
} | ||
}, | ||
|
||
html: `<p>potato</p>`, | ||
|
||
test({ assert, component, target }) { | ||
assert.equal(count, 1); | ||
|
||
component.foo = 'soup'; | ||
assert.equal(count, 1); | ||
|
||
assert.htmlEqual(target.innerHTML, `<p>soup</p>`); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
test/runtime/samples/if-block-conservative-update/main.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,8 @@ | ||
<script> | ||
export let fn; | ||
export let foo; | ||
</script> | ||
|
||
{#if fn()} | ||
<p>{foo}</p> | ||
{/if} |
37 changes: 37 additions & 0 deletions
37
test/runtime/samples/if-block-else-conservative-update/_config.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,37 @@ | ||
let a = true; | ||
let count_a = 0; | ||
let count_b = 0; | ||
|
||
export default { | ||
props: { | ||
foo: 'potato', | ||
fn: () => { | ||
count_a += 1; | ||
return a; | ||
}, | ||
other_fn: () => { | ||
count_b += 1; | ||
return true; | ||
} | ||
}, | ||
|
||
html: `<p>potato</p>`, | ||
|
||
test({ assert, component, target }) { | ||
assert.equal(count_a, 1); | ||
assert.equal(count_b, 0); | ||
|
||
a = false; | ||
component.foo = 'soup'; | ||
assert.equal(count_a, 2); | ||
assert.equal(count_b, 1); | ||
|
||
assert.htmlEqual(target.innerHTML, `<p>SOUP</p>`); | ||
|
||
component.foo = 'salad'; | ||
assert.equal(count_a, 3); | ||
assert.equal(count_b, 1); | ||
|
||
assert.htmlEqual(target.innerHTML, `<p>SALAD</p>`); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
test/runtime/samples/if-block-else-conservative-update/main.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,11 @@ | ||
<script> | ||
export let fn; | ||
export let other_fn; | ||
export let foo; | ||
</script> | ||
|
||
{#if fn(foo)} | ||
<p>{foo}</p> | ||
{:else if other_fn()} | ||
<p>{foo.toUpperCase()}</p> | ||
{/if} |