mirror of https://github.com/sveltejs/svelte
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
276 B
20 lines
276 B
7 years ago
|
<script>
|
||
6 years ago
|
export let x = 0;
|
||
7 years ago
|
|
||
6 years ago
|
function foo(node) {
|
||
|
const handler = () => {
|
||
|
x += 1;
|
||
|
}
|
||
7 years ago
|
|
||
6 years ago
|
node.addEventListener('click', handler);
|
||
|
handler();
|
||
7 years ago
|
|
||
6 years ago
|
return {
|
||
|
destroy() {
|
||
|
node.removeEventListener('click', handler);
|
||
7 years ago
|
}
|
||
6 years ago
|
};
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<button use:foo>{x}</button>
|