Created
January 24, 2017 13:44
-
-
Save dxlbnl/f0a6a52d3c8789be0c0fa25e1602667a to your computer and use it in GitHub Desktop.
Nesting updating components with svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Root from './Root.html'; | |
const root = new Root({target: document.querySelector( 'body' )}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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