fix some await block stuff

pull/3945/head
Richard Harris 6 years ago
parent 1a81878f2b
commit 1d7dd6a6d3

@ -137,6 +137,9 @@ export default class AwaitBlockWrapper extends Wrapper {
block.maintain_context = true;
const value_index = this.node.value && block.renderer.add_to_context(this.node.value, true);
const error_index = this.node.error && block.renderer.add_to_context(this.node.error, true);
const info_props: any = x`{
ctx: #ctx,
current: null,
@ -144,8 +147,8 @@ export default class AwaitBlockWrapper extends Wrapper {
pending: ${this.pending.block.name},
then: ${this.then.block.name},
catch: ${this.catch.block.name},
value: ${this.then.block.name && x`"${this.node.value}"`},
error: ${this.catch.block.name && x`"${this.node.error}"`},
value: ${value_index},
error: ${error_index},
blocks: ${this.pending.block.has_outro_method && x`[,,,]`}
}`;
@ -197,9 +200,11 @@ export default class AwaitBlockWrapper extends Wrapper {
if (this.pending.block.has_update_method) {
block.chunks.update.push(b`
if (${condition}) {
// nothing
} else {
${info}.block.p(@assign(@assign({}, #ctx), ${info}.resolved), #changed);
const #child_ctx = #ctx.slice();
#child_ctx[${value_index}] = ${info}.resolved;
${info}.block.p(#child_ctx, #changed);
}
`);
} else {
@ -210,7 +215,11 @@ export default class AwaitBlockWrapper extends Wrapper {
} else {
if (this.pending.block.has_update_method) {
block.chunks.update.push(b`
${info}.block.p(@assign(@assign({}, #ctx), ${info}.resolved), #changed);
{
const #child_ctx = #ctx.slice();
#child_ctx[${value_index}] = ${info}.resolved;
${info}.block.p(#child_ctx, #changed);
}
`);
}
}

@ -111,12 +111,15 @@ export default class BindingWrapper {
{
const binding_group = get_binding_group(parent.renderer, this.node.expression.node);
block.renderer.add_to_context(`$$binding_groups`);
const reference = block.renderer.reference(`$$binding_groups`);
block.chunks.hydrate.push(
b`#ctx.$$binding_groups[${binding_group}].push(${parent.var});`
b`${reference}[${binding_group}].push(${parent.var});`
);
block.chunks.destroy.push(
b`#ctx.$$binding_groups[${binding_group}].splice(#ctx.$$binding_groups[${binding_group}].indexOf(${parent.var}), 1);`
b`${reference}[${binding_group}].splice(${reference}[${binding_group}].indexOf(${parent.var}), 1);`
);
break;
}

@ -9,9 +9,15 @@ export function handle_promise(promise, info) {
function update(type, index, key?, value?) {
if (info.token !== token) return;
info.resolved = key && { [key]: value };
info.resolved = value;
let child_ctx = info.ctx;
if (key !== undefined) {
child_ctx = child_ctx.slice();
child_ctx[key] = value;
}
const child_ctx = assign(assign({}, info.ctx), info.resolved);
const block = type && (info.current = type)(child_ctx);
let needs_flush = false;
@ -69,6 +75,6 @@ export function handle_promise(promise, info) {
return true;
}
info.resolved = { [info.value]: promise };
info.resolved = promise;
}
}

@ -5,7 +5,7 @@ export default {
promise
},
test({ assert, component, target }) {
test({ assert, target }) {
return promise.then(() => {
assert.htmlEqual(target.innerHTML, `
<p>42</p>

@ -1,6 +1,6 @@
<script>
import Widget from './Widget.svelte';
let promise = Promise.resolve(['a', 'b']);
export let promise = Promise.resolve(['a', 'b']);
let value;
</script>

Loading…
Cancel
Save