0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 01:11:24 +01:00

dont recreate if_blocks incorrectly

This commit is contained in:
Rich Harris 2017-06-23 17:56:34 -04:00
parent cc489be18a
commit 47f9c3dbfd
3 changed files with 68 additions and 2 deletions

View File

@ -369,8 +369,11 @@ function compoundWithOutros(
`;
const createNewBlock = deindent`
${name} = ${if_blocks}[ ${current_block_index} ] = ${if_block_creators}[ ${current_block_index} ]( ${params}, ${block.component} );
${name}.create();
${name} = ${if_blocks}[ ${current_block_index} ];
if ( !${name} ) {
${name} = ${if_blocks}[ ${current_block_index} ] = ${if_block_creators}[ ${current_block_index} ]( ${params}, ${block.component} );
${name}.create();
}
${name}.${mountOrIntro}( ${parentNode}, ${anchor} );
`;

View File

@ -0,0 +1,37 @@
export default {
data: {
foo: false,
threshold: 5
},
html: `
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
`,
test ( assert, component, target, window, raf ) {
const divs = target.querySelectorAll('div');
raf.tick(100);
component.set({ threshold: 4 });
raf.tick(150);
component.set({ threshold: 5 });
raf.tick(200);
component.set({ threshold: 5.5 });
assert.htmlEqual(target.innerHTML, `
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
`);
component.destroy();
}
};

View File

@ -0,0 +1,26 @@
{{#each [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as number}}
{{#if foo}}
{{#if threshold >= number}}
<div transition:foo>{{number}}</div>
{{/if}}
{{else}}
{{#if threshold >= number}}
<div transition:foo>{{number}}</div>
{{/if}}
{{/if}}
{{/each}}
<script>
export default {
transitions: {
foo: function ( node ) {
return {
duration: 100,
tick: t => {
node.foo = t;
}
};
}
}
};
</script>