mirror of https://github.com/sveltejs/svelte
parent
ef33466c12
commit
d707f6a3b2
@ -0,0 +1,30 @@
|
|||||||
|
{{#each things as thing}}
|
||||||
|
<Visibility bind:isVisible="visibilityMap[thing]">
|
||||||
|
<p>{{thing}} ({{visibilityMap[thing]}})</p>
|
||||||
|
</Visibility>
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Visibility from './Visibility.html';
|
||||||
|
import counter from './counter.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
things: ['first thing', 'second thing'],
|
||||||
|
visibilityMap: {}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
visibleThings: (things, visibilityMap) => {
|
||||||
|
counter.count += 1;
|
||||||
|
return things.filter(text => visibilityMap[text]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
components: {
|
||||||
|
Visibility
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
@ -0,0 +1,11 @@
|
|||||||
|
<div>
|
||||||
|
{{yield}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
oncreate() {
|
||||||
|
this.set({ isVisible: true });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
@ -0,0 +1,21 @@
|
|||||||
|
import counter from './counter.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
'skip-ssr': true,
|
||||||
|
|
||||||
|
html: `
|
||||||
|
<div><p>first thing (true)</p></div>
|
||||||
|
<div><p>second thing (true)</p></div>
|
||||||
|
`,
|
||||||
|
|
||||||
|
test(assert, component) {
|
||||||
|
const visibleThings = component.get('visibleThings');
|
||||||
|
assert.deepEqual(visibleThings, ['first thing', 'second thing']);
|
||||||
|
|
||||||
|
const snapshots = component.snapshots;
|
||||||
|
assert.deepEqual(snapshots, [visibleThings]);
|
||||||
|
|
||||||
|
// TODO minimise the number of recomputations during oncreate
|
||||||
|
// assert.equal(counter.count, 1);
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,3 @@
|
|||||||
|
export default {
|
||||||
|
count: 0
|
||||||
|
};
|
@ -0,0 +1,24 @@
|
|||||||
|
<Nested bind:visibleThings="visibleThings" />
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Nested from './Nested.html';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
visibleThings: []
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
components: {
|
||||||
|
Nested
|
||||||
|
},
|
||||||
|
|
||||||
|
oncreate() {
|
||||||
|
this.snapshots = [];
|
||||||
|
this.observe('visibleThings', things => {
|
||||||
|
this.snapshots.push(things);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
Loading…
Reference in new issue