From 9b09758f8c274cfa1c060785ddbbb6809dadf53e Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 12 Dec 2017 19:51:57 -0500 Subject: [PATCH 1/2] remove unused import --- src/generators/nodes/Text.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/generators/nodes/Text.ts b/src/generators/nodes/Text.ts index 2a68656836..f3f0c3968c 100644 --- a/src/generators/nodes/Text.ts +++ b/src/generators/nodes/Text.ts @@ -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 From 8c7e5b7758b88414b0d29b0b1ce7d85913dec8a4 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 12 Dec 2017 20:01:24 -0500 Subject: [PATCH 2/2] allow await blocks in slots - fixes #1014 --- src/generators/nodes/AwaitBlock.ts | 3 +- .../samples/await-then-catch-in-slot/Foo.html | 1 + .../await-then-catch-in-slot/_config.js | 49 +++++++++++++++++++ .../await-then-catch-in-slot/main.html | 17 +++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/await-then-catch-in-slot/Foo.html create mode 100644 test/runtime/samples/await-then-catch-in-slot/_config.js create mode 100644 test/runtime/samples/await-then-catch-in-slot/main.html diff --git a/src/generators/nodes/AwaitBlock.ts b/src/generators/nodes/AwaitBlock.ts index 61fa2f053e..f47f5de61b 100644 --- a/src/generators/nodes/AwaitBlock.ts +++ b/src/generators/nodes/AwaitBlock.ts @@ -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}); } } diff --git a/test/runtime/samples/await-then-catch-in-slot/Foo.html b/test/runtime/samples/await-then-catch-in-slot/Foo.html new file mode 100644 index 0000000000..49aeb95a1d --- /dev/null +++ b/test/runtime/samples/await-then-catch-in-slot/Foo.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/runtime/samples/await-then-catch-in-slot/_config.js b/test/runtime/samples/await-then-catch-in-slot/_config.js new file mode 100644 index 0000000000..ed467b0382 --- /dev/null +++ b/test/runtime/samples/await-then-catch-in-slot/_config.js @@ -0,0 +1,49 @@ +let fulfil; + +let thePromise = new Promise(f => { + fulfil = f; +}); + +export default { + data: { + thePromise + }, + + html: ` +

loading...

+ `, + + test(assert, component, target) { + fulfil(42); + + return thePromise + .then(() => { + assert.htmlEqual(target.innerHTML, ` +

the value is 42

+ `); + + let reject; + + thePromise = new Promise((f, r) => { + reject = r; + }); + + component.set({ + thePromise + }); + + assert.htmlEqual(target.innerHTML, ` +

loading...

+ `); + + reject(new Error('something broke')); + + return thePromise.catch(() => {}); + }) + .then(() => { + assert.htmlEqual(target.innerHTML, ` +

oh no! something broke

+ `); + }); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/await-then-catch-in-slot/main.html b/test/runtime/samples/await-then-catch-in-slot/main.html new file mode 100644 index 0000000000..34519e8c23 --- /dev/null +++ b/test/runtime/samples/await-then-catch-in-slot/main.html @@ -0,0 +1,17 @@ + + {{#await thePromise}} +

loading...

+ {{then theValue}} +

the value is {{theValue}}

+ {{catch theError}} +

oh no! {{theError.message}}

+ {{/await}} +
+ + \ No newline at end of file