I understand that I need a emit.change()
dispatcher, to let all components know that something changed inside the store. But I dont understand why I need to dispatch actions rather than calling stores directly from inside the actions,
.i.e. why should I do this:
var Dispatcher = require('dispatcher');
var MyActions = {
addItem: function(item){
Dispatcher.dispatch({
action: 'ADD_ITEM',
payload: item
})
}
}
rather than this:
var MyStore = require('mystore');
var MyActions = {
addItem: function(item){
MyStore.addItem(item);
}
}
Is that for the case that multiple stores listen to the same event, for example when StoreA
and StoreB
listen to ADD_ITEM
as well?