mirror of https://github.com/sveltejs/svelte
fix: improve dynamic event handling (#12570)
parent
d17755a8b5
commit
64e9f0e5f6
@ -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 onclick={saySomething('Tama').handler}>Tama</button>
|
||||
<button onclick={saySomething('Pochi').handler}>Pochi</button>
|
||||
|
||||
<br>
|
||||
<button onclick={change}>Change Function</button>
|
Loading…
Reference in new issue