mirror of https://github.com/sveltejs/svelte
Allows transitions to only run locally, skipping running when they are added to the DOM or removed from it. Example: ```html {#if visible} {#each things as thing} <div transition:fade|local></div> {/each} {/if} <script> export default { transitions: { fade(node, params) { return { duration: 400, css: t => { return `opacity: ${t}`; } }; } } }; </script> ``` In this example items in the each-block will fade in and fade out when they are added to or removed from `things` but the list will appear suddenly and disappear suddenly (no fade) when `visible` is toggled to `true` or `false`. This is another try at #1480.pull/1734/head
parent
a4d412fb53
commit
326d5a7d58
@ -0,0 +1,33 @@
|
||||
let fulfil;
|
||||
|
||||
const promise = new Promise(f => {
|
||||
fulfil = f;
|
||||
});
|
||||
|
||||
export default {
|
||||
nestedTransitions: true,
|
||||
|
||||
data: {
|
||||
x: false,
|
||||
promise
|
||||
},
|
||||
|
||||
test(assert, component, target, window, raf) {
|
||||
component.set({ x: true });
|
||||
fulfil();
|
||||
|
||||
return promise.then(() => {
|
||||
const div = target.querySelector('div');
|
||||
assert.equal(div.foo, 0);
|
||||
|
||||
raf.tick(100);
|
||||
assert.equal(div.foo, 1);
|
||||
|
||||
component.set({ x: false });
|
||||
assert.htmlEqual(target.innerHTML, '');
|
||||
|
||||
raf.tick(150);
|
||||
assert.equal(div.foo, 1);
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,20 @@
|
||||
{#if x}
|
||||
{#await promise then value}
|
||||
<div transition:foo|local></div>
|
||||
{/await}
|
||||
{/if}
|
||||
|
||||
<script>
|
||||
export default {
|
||||
transitions: {
|
||||
foo(node, params) {
|
||||
return {
|
||||
duration: 100,
|
||||
tick: t => {
|
||||
node.foo = t;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,16 @@
|
||||
<div transition:foo|local></div>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
transitions: {
|
||||
foo(node, params) {
|
||||
return {
|
||||
duration: 100,
|
||||
tick: t => {
|
||||
node.foo = t;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,26 @@
|
||||
export default {
|
||||
nestedTransitions: true,
|
||||
|
||||
data: {
|
||||
x: false
|
||||
},
|
||||
|
||||
test(assert, component, target, window, raf) {
|
||||
component.set({ x: true });
|
||||
|
||||
const div = target.querySelector('div');
|
||||
assert.equal(div.foo, 0);
|
||||
|
||||
raf.tick(100);
|
||||
assert.equal(div.foo, 1);
|
||||
|
||||
component.set({ x: false });
|
||||
assert.htmlEqual(target.innerHTML, '<div></div>');
|
||||
|
||||
raf.tick(150);
|
||||
assert.equal(div.foo, 0.5);
|
||||
|
||||
raf.tick(200);
|
||||
assert.htmlEqual(target.innerHTML, '');
|
||||
}
|
||||
};
|
@ -0,0 +1,13 @@
|
||||
{#if x}
|
||||
<Widget/>
|
||||
{/if}
|
||||
|
||||
<script>
|
||||
import Widget from './Widget.html';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Widget: './Widget.html'
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,32 @@
|
||||
export default {
|
||||
nestedTransitions: true,
|
||||
|
||||
data: {
|
||||
x: false,
|
||||
things: ['a']
|
||||
},
|
||||
|
||||
test(assert, component, target, window, raf) {
|
||||
component.set({ x: true });
|
||||
|
||||
const div1 = target.querySelector('div');
|
||||
assert.equal(div1.foo, undefined);
|
||||
|
||||
raf.tick(100);
|
||||
assert.equal(div1.foo, undefined);
|
||||
|
||||
component.set({ things: ['a', 'b'] });
|
||||
assert.htmlEqual(target.innerHTML, '<div></div><div></div>');
|
||||
|
||||
const div2 = target.querySelector('div:last-child');
|
||||
assert.equal(div1.foo, undefined);
|
||||
assert.equal(div2.foo, 0);
|
||||
|
||||
raf.tick(200);
|
||||
assert.equal(div1.foo, undefined);
|
||||
assert.equal(div2.foo, 1);
|
||||
|
||||
component.set({ x: false });
|
||||
assert.htmlEqual(target.innerHTML, '');
|
||||
},
|
||||
};
|
@ -0,0 +1,20 @@
|
||||
{#if x}
|
||||
{#each things as thing (thing)}
|
||||
<div transition:foo|local></div>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
<script>
|
||||
export default {
|
||||
transitions: {
|
||||
foo(node, params) {
|
||||
return {
|
||||
duration: 100,
|
||||
tick: t => {
|
||||
node.foo = t;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,32 @@
|
||||
export default {
|
||||
nestedTransitions: true,
|
||||
|
||||
data: {
|
||||
x: false,
|
||||
things: ['a']
|
||||
},
|
||||
|
||||
test(assert, component, target, window, raf) {
|
||||
component.set({ x: true });
|
||||
|
||||
const div1 = target.querySelector('div');
|
||||
assert.equal(div1.foo, undefined);
|
||||
|
||||
raf.tick(100);
|
||||
assert.equal(div1.foo, undefined);
|
||||
|
||||
component.set({ things: ['a', 'b'] });
|
||||
assert.htmlEqual(target.innerHTML, '<div></div><div></div>');
|
||||
|
||||
const div2 = target.querySelector('div:last-child');
|
||||
assert.equal(div1.foo, undefined);
|
||||
assert.equal(div2.foo, 0);
|
||||
|
||||
raf.tick(200);
|
||||
assert.equal(div1.foo, undefined);
|
||||
assert.equal(div2.foo, 1);
|
||||
|
||||
component.set({ x: false });
|
||||
assert.htmlEqual(target.innerHTML, '');
|
||||
},
|
||||
};
|
@ -0,0 +1,20 @@
|
||||
{#if x}
|
||||
{#each things as thing}
|
||||
<div transition:foo|local></div>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
<script>
|
||||
export default {
|
||||
transitions: {
|
||||
foo(node, params) {
|
||||
return {
|
||||
duration: 100,
|
||||
tick: t => {
|
||||
node.foo = t;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,41 @@
|
||||
export default {
|
||||
nestedTransitions: true,
|
||||
|
||||
data: {
|
||||
x: false,
|
||||
y: true
|
||||
},
|
||||
|
||||
test(assert, component, target, window, raf) {
|
||||
component.set({ x: true });
|
||||
|
||||
let div = target.querySelector('div');
|
||||
assert.equal(div.foo, undefined);
|
||||
|
||||
component.set({ y: false });
|
||||
assert.htmlEqual(target.innerHTML, '<div></div>');
|
||||
div = target.querySelector('div');
|
||||
|
||||
raf.tick(50);
|
||||
assert.equal(div.foo, 0.5);
|
||||
|
||||
raf.tick(100);
|
||||
assert.htmlEqual(target.innerHTML, '');
|
||||
|
||||
component.set({ x: false, y: true });
|
||||
assert.htmlEqual(target.innerHTML, '');
|
||||
|
||||
component.set({ x: true });
|
||||
assert.htmlEqual(target.innerHTML, '<div></div>');
|
||||
div = target.querySelector('div');
|
||||
|
||||
component.set({ y: false });
|
||||
assert.htmlEqual(target.innerHTML, '<div></div>');
|
||||
|
||||
raf.tick(150);
|
||||
assert.equal(div.foo, 0.5);
|
||||
|
||||
raf.tick(200);
|
||||
assert.htmlEqual(target.innerHTML, '');
|
||||
},
|
||||
};
|
@ -0,0 +1,20 @@
|
||||
{#if x}
|
||||
{#if y}
|
||||
<div transition:foo|local></div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<script>
|
||||
export default {
|
||||
transitions: {
|
||||
foo(node, params) {
|
||||
return {
|
||||
duration: 100,
|
||||
tick: t => {
|
||||
node.foo = t;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,41 @@
|
||||
export default {
|
||||
nestedTransitions: true,
|
||||
|
||||
data: {
|
||||
x: false,
|
||||
y: true
|
||||
},
|
||||
|
||||
test(assert, component, target, window, raf) {
|
||||
component.set({ x: true });
|
||||
|
||||
let div = target.querySelector('div');
|
||||
assert.equal(div.foo, undefined);
|
||||
|
||||
component.set({ y: false });
|
||||
assert.htmlEqual(target.innerHTML, '<div></div>');
|
||||
div = target.querySelector('div');
|
||||
|
||||
raf.tick(50);
|
||||
assert.equal(div.foo, 0.5);
|
||||
|
||||
raf.tick(100);
|
||||
assert.htmlEqual(target.innerHTML, '');
|
||||
|
||||
component.set({ x: false, y: true });
|
||||
assert.htmlEqual(target.innerHTML, '');
|
||||
|
||||
component.set({ x: true });
|
||||
assert.htmlEqual(target.innerHTML, '<div></div>');
|
||||
div = target.querySelector('div');
|
||||
|
||||
component.set({ y: false });
|
||||
assert.htmlEqual(target.innerHTML, '<div></div>');
|
||||
|
||||
raf.tick(120);
|
||||
assert.equal(div.foo, 0.8);
|
||||
|
||||
raf.tick(200);
|
||||
assert.htmlEqual(target.innerHTML, '');
|
||||
},
|
||||
};
|
@ -0,0 +1,20 @@
|
||||
{#if x}
|
||||
{#if y}
|
||||
<div transition:foo|local></div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<script>
|
||||
export default {
|
||||
transitions: {
|
||||
foo(node, params) {
|
||||
return {
|
||||
duration: 100,
|
||||
tick: t => {
|
||||
node.foo = t;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in new issue