allow await blocks in slots - fixes #1014

pull/1018/head
Rich Harris 7 years ago
parent 9b09758f8c
commit 8c7e5b7758

@ -69,6 +69,7 @@ export default class AwaitBlock extends Node {
const name = this.var; const name = this.var;
const anchor = this.getOrCreateAnchor(block, parentNode); const anchor = this.getOrCreateAnchor(block, parentNode);
const updateMountNode = this.getUpdateMountNode(anchor);
const params = block.params.join(', '); const params = block.params.join(', ');
@ -107,7 +108,7 @@ export default class AwaitBlock extends Node {
${old_block}.u(); ${old_block}.u();
${old_block}.d(); ${old_block}.d();
${await_block}.c(); ${await_block}.c();
${await_block}.m(${parentNode || `${anchor}.parentNode`}, ${anchor}); ${await_block}.m(${updateMountNode}, ${anchor});
} }
} }

@ -0,0 +1,49 @@
let fulfil;
let thePromise = new Promise(f => {
fulfil = f;
});
export default {
data: {
thePromise
},
html: `
<p>loading...</p>
`,
test(assert, component, target) {
fulfil(42);
return thePromise
.then(() => {
assert.htmlEqual(target.innerHTML, `
<p>the value is 42</p>
`);
let reject;
thePromise = new Promise((f, r) => {
reject = r;
});
component.set({
thePromise
});
assert.htmlEqual(target.innerHTML, `
<p>loading...</p>
`);
reject(new Error('something broke'));
return thePromise.catch(() => {});
})
.then(() => {
assert.htmlEqual(target.innerHTML, `
<p>oh no! something broke</p>
`);
});
}
};

@ -0,0 +1,17 @@
<Foo>
{{#await thePromise}}
<p>loading...</p>
{{then theValue}}
<p>the value is {{theValue}}</p>
{{catch theError}}
<p>oh no! {{theError.message}}</p>
{{/await}}
</Foo>
<script>
import Foo from './Foo.html';
export default {
components: { Foo }
};
</script>
Loading…
Cancel
Save