mirror of https://github.com/sveltejs/svelte
only add event listeners when a block is first mounted (#4860)
parent
24ef4e1181
commit
3330c3fbab
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
export let action;
|
||||
</script>
|
||||
|
||||
<div use:action />
|
@ -0,0 +1,21 @@
|
||||
export default {
|
||||
test({ assert, component, raf }) {
|
||||
assert.equal(component.count, 0);
|
||||
|
||||
component.arr = ["2"];
|
||||
|
||||
assert.equal(component.count, 1);
|
||||
|
||||
component.arr = ["1", "2"];
|
||||
|
||||
assert.equal(component.count, 2);
|
||||
|
||||
component.arr = ["2", "1"];
|
||||
|
||||
assert.equal(component.count, 2);
|
||||
|
||||
component.arr = [];
|
||||
|
||||
assert.equal(component.count, 0);
|
||||
},
|
||||
};
|
@ -0,0 +1,17 @@
|
||||
<script>
|
||||
import Component from "./Component.svelte";
|
||||
export let arr = [];
|
||||
export let count = 0;
|
||||
function action(node, params) {
|
||||
count += 1;
|
||||
return {
|
||||
destroy() {
|
||||
count -= 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
{#each arr as item (item)}
|
||||
<Component {action} />
|
||||
{/each}
|
Loading…
Reference in new issue