-
-
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.
Merge pull request #694 from sveltejs/oncreate-before-bindings
Call `oncreate` functions before updating bindings
- Loading branch information
Showing
23 changed files
with
177 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
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
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
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,15 @@ | ||
<Two bind:foo/> | ||
|
||
<script> | ||
import Two from './Two.html'; | ||
|
||
export default { | ||
components: { | ||
Two | ||
}, | ||
|
||
oncreate() { | ||
this.snapshot = this.get('foo'); | ||
} | ||
}; | ||
</script> |
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,15 @@ | ||
<script> | ||
export default { | ||
data() { | ||
return { | ||
bar: 1 | ||
}; | ||
}, | ||
|
||
computed: { | ||
foo(bar) { | ||
return bar * 2; | ||
} | ||
} | ||
}; | ||
</script> |
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,5 @@ | ||
export default { | ||
test(assert, component) { | ||
assert.equal(component.refs.one.snapshot, 2); | ||
} | ||
}; |
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,9 @@ | ||
<One ref:one/> | ||
|
||
<script> | ||
import One from './One.html'; | ||
|
||
export default { | ||
components: { One } | ||
}; | ||
</script> |
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,30 @@ | ||
{{#each things as thing}} | ||
<Visibility bind:isVisible="visibilityMap[thing]"> | ||
<p>{{thing}} ({{visibilityMap[thing]}})</p> | ||
</Visibility> | ||
{{/each}} | ||
|
||
<script> | ||
import Visibility from './Visibility.html'; | ||
import counter from './counter.js'; | ||
|
||
export default { | ||
data() { | ||
return { | ||
things: ['first thing', 'second thing'], | ||
visibilityMap: {} | ||
}; | ||
}, | ||
|
||
computed: { | ||
visibleThings: (things, visibilityMap) => { | ||
counter.count += 1; | ||
return things.filter(text => visibilityMap[text]); | ||
} | ||
}, | ||
|
||
components: { | ||
Visibility | ||
} | ||
}; | ||
</script> |
11 changes: 11 additions & 0 deletions
11
test/runtime/samples/flush-before-bindings/Visibility.html
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 @@ | ||
<div> | ||
{{yield}} | ||
</div> | ||
|
||
<script> | ||
export default { | ||
oncreate() { | ||
this.set({ isVisible: true }); | ||
} | ||
}; | ||
</script> |
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 @@ | ||
import counter from './counter.js'; | ||
|
||
export default { | ||
'skip-ssr': true, | ||
|
||
html: ` | ||
<div><p>first thing (true)</p></div> | ||
<div><p>second thing (true)</p></div> | ||
`, | ||
|
||
test(assert, component) { | ||
const visibleThings = component.get('visibleThings'); | ||
assert.deepEqual(visibleThings, ['first thing', 'second thing']); | ||
|
||
const snapshots = component.snapshots; | ||
assert.deepEqual(snapshots, [visibleThings]); | ||
|
||
// TODO minimise the number of recomputations during oncreate | ||
// assert.equal(counter.count, 1); | ||
} | ||
}; |
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,3 @@ | ||
export default { | ||
count: 0 | ||
}; |
Oops, something went wrong.