mirror of https://github.com/sveltejs/svelte
fix: apply dynamic event fixes to OnDirective (#12582)
* fix: apply dynamic event fixes to OnDirective * buildpull/12588/head
parent
528d3468d0
commit
37f58cf318
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: apply dynamic event fixes to OnDirective
|
@ -0,0 +1,26 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: '<button>Tama</button><button>Pochi</button><br><button>Change Function</button>',
|
||||
|
||||
test({ assert, logs, target }) {
|
||||
const [b1, b2, b3] = target.querySelectorAll('button');
|
||||
|
||||
b1?.click();
|
||||
b2?.click();
|
||||
b3?.click();
|
||||
b1?.click();
|
||||
b2?.click();
|
||||
|
||||
assert.deepEqual(logs, [
|
||||
'creating "Hello" handler for Tama',
|
||||
'Hello Tama',
|
||||
'creating "Hello" handler for Pochi',
|
||||
'Hello Pochi',
|
||||
'creating "Bye" handler for Tama',
|
||||
'Bye Tama',
|
||||
'creating "Bye" handler for Pochi',
|
||||
'Bye Pochi'
|
||||
]);
|
||||
}
|
||||
});
|
@ -0,0 +1,19 @@
|
||||
<script>
|
||||
let saySomething = $state(name => {
|
||||
console.log('creating "Hello" handler for ' + name);
|
||||
return { handler: () => console.log('Hello ' + name) };
|
||||
});
|
||||
|
||||
function change() {
|
||||
saySomething = name => {
|
||||
console.log('creating "Bye" handler for ' + name);
|
||||
return { handler: () => console.log('Bye ' + name) };
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<button on:click={saySomething('Tama').handler}>Tama</button>
|
||||
<button on:click={saySomething('Pochi').handler}>Pochi</button>
|
||||
|
||||
<br>
|
||||
<button on:click={change}>Change Function</button>
|
Loading…
Reference in new issue