pitfalls when using riot - PuZheng/PuZheng-Docs GitHub Wiki
- create the same kind of store multiple times.
bad way:
riot.route.on(function (app) {
if (app === 'list') {
RiotControl.add(new StudentListStore()); // add a new store each time when "list" is hit
// ...
}
});
good way:
RiotControl.add(new StudentListStore());
riot.route.on(function (app) {
if (app === 'list') {
// ...
}
});
- mount the same tag again and again, where you should just update it.
bad way:
riot.route.on(function (app) {
if (app === 'list') {
riot.mount('#container', 'my-tag');
}
});
good way:
var myTag;
riot.route.on(function (app) {
if (app === 'list') {
myTag = myTag || riot.mount('#container', 'my-tag');
}
});
- in flux architecture, a store should only trigger events upon itself
bad way:
function MyStore() {
riot.observable(this);
this.on('fetch', function () {
$.getJSON('some url', function (data) {
RiotControl.trigger('fetched', data);
});
}); // in fact this will
}
good way:
function MyStore() {}