Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow await blocks in slots #1018

Merged
merged 2 commits into from
Dec 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/generators/nodes/AwaitBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(', ');

Expand Down Expand Up @@ -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});
}
}

Expand Down
1 change: 0 additions & 1 deletion src/generators/nodes/Text.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions test/runtime/samples/await-then-catch-in-slot/Foo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<slot></slot>
49 changes: 49 additions & 0 deletions test/runtime/samples/await-then-catch-in-slot/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
let fulfil;

let thePromise = new Promise(f => {
fulfil = f;
});

export default {
data: {
thePromise
},

html: `
<p>loading...</p>
`,

test(assert, component, target) {
fulfil(42);

return thePromise
.then(() => {
assert.htmlEqual(target.innerHTML, `
<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>
`);

reject(new Error('something broke'));

return thePromise.catch(() => {});
})
.then(() => {
assert.htmlEqual(target.innerHTML, `
<p>oh no! something broke</p>
`);
});
}
};
17 changes: 17 additions & 0 deletions test/runtime/samples/await-then-catch-in-slot/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Foo>
{{#await thePromise}}
<p>loading...</p>
{{then theValue}}
<p>the value is {{theValue}}</p>
{{catch theError}}
<p>oh no! {{theError.message}}</p>
{{/await}}
</Foo>

<script>
import Foo from './Foo.html';

export default {
components: { Foo }
};
</script>