Skip to content

Commit

Permalink
Fix race condition for if block
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Zhuravlev committed Jul 6, 2018
1 parent a043c44 commit 7cab338
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/compile/dom/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,11 @@ export default class Block {

toString() {
const { dev } = this.compiler.options;
const properties = new CodeBuilder();

if (this.hasIntroMethod || this.hasOutroMethod) {
this.addVariable('#current');
properties.addBlock(`cr(){ return #current; },`);

if (!this.builders.mount.isEmpty()) {
this.builders.mount.addLine(`#current = true;`);
Expand All @@ -186,8 +188,6 @@ export default class Block {
this.builders.mount.addLine(`${this.autofocus}.focus();`);
}

const properties = new CodeBuilder();

let localKey;
if (this.key) {
localKey = this.getUniqueName('key');
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`
@groupOutros();
if(${name}.cr()) @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`
@groupOutros();
if(${name}.cr()) @groupOutros();
${name}.o(function() {
${name}.d(1);
${name} = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default {
test ( assert, component, target, window, raf ) {
component.set({ visible: true });
const div = target.querySelector('div');

component.set({ visible: false });
assert.equal(window.getComputedStyle(div).opacity, 1);

raf.tick(200);
assert.equal(window.getComputedStyle(div).opacity, 0.5);
component.set({ blabla: false });

raf.tick(400);
assert.equal(window.getComputedStyle(div).opacity, 0);

raf.tick(600);
assert.equal(component.refs.div, undefined);
assert.equal(target.querySelector('div'), undefined);

component.destroy();
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{#if visible}
<div out:fade style="opacity: 1;" ref:div>yes</div>
{/if}

<script>
export default {
transitions: {
fade: function ( node, params ) {
return {
duration: 400,
tick: t => {
node.style.opacity = t;
}
};
}
}
};
</script>

0 comments on commit 7cab338

Please sign in to comment.