pull/3539/head
Richard Harris 6 years ago
parent 3470005c29
commit 2adcdfb2bf

@ -144,8 +144,8 @@ export default class AwaitBlockWrapper extends Wrapper {
pending: ${this.pending.block.name}, pending: ${this.pending.block.name},
then: ${this.then.block.name}, then: ${this.then.block.name},
catch: ${this.catch.block.name}, catch: ${this.catch.block.name},
value: ${this.then.block.name && this.node.value}, value: ${this.then.block.name && x`"${this.node.value}"`},
error: ${this.catch.block.name && this.node.error}, error: ${this.catch.block.name && x`"${this.node.error}"`},
blocks: ${this.pending.block.has_outro_method && x`[,,,]`} blocks: ${this.pending.block.has_outro_method && x`[,,,]`}
}`; }`;

@ -491,11 +491,11 @@ export default class EachBlockWrapper extends Wrapper {
? b` ? b`
if (${iterations}[#i]) { if (${iterations}[#i]) {
${iterations}[#i].p(changed, child_ctx); ${iterations}[#i].p(changed, child_ctx);
${has_transitions && `@transition_in(${this.vars.iterations}[#i], 1);`} ${has_transitions && b`@transition_in(${this.vars.iterations}[#i], 1);`}
} else { } else {
${iterations}[#i] = ${create_each_block}(child_ctx); ${iterations}[#i] = ${create_each_block}(child_ctx);
${iterations}[#i].c(); ${iterations}[#i].c();
${has_transitions && `@transition_in(${this.vars.iterations}[#i], 1);`} ${has_transitions && b`@transition_in(${this.vars.iterations}[#i], 1);`}
${iterations}[#i].m(${update_mount_node}, ${update_anchor_node}); ${iterations}[#i].m(${update_mount_node}, ${update_anchor_node});
} }
` `

@ -631,7 +631,7 @@ export default class ElementWrapper extends Wrapper {
if (intro === outro) { if (intro === outro) {
// bidirectional transition // bidirectional transition
const name = block.get_unique_name(`${this.var}_transition`); const name = block.get_unique_name(`${this.var.name}_transition`);
const snippet = intro.expression const snippet = intro.expression
? intro.expression.manipulate(block) ? intro.expression.manipulate(block)
: '{}'; : '{}';

@ -248,7 +248,9 @@ export default class IfBlockWrapper extends Wrapper {
) { ) {
const select_block_type = this.renderer.component.get_unique_name(`select_block_type`); const select_block_type = this.renderer.component.get_unique_name(`select_block_type`);
const current_block_type = block.get_unique_name(`current_block_type`); const current_block_type = block.get_unique_name(`current_block_type`);
const current_block_type_and = has_else ? '' : `${current_block_type} && `; const get_block = has_else
? x`${current_block_type} && ${current_block_type}(#ctx)`
: x`${current_block_type}(#ctx)`
/* eslint-disable @typescript-eslint/indent,indent */ /* eslint-disable @typescript-eslint/indent,indent */
if (this.needs_update) { if (this.needs_update) {
@ -258,19 +260,19 @@ export default class IfBlockWrapper extends Wrapper {
? b` ? b`
${snippet && ( ${snippet && (
dependencies.length > 0 dependencies.length > 0
? `if ((${condition} == null) || ${dependencies.map(n => `changed.${n}`).join(' || ')}) ${condition} = !!(${snippet})` ? b`if ((${condition} == null) || ${dependencies.map(n => `changed.${n}`).join(' || ')}) ${condition} = !!(${snippet})`
: `if (${condition} == null) ${condition} = !!(${snippet})` : b`if (${condition} == null) ${condition} = !!(${snippet})`
)} )}
if (${condition}) return ${block.name};` if (${condition}) return ${block.name};`
: `return ${block.name};`)} : b`return ${block.name};`)}
} }
`); `);
} else { } else {
block.chunks.init.push(b` block.chunks.init.push(b`
function ${select_block_type}(#changed, #ctx) { function ${select_block_type}(#changed, #ctx) {
${this.branches.map(({ condition, snippet, block }) => condition ${this.branches.map(({ condition, snippet, block }) => condition
? `if (${snippet || condition}) return ${block.name};` ? b`if (${snippet || condition}) return ${block.name};`
: `return ${block.name};`)} : b`return ${block.name};`)}
} }
`); `);
} }
@ -278,7 +280,7 @@ export default class IfBlockWrapper extends Wrapper {
block.chunks.init.push(b` block.chunks.init.push(b`
let ${current_block_type} = ${select_block_type}(null, #ctx); let ${current_block_type} = ${select_block_type}(null, #ctx);
let ${name} = ${current_block_type_and}${current_block_type}(#ctx); let ${name} = ${get_block};
`); `);
const initial_mount_node = parent_node || '#target'; const initial_mount_node = parent_node || '#target';
@ -291,11 +293,11 @@ export default class IfBlockWrapper extends Wrapper {
const update_mount_node = this.get_update_mount_node(anchor); const update_mount_node = this.get_update_mount_node(anchor);
const change_block = b` const change_block = b`
${if_exists_condition}${name}.d(1); if (${if_exists_condition}) ${name}.d(1);
${name} = ${current_block_type_and}${current_block_type}(#ctx); ${name} = ${get_block};
if (${name}) { if (${name}) {
${name}.c(); ${name}.c();
${has_transitions && `@transition_in(${name}, 1);`} ${has_transitions && b`@transition_in(${name}, 1);`}
${name}.m(${update_mount_node}, ${anchor}); ${name}.m(${update_mount_node}, ${anchor});
} }
`; `;
@ -358,18 +360,18 @@ export default class IfBlockWrapper extends Wrapper {
function ${select_block_type}(#changed, #ctx) { function ${select_block_type}(#changed, #ctx) {
${this.branches.map(({ dependencies, condition, snippet }, i) => condition ${this.branches.map(({ dependencies, condition, snippet }, i) => condition
? b` ? b`
${snippet && `if ((${condition} == null) || ${dependencies.map(n => `changed.${n}`).join(' || ')}) ${condition} = !!(${snippet})`} ${snippet && b`if ((${condition} == null) || ${dependencies.map(n => `changed.${n}`).join(' || ')}) ${condition} = !!(${snippet})`}
if (${condition}) return ${String(i)};` if (${condition}) return ${String(i)};`
: `return ${i};`)} : b`return ${i};`)}
${!has_else && `return -1;`} ${!has_else && b`return -1;`}
} }
` `
: b` : b`
function ${select_block_type}(#changed, #ctx) { function ${select_block_type}(#changed, #ctx) {
${this.branches.map(({ condition, snippet }, i) => condition ${this.branches.map(({ condition, snippet }, i) => condition
? `if (${snippet || condition}) return ${String(i)};` ? b`if (${snippet || condition}) return ${String(i)};`
: `return ${i};`)} : b`return ${i};`)}
${!has_else && `return -1;`} ${!has_else && b`return -1;`}
} }
`} `}
`); `);
@ -412,7 +414,7 @@ export default class IfBlockWrapper extends Wrapper {
${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#ctx); ${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#ctx);
${name}.c(); ${name}.c();
} }
${has_transitions && `@transition_in(${name}, 1);`} ${has_transitions && b`@transition_in(${name}, 1);`}
${name}.m(${update_mount_node}, ${anchor}); ${name}.m(${update_mount_node}, ${anchor});
`; `;
@ -492,11 +494,11 @@ export default class IfBlockWrapper extends Wrapper {
? b` ? b`
if (${name}) { if (${name}) {
${name}.p(#changed, #ctx); ${name}.p(#changed, #ctx);
${has_transitions && `@transition_in(${name}, 1);`} ${has_transitions && b`@transition_in(${name}, 1);`}
} else { } else {
${name} = ${branch.block.name}(#ctx); ${name} = ${branch.block.name}(#ctx);
${name}.c(); ${name}.c();
${has_transitions && `@transition_in(${name}, 1);`} ${has_transitions && b`@transition_in(${name}, 1);`}
${name}.m(${update_mount_node}, ${anchor}); ${name}.m(${update_mount_node}, ${anchor});
} }
` `
@ -504,9 +506,9 @@ export default class IfBlockWrapper extends Wrapper {
if (!${name}) { if (!${name}) {
${name} = ${branch.block.name}(#ctx); ${name} = ${branch.block.name}(#ctx);
${name}.c(); ${name}.c();
${has_transitions && `@transition_in(${name}, 1);`} ${has_transitions && b`@transition_in(${name}, 1);`}
${name}.m(${update_mount_node}, ${anchor}); ${name}.m(${update_mount_node}, ${anchor});
} ${has_transitions && `else @transition_in(${name}, 1);`} } ${has_transitions && b`else @transition_in(${name}, 1);`}
`; `;
if (branch.snippet) { if (branch.snippet) {

@ -6,6 +6,7 @@ import add_event_handlers from './shared/add_event_handlers';
import Window from '../../nodes/Window'; import Window from '../../nodes/Window';
import add_actions from './shared/add_actions'; import add_actions from './shared/add_actions';
import { INode } from '../../nodes/interfaces'; import { INode } from '../../nodes/interfaces';
import { changed } from './shared/changed';
const associated_events = { const associated_events = {
innerWidth: 'resize', innerWidth: 'resize',
@ -125,7 +126,7 @@ export default class WindowWrapper extends Wrapper {
component.partly_hoisted.push(b` component.partly_hoisted.push(b`
function ${id}() { function ${id}() {
${props.map(prop => `${prop.name} = @_window.${prop.value}; $$invalidate('${prop.name}', ${prop.name});`)} ${props.map(prop => x`$$invalidate('${prop.name}', ${prop.name} = @_window.${prop.value});`)}
} }
`); `);
@ -138,19 +139,15 @@ export default class WindowWrapper extends Wrapper {
// special case... might need to abstract this out if we add more special cases // special case... might need to abstract this out if we add more special cases
if (bindings.scrollX || bindings.scrollY) { if (bindings.scrollX || bindings.scrollY) {
const condition = changed([bindings.scrollX, bindings.scrollY].filter(Boolean));
const scrollX = bindings.scrollX ? x`#ctx.${bindings.scrollX}` : x`@_window.pageXOffset`;
const scrollY = bindings.scrollY ? x`#ctx.${bindings.scrollY}` : x`@_window.pageYOffset`;
block.chunks.update.push(b` block.chunks.update.push(b`
if (${ if (${condition} && !${scrolling}) {
[bindings.scrollX, bindings.scrollY].filter(Boolean).map(
b => `changed.${b}`
).join(' || ')
} && !${scrolling}) {
${scrolling} = true; ${scrolling} = true;
@_clearTimeout(${scrolling_timeout}); @_clearTimeout(${scrolling_timeout});
@_scrollTo(${ @_scrollTo(${scrollX}, ${scrollY});
bindings.scrollX ? `#ctx.${bindings.scrollX}` : `@_window.pageXOffset`
}, ${
bindings.scrollY ? `#ctx.${bindings.scrollY}` : `@_window.pageYOffset`
});
${scrolling_timeout} = @_setTimeout(${clear_scrolling}, 100); ${scrolling_timeout} = @_setTimeout(${clear_scrolling}, 100);
} }
`); `);

Loading…
Cancel
Save