Skip to content

Commit

Permalink
Merge pull request #1493 from sveltejs/gh-1492
Browse files Browse the repository at this point in the history
separate hasOutros from hasOutroMethod
  • Loading branch information
Rich-Harris authored May 25, 2018
2 parents 9e52cf9 + 15efef9 commit 607f96d
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 23 deletions.
8 changes: 5 additions & 3 deletions src/compile/dom/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export default class Block {

maintainContext: boolean;
hasAnimation: boolean;
hasIntroMethod: boolean;
hasIntros: boolean;
hasOutros: boolean;
hasIntroMethod: boolean; // could have the method without the transition, due to siblings
hasOutroMethod: boolean;
outros: number;

Expand Down Expand Up @@ -127,11 +129,11 @@ export default class Block {
}

addIntro() {
this.hasIntroMethod = this.compiler.target.hasIntroTransitions = true;
this.hasIntros = this.hasIntroMethod = this.compiler.target.hasIntroTransitions = true;
}

addOutro() {
this.hasOutroMethod = this.compiler.target.hasOutroTransitions = true;
this.hasOutros = this.hasOutroMethod = this.compiler.target.hasOutroTransitions = true;
this.outros += 1;
}

Expand Down
4 changes: 2 additions & 2 deletions src/compile/nodes/Attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export default class Attribute extends Node {
if (this.dependencies.size || isSelectValueAttribute) {
const dependencies = Array.from(this.dependencies);
const changedCheck = (
( block.hasOutroMethod ? `#outroing || ` : '' ) +
( block.hasOutros ? `#outroing || ` : '' ) +
dependencies.map(dependency => `changed.${dependency}`).join(' || ')
);

Expand Down Expand Up @@ -308,7 +308,7 @@ export default class Attribute extends Node {
if (propDependencies.size) {
const dependencies = Array.from(propDependencies);
const condition = (
(block.hasOutroMethod ? `#outroing || ` : '') +
(block.hasOutros ? `#outroing || ` : '') +
dependencies.map(dependency => `changed.${dependency}`).join(' || ')
);

Expand Down
4 changes: 2 additions & 2 deletions src/compile/nodes/AwaitBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export default class AwaitBlock extends Node {
block.addDependencies(child.block.dependencies);
}

if (child.block.hasIntroMethod) hasIntros = true;
if (child.block.hasOutroMethod) hasOutros = true;
if (child.block.hasIntros) hasIntros = true;
if (child.block.hasOutros) hasOutros = true;
});

this.pending.block.hasUpdateMethod = isDynamic;
Expand Down
12 changes: 6 additions & 6 deletions src/compile/nodes/EachBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default class EachBlock extends Node {
this.else.block.hasUpdateMethod = this.else.block.dependencies.size > 0;
}

if (this.block.hasOutroMethod || (this.else && this.else.block.hasOutroMethod)) {
if (this.block.hasOutros || (this.else && this.else.block.hasOutros)) {
block.addOutro();
}
}
Expand Down Expand Up @@ -317,14 +317,14 @@ export default class EachBlock extends Node {
const rects = block.getUniqueName('rects');
const destroy = this.block.hasAnimation
? `@fixAndOutroAndDestroyBlock`
: this.block.hasOutroMethod
: this.block.hasOutros
? `@outroAndDestroyBlock`
: `@destroyBlock`;

block.builders.update.addBlock(deindent`
const ${this.each_block_value} = ${snippet};
${this.block.hasOutroMethod && `@transitionManager.groupOutros();`}
${this.block.hasOutros && `@transitionManager.groupOutros();`}
${this.block.hasAnimation && `for (let #i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].r();`}
${blocks} = @updateKeyedEach(${blocks}, #component, changed, ${get_key}, ${dynamic ? '1' : '0'}, ctx, ${this.each_block_value}, ${lookup}, ${updateMountNode}, ${destroy}, ${create_each_block}, "${mountOrIntro}", ${anchor}, ${this.get_each_context});
${this.block.hasAnimation && `for (let #i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].a();`}
Expand Down Expand Up @@ -393,7 +393,7 @@ export default class EachBlock extends Node {
allDependencies.add(dependency);
});

const outro = this.block.hasOutroMethod && block.getUniqueName('outro')
const outro = this.block.hasOutros && block.getUniqueName('outro')
if (outro) {
block.builders.init.addBlock(deindent`
function ${outro}(i, detach, fn) {
Expand All @@ -415,7 +415,7 @@ export default class EachBlock extends Node {

if (condition !== '') {
const forLoopBody = this.block.hasUpdateMethod
? (this.block.hasIntroMethod || this.block.hasOutroMethod)
? (this.block.hasIntros || this.block.hasOutros)
? deindent`
if (${iterations}[#i]) {
${iterations}[#i].p(changed, child_ctx);
Expand Down Expand Up @@ -444,7 +444,7 @@ export default class EachBlock extends Node {

let destroy;

if (this.block.hasOutroMethod) {
if (this.block.hasOutros) {
destroy = deindent`
@transitionManager.groupOutros();
for (; #i < ${iterations}.length; #i += 1) ${outro}(#i, 1);
Expand Down
12 changes: 5 additions & 7 deletions src/compile/nodes/IfBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export default class IfBlock extends Node {
block.addDependencies(node.block.dependencies);
}

if (node.block.hasIntroMethod) hasIntros = true;
if (node.block.hasOutroMethod) hasOutros = true;
if (node.block.hasIntros) hasIntros = true;
if (node.block.hasOutros) hasOutros = true;

if (isElseIf(node.else)) {
attachBlocks(node.else.children[0]);
Expand Down Expand Up @@ -302,8 +302,8 @@ export default class IfBlock extends Node {
const destroyOldBlock = deindent`
@transitionManager.groupOutros();
${name}.o(function() {
${if_blocks}[ ${previous_block_index} ].d(1);
${if_blocks}[ ${previous_block_index} ] = null;
${if_blocks}[${previous_block_index}].d(1);
${if_blocks}[${previous_block_index}] = null;
});
`;

Expand Down Expand Up @@ -355,9 +355,7 @@ export default class IfBlock extends Node {
}

block.builders.destroy.addLine(deindent`
${if_current_block_type_index}{
${if_blocks}[${current_block_type_index}].d(${parentNode ? '' : 'detach'});
}
${if_current_block_type_index}${if_blocks}[${current_block_type_index}].d(${parentNode ? '' : 'detach'});
`);
}

Expand Down
2 changes: 1 addition & 1 deletion src/compile/nodes/Title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class Title extends Node {
if (allDependencies.size) {
const dependencies = Array.from(allDependencies);
const changedCheck = (
( block.hasOutroMethod ? `#outroing || ` : '' ) +
( block.hasOutros ? `#outroing || ` : '' ) +
dependencies.map(dependency => `changed.${dependency}`).join(' || ')
);

Expand Down
2 changes: 1 addition & 1 deletion src/compile/nodes/shared/Tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class Tag extends Node {

if (dependencies.size) {
const changedCheck = (
(block.hasOutroMethod ? `#outroing || ` : '') +
(block.hasOutros ? `#outroing || ` : '') +
[...dependencies].map((dependency: string) => `changed.${dependency}`).join(' || ')
);

Expand Down
2 changes: 1 addition & 1 deletion src/parse/read/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const DIRECTIVES: Record<string, {
attribute(start, end, type, name, expression) {
return { start, end, type, name, expression };
},
allowedExpressionTypes: [ 'Identifier', 'MemberExpression', 'ObjectExpression', 'Literal', 'CallExpression' ],
allowedExpressionTypes: ['Identifier', 'MemberExpression', 'ObjectExpression', 'Literal', 'CallExpression'],
error: 'Data passed to actions must be an identifier (e.g. `foo`), a member expression ' +
'(e.g. `foo.bar` or `foo[baz]`), a method call (e.g. `foo()`), or a literal (e.g. `true` or `\'a string\'`'
},
Expand Down
1 change: 1 addition & 0 deletions test/runtime/samples/if-block-else-partial-outro/Foo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo
19 changes: 19 additions & 0 deletions test/runtime/samples/if-block-else-partial-outro/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default {
data: {
x: 1,
y: false,
},

html: `
<span>1</span>
`,

nestedTransitions: true,

test(assert, component, target) {
component.set({ x: 2 });
assert.htmlEqual(target.innerHTML, `
<span>2</span>
`);
},
};
20 changes: 20 additions & 0 deletions test/runtime/samples/if-block-else-partial-outro/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{#if y}
<Foo/>
{:else}
<span>{x}</span>
{/if}

<script>
export default {
components: {
Foo: './Foo.html'
},

data() {
return {
x: 'x',
y: false
};
}
};
</script>

0 comments on commit 607f96d

Please sign in to comment.