Skip to content

Commit 8c7e5b7

Browse files
committed
allow await blocks in slots - fixes #1014
1 parent 9b09758 commit 8c7e5b7

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

src/generators/nodes/AwaitBlock.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export default class AwaitBlock extends Node {
6969
const name = this.var;
7070

7171
const anchor = this.getOrCreateAnchor(block, parentNode);
72+
const updateMountNode = this.getUpdateMountNode(anchor);
7273

7374
const params = block.params.join(', ');
7475

@@ -107,7 +108,7 @@ export default class AwaitBlock extends Node {
107108
${old_block}.u();
108109
${old_block}.d();
109110
${await_block}.c();
110-
${await_block}.m(${parentNode || `${anchor}.parentNode`}, ${anchor});
111+
${await_block}.m(${updateMountNode}, ${anchor});
111112
}
112113
}
113114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<slot></slot>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
let fulfil;
2+
3+
let thePromise = new Promise(f => {
4+
fulfil = f;
5+
});
6+
7+
export default {
8+
data: {
9+
thePromise
10+
},
11+
12+
html: `
13+
<p>loading...</p>
14+
`,
15+
16+
test(assert, component, target) {
17+
fulfil(42);
18+
19+
return thePromise
20+
.then(() => {
21+
assert.htmlEqual(target.innerHTML, `
22+
<p>the value is 42</p>
23+
`);
24+
25+
let reject;
26+
27+
thePromise = new Promise((f, r) => {
28+
reject = r;
29+
});
30+
31+
component.set({
32+
thePromise
33+
});
34+
35+
assert.htmlEqual(target.innerHTML, `
36+
<p>loading...</p>
37+
`);
38+
39+
reject(new Error('something broke'));
40+
41+
return thePromise.catch(() => {});
42+
})
43+
.then(() => {
44+
assert.htmlEqual(target.innerHTML, `
45+
<p>oh no! something broke</p>
46+
`);
47+
});
48+
}
49+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Foo>
2+
{{#await thePromise}}
3+
<p>loading...</p>
4+
{{then theValue}}
5+
<p>the value is {{theValue}}</p>
6+
{{catch theError}}
7+
<p>oh no! {{theError.message}}</p>
8+
{{/await}}
9+
</Foo>
10+
11+
<script>
12+
import Foo from './Foo.html';
13+
14+
export default {
15+
components: { Foo }
16+
};
17+
</script>

0 commit comments

Comments
 (0)