mirror of https://github.com/sveltejs/svelte
parent
ca6e9b5745
commit
b51fcdd83a
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
feat: add svelete/events package and export attach function
|
||||
@ -0,0 +1 @@
|
||||
export { attach } from '../internal/client/dom/elements/events';
|
||||
@ -0,0 +1,17 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
mode: ['client'],
|
||||
|
||||
test({ assert, target, logs }) {
|
||||
const [b1] = target.querySelectorAll('button');
|
||||
|
||||
b1?.click();
|
||||
b1?.click();
|
||||
b1?.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(target.innerHTML, '<section><button>clicks: 3</button></section>');
|
||||
assert.deepEqual(logs, []);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,23 @@
|
||||
<script>
|
||||
import {attach} from 'svelte/events';
|
||||
|
||||
let count = $state(0);
|
||||
|
||||
function increment(e) {
|
||||
e.stopPropagation();
|
||||
count += 1;
|
||||
}
|
||||
|
||||
let sectionEl
|
||||
$effect(() => {
|
||||
return attach(sectionEl, 'click', () => {
|
||||
console.log('logged from addEventListener');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<section bind:this={sectionEl} onclick={() => console.log('logged from onclick')}>
|
||||
<button onclick={increment}>
|
||||
clicks: {count}
|
||||
</button>
|
||||
</section>
|
||||
Loading…
Reference in new issue