Open
Description
I'd like suggest an little improvement around RiotControl. I've created a simple application using ES6 syntax, and my store is simple ES6 class, that looks like:
import riot from 'riot';
class ContatoStore {
constructor() {
riot.observable(this);
this.state = [{id:'192', nome:'Abdoral Gusmao', email:'[email protected]'}];
this.on('contact_add', this.add);
this.on('contact_remove', this.remove);
this.on('contact_load', this.load);
}
load() {
this.trigger('contact_change', this.state);
}
add(contato) {
console.log('New Contact');
}
remove(id) {
console.log('Remove contact');
}
}
module.exports = ContatoStore;
There is nothing wrong with this code below, but RiotControl print out on browser's console Cannot read property 'apply' of undefined
. This error message is because el
is a function and it's not an object instance. I just did some adjustment on API, putting a validation that shows warning message. But my suggestion is to resolve this issue checking type and instantiating a object in case of function.
['on','one','off','trigger'].forEach(function(api){
RiotControl[api] = function() {
var args = [].slice.call(arguments);
this._stores.forEach(function(el) {
if (typeof el === 'object')
el[api].apply(null, args);
else
console.warn(el.name +' is not an object instance.')
});
};
});
Metadata
Metadata
Assignees
Labels
No labels