Skip to content

Commit

Permalink
separate groupOutros from transitionsManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jun 29, 2018
1 parent bde21da commit 7678b36
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 27 deletions.
8 changes: 5 additions & 3 deletions src/compile/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,13 @@ export default class Compiler {
},
});

if (name === 'transitionManager') {
if (name === 'transitionManager' || name === 'outros') {
// special case
const global = `_svelteTransitionManager`;
const global = name === 'outros'
? `_svelteOutros`
: `_svelteTransitionManager`;

inlineHelpers += `\n\nvar ${this.alias('transitionManager')} = window.${global} || (window.${global} = ${code});\n\n`;
inlineHelpers += `\n\nvar ${this.alias(name)} = window.${global} || (window.${global} = ${code});\n\n`;
} else if (name === 'escaped' || name === 'missingComponent') {
// vars are an awkward special case... would be nice to avoid this
const alias = this.alias(name);
Expand Down
2 changes: 1 addition & 1 deletion src/compile/nodes/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export default class Component extends Node {
if (${name}) {
${this.compiler.options.nestedTransitions
? deindent`
@transitionManager.groupOutros();
@groupOutros();
const old_component = ${name};
old_component._fragment.o(() => {
old_component.destroy();
Expand Down
4 changes: 2 additions & 2 deletions src/compile/nodes/EachBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export default class EachBlock extends Node {
block.builders.update.addBlock(deindent`
const ${this.each_block_value} = ${snippet};
${this.block.hasOutros && `@transitionManager.groupOutros();`}
${this.block.hasOutros && `@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 @@ -449,7 +449,7 @@ export default class EachBlock extends Node {

if (this.block.hasOutros) {
destroy = deindent`
@transitionManager.groupOutros();
@groupOutros();
for (; #i < ${iterations}.length; #i += 1) ${outroBlock}(#i, 1);
`;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/compile/nodes/IfBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export default class IfBlock extends Node {
const updateMountNode = this.getUpdateMountNode(anchor);

const destroyOldBlock = deindent`
@transitionManager.groupOutros();
@groupOutros();
${name}.o(function() {
${if_blocks}[${previous_block_index}].d(1);
${if_blocks}[${previous_block_index}] = null;
Expand Down Expand Up @@ -423,7 +423,7 @@ export default class IfBlock extends Node {
// as that will typically result in glitching
const exit = branch.hasOutroMethod
? deindent`
@transitionManager.groupOutros();
@groupOutros();
${name}.o(function() {
${name}.d(1);
${name} = null;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fs.readdirSync(__dirname).forEach(file => {
? declaration.declarations[0].init
: declaration;

declarations[name] = source.slice(value.start, value.end);
declarations[name] = value ? source.slice(value.start, value.end) : 'null';
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/shared/await-block.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assign, isPromise } from './utils.js';
import { transitionManager } from './transitions.js';
import { groupOutros } from './transitions.js';

export function handlePromise(promise, info) {
var token = info.token = {};
Expand All @@ -16,7 +16,7 @@ export function handlePromise(promise, info) {
if (info.blocks) {
info.blocks.forEach((block, i) => {
if (i !== index && block) {
transitionManager.groupOutros();
groupOutros();
block.o(() => {
block.d(1);
info.blocks[i] = null;
Expand Down
21 changes: 12 additions & 9 deletions src/shared/transitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export function wrapTransition(component, node, fn, params, intro) {
}

if (!b) {
program.group = transitionManager.outros;
transitionManager.outros.remaining += 1;
program.group = outros;
outros.remaining += 1;
}

if (obj.delay) {
Expand Down Expand Up @@ -165,6 +165,16 @@ export function wrapTransition(component, node, fn, params, intro) {
};
}

export let outros = {
remaining: 0,
callbacks: []
};

export function groupOutros() {
outros.remaining = 0;
outros.callbacks = [];
}

export var transitionManager = {
running: false,
transitions: [],
Expand Down Expand Up @@ -236,13 +246,6 @@ export var transitionManager = {
.join(', ');
},

groupOutros() {
this.outros = {
remaining: 0,
callbacks: []
};
},

wait() {
if (!transitionManager.promise) {
transitionManager.promise = Promise.resolve();
Expand Down
7 changes: 0 additions & 7 deletions test/js/samples/each-block-keyed-animated/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,6 @@ var transitionManager = {
.join(', ');
},

groupOutros() {
this.outros = {
remaining: 0,
callbacks: []
};
},

wait() {
if (!transitionManager.promise) {
transitionManager.promise = Promise.resolve();
Expand Down

0 comments on commit 7678b36

Please sign in to comment.