mirror of https://github.com/sveltejs/svelte
Makes transitions only run when the closest non-component block containing them has changed state. Implements #1480. ### Details Without the `containedTransitions` compiler option, all transitions are run whenever their element is added/remove from the dom. With `containedTransitions` the transitions are only run when the closest non-component block (e.g. an if-block or each-block) changes state. This means the transitions on the items of an each-block will not run when the each-block first appears on screen, or when it is removed, but they will run when items are added/removed from the each block. In addition, if a whole page fades in with a transition at the page level, the there will not be other transitions occuring inside the page. The transition containers do not include components, since a component is a reusable container and not a state-driven block. Thus, a transition at the root of a component will run when that component is added to the DOM inside an if-block or each-block the same way an element with a transition inside either of those blocks is run.pull/1692/head
parent
0f171a5f3e
commit
72cb842342
@ -0,0 +1,34 @@
|
||||
let fulfil;
|
||||
|
||||
const promise = new Promise(f => {
|
||||
fulfil = f;
|
||||
});
|
||||
|
||||
export default {
|
||||
containedTransitions: true,
|
||||
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></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></div>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
transitions: {
|
||||
foo(node, params) {
|
||||
return {
|
||||
duration: 100,
|
||||
tick: t => {
|
||||
node.foo = t;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,27 @@
|
||||
export default {
|
||||
containedTransitions: true,
|
||||
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,33 @@
|
||||
export default {
|
||||
containedTransitions: true,
|
||||
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></div>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
<script>
|
||||
export default {
|
||||
transitions: {
|
||||
foo(node, params) {
|
||||
return {
|
||||
duration: 100,
|
||||
tick: t => {
|
||||
node.foo = t;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,33 @@
|
||||
export default {
|
||||
containedTransitions: true,
|
||||
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></div>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
<script>
|
||||
export default {
|
||||
transitions: {
|
||||
foo(node, params) {
|
||||
return {
|
||||
duration: 100,
|
||||
tick: t => {
|
||||
node.foo = t;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,45 @@
|
||||
export default {
|
||||
containedTransitions: true,
|
||||
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);
|
||||
|
||||
raf.tick(100);
|
||||
assert.equal(div.foo, undefined);
|
||||
assert.htmlEqual(target.innerHTML, '<div></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, '');
|
||||
|
||||
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(250);
|
||||
assert.equal(div.foo, 0.5);
|
||||
|
||||
raf.tick(300);
|
||||
assert.htmlEqual(target.innerHTML, '');
|
||||
},
|
||||
};
|
@ -0,0 +1,20 @@
|
||||
{#if x}
|
||||
{#if y}
|
||||
<div transition:foo></div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<script>
|
||||
export default {
|
||||
transitions: {
|
||||
foo(node, params) {
|
||||
return {
|
||||
duration: 100,
|
||||
tick: t => {
|
||||
node.foo = t;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in new issue