I have a simple code
<test>
<ul>
<li each={ books }> { title }</li>
</ul>
<button type="button" name="button" onclick={ loadBooks }>Load books</button>
<script>
'use strict';
this.books = [];
let offset = 0;
this.on('mount', () => {
console.log('mounted');
});
this.on('update', () => {
console.log('updated');
});
loadBooks () {
fetch('/api/books?limit=10&offset='+offset)
.then(response => response.json())
.then(books => {
offset+=10;
this.books = books;
// this.update();
})
.catch(err => console.log(err));
}
</script>
in my app.js i just requrie riot, test.tag and do riot.mount('#root', 'test');
this is init screen, why update fired before mount ? when i click first time, it log that update fired but view do not re-rendered and after second click, event update fired and view re-rendered
if i uncomment this.update();
inside promise, event update will fired twice
upd: if remove this.books = books
and write this.update({books});
event update will fire twice, and render will work, but why 2 times???
1) update
before mount
: this is fixed in @next / 3.0.0, as per: https://github.com/riot/riot/issues/1661
2) Why 2x update
: possibly, one from the tag and one regarding the child tag. This was asked here: https://muut.com/i/riot-js/using:why-update-event-is-trigg
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.