correctly mount await block that has an anchor

pull/952/head
Rich Harris 7 years ago
parent 82fc0f2713
commit 844e89f277

@ -110,7 +110,7 @@ export default function visitAwaitBlock(
const anchorNode = state.parentNode ? 'null' : 'anchor';
block.builders.mount.addBlock(deindent`
${await_block}.m(${targetNode}, ${anchor});
${await_block}.m(${targetNode}, ${anchorNode});
`);
const conditions = [];

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

@ -0,0 +1,15 @@
{{#await thePromise}}
<p>loading...</p>
{{then theValue}}
<p>the value is {{theValue}}</p>
{{catch theError}}
<p>oh no! {{theError.message}}</p>
{{/await}}
{{#await thePromise}}
<p>loading...</p>
{{then theValue}}
<p>the value is {{theValue}}</p>
{{catch theError}}
<p>oh no! {{theError.message}}</p>
{{/await}}
Loading…
Cancel
Save