Skip to content

Commit

Permalink
Merge pull request #1150 from sveltejs/gh-1131
Browse files Browse the repository at this point in the history
prevent await blocks using stale state
  • Loading branch information
Rich-Harris authored Feb 4, 2018
2 parents 37d5260 + bf25248 commit 29a1569
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/generators/nodes/AwaitBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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});
});
Expand Down
16 changes: 16 additions & 0 deletions test/runtime/samples/await-set-simultaneous/_config.js
Original file line number Diff line number Diff line change
@@ -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>
`);
});
}
};
9 changes: 9 additions & 0 deletions test/runtime/samples/await-set-simultaneous/main.html
Original file line number Diff line number Diff line change
@@ -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}}

0 comments on commit 29a1569

Please sign in to comment.