mirror of https://github.com/sveltejs/svelte
parent
df0f836dcb
commit
87b418adee
@ -1,21 +1,21 @@
|
|||||||
<script>
|
<script>
|
||||||
import InnerChild from './InnerChild.svelte';
|
import InnerChild from './InnerChild.svelte';
|
||||||
|
|
||||||
export let id = 1;
|
export let id = 1;
|
||||||
export let count;
|
export let count;
|
||||||
export let increment;
|
export let increment;
|
||||||
|
|
||||||
let list;
|
let list;
|
||||||
$: {
|
$: {
|
||||||
list = [];
|
list = [];
|
||||||
for (let i = 0; i < count; ++i) {
|
for (let i = 0; i < count; ++i) {
|
||||||
list.push(i);
|
list.push(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div data-id={id}>
|
<div data-id={id}>
|
||||||
{#each list as item (item)}
|
{#each list as item (item)}
|
||||||
<InnerChild val={item} {increment} />
|
<InnerChild val={item} {increment} />
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
<script>
|
<script>
|
||||||
import { afterUpdate } from 'svelte';
|
import { afterUpdate } from 'svelte';
|
||||||
|
|
||||||
export let val = 1;
|
export let val = 1;
|
||||||
export let increment;
|
export let increment;
|
||||||
|
|
||||||
afterUpdate(() => {
|
afterUpdate(() => {
|
||||||
increment();
|
increment();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<inner>
|
<inner>
|
||||||
{val}
|
{val}
|
||||||
</inner>
|
</inner>
|
||||||
@ -1,35 +1,35 @@
|
|||||||
<script>
|
<script>
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import Child from './Child.svelte';
|
import Child from './Child.svelte';
|
||||||
|
|
||||||
let updateCounter = 0;
|
let updateCounter = 0;
|
||||||
let promiseResolve;
|
let promiseResolve;
|
||||||
export const done = new Promise(resolve => {
|
export const done = new Promise(resolve => {
|
||||||
promiseResolve = resolve;
|
promiseResolve = resolve;
|
||||||
});
|
});
|
||||||
export const getCounter = () => {
|
export const getCounter = () => {
|
||||||
return updateCounter;
|
return updateCounter;
|
||||||
};
|
};
|
||||||
|
|
||||||
let vals = [1, 2, 3];
|
let vals = [1, 2, 3];
|
||||||
const instances = [];
|
const instances = [];
|
||||||
let count = 3;
|
let count = 3;
|
||||||
|
|
||||||
const increment = () => {
|
const increment = () => {
|
||||||
++updateCounter;
|
++updateCounter;
|
||||||
};
|
};
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
count = 2;
|
count = 2;
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
vals = vals.reverse();
|
vals = vals.reverse();
|
||||||
|
|
||||||
setTimeout(promiseResolve);
|
setTimeout(promiseResolve);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#each vals as val, index (val)}
|
{#each vals as val, index (val)}
|
||||||
<Child bind:this={instances[index]} id={val} {count} {increment} />
|
<Child bind:this={instances[index]} id={val} {count} {increment} />
|
||||||
{/each}
|
{/each}
|
||||||
|
|||||||
@ -1,21 +1,21 @@
|
|||||||
<script>
|
<script>
|
||||||
import InnerChild from './InnerChild.svelte';
|
import InnerChild from './InnerChild.svelte';
|
||||||
|
|
||||||
export let id = 1;
|
export let id = 1;
|
||||||
export let count;
|
export let count;
|
||||||
export let increment;
|
export let increment;
|
||||||
|
|
||||||
let list;
|
let list;
|
||||||
$: {
|
$: {
|
||||||
list = [];
|
list = [];
|
||||||
for (let i = 0; i < count; ++i) {
|
for (let i = 0; i < count; ++i) {
|
||||||
list.push(i);
|
list.push(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div data-id={id}>
|
<div data-id={id}>
|
||||||
{#each list as item}
|
{#each list as item}
|
||||||
<InnerChild val={item} {increment} />
|
<InnerChild val={item} {increment} />
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
<script>
|
<script>
|
||||||
import { afterUpdate } from 'svelte';
|
import { afterUpdate } from 'svelte';
|
||||||
|
|
||||||
export let val = 1;
|
export let val = 1;
|
||||||
export let increment;
|
export let increment;
|
||||||
|
|
||||||
afterUpdate(() => {
|
afterUpdate(() => {
|
||||||
increment();
|
increment();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<inner>
|
<inner>
|
||||||
{val}
|
{val}
|
||||||
</inner>
|
</inner>
|
||||||
@ -1,35 +1,35 @@
|
|||||||
<script>
|
<script>
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import Child from './Child.svelte';
|
import Child from './Child.svelte';
|
||||||
|
|
||||||
let updateCounter = 0;
|
let updateCounter = 0;
|
||||||
let promiseResolve;
|
let promiseResolve;
|
||||||
export const done = new Promise(resolve => {
|
export const done = new Promise(resolve => {
|
||||||
promiseResolve = resolve;
|
promiseResolve = resolve;
|
||||||
});
|
});
|
||||||
export const getCounter = () => {
|
export const getCounter = () => {
|
||||||
return updateCounter;
|
return updateCounter;
|
||||||
};
|
};
|
||||||
|
|
||||||
let vals = [1, 2, 3];
|
let vals = [1, 2, 3];
|
||||||
const instances = [];
|
const instances = [];
|
||||||
let count = 3;
|
let count = 3;
|
||||||
|
|
||||||
const increment = () => {
|
const increment = () => {
|
||||||
++updateCounter;
|
++updateCounter;
|
||||||
};
|
};
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
count = 2;
|
count = 2;
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
vals = vals.reverse();
|
vals = vals.reverse();
|
||||||
|
|
||||||
setTimeout(promiseResolve);
|
setTimeout(promiseResolve);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#each vals as val, index (val)}
|
{#each vals as val, index (val)}
|
||||||
<Child bind:this={instances[index]} id={val} {count} {increment} />
|
<Child bind:this={instances[index]} id={val} {count} {increment} />
|
||||||
{/each}
|
{/each}
|
||||||
|
|||||||
Loading…
Reference in new issue