Skip to content

Commit 49bc092

Browse files
authored
Merge pull request #1094 from sveltejs/gh-1061-b
fire oncreate handlers for components inside await blocks
2 parents 2537db9 + c1b5bed commit 49bc092

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

src/generators/nodes/AwaitBlock.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ export default class AwaitBlock extends Node {
101101
block.addVariable(promise);
102102
block.addVariable(resolved);
103103

104+
// the `#component.root.set({})` below is just a cheap way to flush
105+
// any oncreate handlers. We could have a dedicated `flush()` method
106+
// but it's probably not worth it
107+
104108
block.builders.init.addBlock(deindent`
105109
function ${replace_await_block}(${token}, type, ${value}, ${params}) {
106110
if (${token} !== ${await_token}) return;
@@ -113,6 +117,8 @@ export default class AwaitBlock extends Node {
113117
${old_block}.d();
114118
${await_block}.c();
115119
${await_block}.m(${updateMountNode}, ${anchor});
120+
121+
#component.root.set({});
116122
}
117123
}
118124
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<p>{{value}}</p>
2+
<p>{{called}}</p>
3+
4+
<script>
5+
export default {
6+
data() {
7+
return { called: false };
8+
},
9+
10+
oncreate() {
11+
this.set({ called: true });
12+
}
13+
};
14+
</script>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const promise = Promise.resolve(42);
2+
3+
export default {
4+
data: {
5+
promise
6+
},
7+
8+
test(assert, component, target) {
9+
return promise.then(() => {
10+
assert.htmlEqual(target.innerHTML, `
11+
<p>42</p>
12+
<p>true</p>
13+
`);
14+
});
15+
}
16+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{#await promise then value}}
2+
<Foo :value />
3+
{{/await}}
4+
5+
<script>
6+
import Foo from './Foo.html';
7+
8+
export default {
9+
components: {
10+
Foo
11+
}
12+
};
13+
</script>

0 commit comments

Comments
 (0)