Merge branch 'await-then-catch-order' of https://github.com/RedHatter/svelte into RedHatter-await-then-catch-order

pull/1887/head
Rich Harris 6 years ago
commit 327a58128a

@ -174,6 +174,9 @@ export default class AwaitBlockWrapper extends Wrapper {
block.builders.mount.addBlock(deindent` block.builders.mount.addBlock(deindent`
${info}.block.${hasTransitions ? 'i' : 'm'}(${initialMountNode}, ${info}.anchor = ${anchorNode}); ${info}.block.${hasTransitions ? 'i' : 'm'}(${initialMountNode}, ${info}.anchor = ${anchorNode});
${info}.mount = () => ${updateMountNode}; ${info}.mount = () => ${updateMountNode};
if (${info}.anchor == null) {
${info}.anchor = ${anchor};
}
`); `);
const conditions = []; const conditions = [];

@ -0,0 +1,27 @@
let fulfil;
let thePromise = new Promise(f => {
fulfil = f;
});
export default {
data: {
thePromise
},
html: `
<p>loading...</p><p>true!</p>
`,
test(assert, component, target) {
fulfil(42);
return thePromise
.then(() => {
assert.htmlEqual(target.innerHTML, `
<p>the value is 42</p><p>true!</p>
`);
});
}
};

@ -0,0 +1,11 @@
{#await thePromise}
<p>loading...</p>
{:then theValue}
<p>the value is {theValue}</p>
{:catch theError}
<p>oh no! {theError.message}</p>
{/await}
{#if true}
<p>true!</p>
{/if}

@ -26,10 +26,10 @@ export default {
return promise.then(() => { return promise.then(() => {
raf.tick(80); raf.tick(80);
let ps = document.querySelectorAll('p'); let ps = document.querySelectorAll('p');
assert.equal(ps[0].className, 'pending'); assert.equal(ps[1].className, 'pending');
assert.equal(ps[1].className, 'then'); assert.equal(ps[0].className, 'then');
assert.equal(ps[0].foo, 0.2); assert.equal(ps[1].foo, 0.2);
assert.equal(ps[1].foo, 0.3); assert.equal(ps[0].foo, 0.3);
}); });
} }
}; };

Loading…
Cancel
Save