mirror of https://github.com/sveltejs/svelte
fix: support dynamic transition functions (#9844)
* fix: support dynamic transition functions * add test * lint * load dynamic code lazily load dynamic code lazily load dynamic code lazilypull/9848/head
parent
ab21253073
commit
fd78acfec9
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: support dynamic transition functions
|
@ -0,0 +1,25 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
import { log } from './log.js';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
before_test() {
|
||||||
|
log.length = 0;
|
||||||
|
},
|
||||||
|
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const [b1, b2] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
b1.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(log, ['transition 2']);
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
b2.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(log, ['transition 2', 'transition 1', 'transition 1']);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,2 @@
|
|||||||
|
/** @type {any[]} */
|
||||||
|
export const log = [];
|
@ -0,0 +1,33 @@
|
|||||||
|
<script>
|
||||||
|
import { log } from './log.js';
|
||||||
|
|
||||||
|
function transition1() {
|
||||||
|
log.push('transition 1')
|
||||||
|
return {
|
||||||
|
tick() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function transition2() {
|
||||||
|
log.push('transition 2')
|
||||||
|
return {
|
||||||
|
tick() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let toggle = $state(false);
|
||||||
|
let toggleTransition = $state(false);
|
||||||
|
|
||||||
|
const derived = $derived(toggleTransition ? transition1 : transition2)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
<button on:click={() => toggle = !toggle}>{toggle}</button>
|
||||||
|
<button on:click={() => toggleTransition = !toggleTransition}>{toggleTransition}</button>
|
||||||
|
|
||||||
|
{#if toggle}<div transition:derived></div>{/if}
|
||||||
|
|
Loading…
Reference in new issue