prevent await blocks using stale state - fixes #1131

pull/1150/head
Rich Harris 8 years ago
parent 37d5260036
commit bf25248f9e

@ -127,8 +127,10 @@ export default class AwaitBlock extends Node {
if (@isPromise(${promise})) {
${promise}.then(function(${value}) {
var state = #component.get();
${replace_await_block}(${token}, ${create_then_block}, ${value}, ${params});
}, function (${error}) {
var state = #component.get();
${replace_await_block}(${token}, ${create_catch_block}, ${error}, ${params});
});

@ -0,0 +1,16 @@
export default {
test(assert, component, target) {
const promise = Promise.resolve().then(() => component.set({ answer: 42 }));
component.set({ promise });
assert.htmlEqual(target.innerHTML, `<p>wait for it...</p>`);
return promise
.then(() => {
assert.htmlEqual(target.innerHTML, `
<p>the answer is 42!</p>
`);
});
}
};

@ -0,0 +1,9 @@
{{#if promise}}
{{#await promise}}
<p>wait for it...</p>
{{then _}}
<p>the answer is {{answer}}!</p>
{{catch error}}
<p>well that's odd</p>
{{/await}}
{{/if}}
Loading…
Cancel
Save