Merge pull request #1018 from sveltejs/gh-1014

allow await blocks in slots
pull/1021/head
Rich Harris 7 years ago committed by GitHub
commit b252e3378f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

@ -1,7 +1,6 @@
import { stringify } from '../../utils/stringify';
import Node from './shared/Node';
import Block from '../dom/Block';
import { State } from '../dom/interfaces';
// Whitespace inside one of these elements will not result in
// a whitespace node being created in any circumstances. (This

@ -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