Skip to content

Instantly share code, notes, and snippets.

@dxlbnl
Created January 24, 2017 13:44
Show Gist options
  • Save dxlbnl/f0a6a52d3c8789be0c0fa25e1602667a to your computer and use it in GitHub Desktop.
Save dxlbnl/f0a6a52d3c8789be0c0fa25e1602667a to your computer and use it in GitHub Desktop.
Nesting updating components with svelte
<li>{{value}}</li>
<script>
export default {
data() {
return {
value: 'XX'
};
},
onrender() {
console.log('rendering', this.get('item'));
setInterval(() => {
this.set({value: this.get('value') + 1});
}, 500)
this.observe('item', (item) => this.set({value: item}));
}
};
</script>
<ul>
{{#each items as item}}
<Item item={{item}} />
{{/each}}
</ul>
<script>
import Item from './Item.html';
export default {
data() {
return {
items: [3, 2, 1]
};
},
onrender() {
window.setTimeout(() => {
console.log("Setting items")
this.set({
items: this.get('list')
});
}, 5000)
},
components: {
Item
}
};
</script>
import Root from './Root.html';
const root = new Root({target: document.querySelector( 'body' )});
<div>
Root element
<List list={{list}} />
</div>
<script>
import List from './List.html';
export default {
data: () => ({
list: [1, 2, 3, 4, 5]
}),
components: {
List
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment