action creator method must be called asynchronously
I've defined an action creator, and call some method direct in the view page (or in the constructor):
//action creator
MaintenanceActions.initCarInfo({
data: [{test:'test'}],
source: settings.fluxSource.cache
});
and listen to the event:
componentDidMount(){
let initCallback = function(){
console.log('init callback..');
}
//init
MaintenanceStore.addInitListener(initCallback);
}
the 'initCallback' function is not called. It seem that
this.on('init_event', callback)
doesn't handle.
But, if I call 'MaintenanceActions.initCarInfo()' in an event handler, like click event, or a ajax callback, it works.
Must I call the action creator method asynchronously?
I can't see any problem above your code. initCallback will call when you create a action
You shouldn't need to call an action creator asynchronously. You will want to ensure that your store has registered itself with the dispatcher before calling your action creators synchronously though.
Thanks, I should listen to the event, before the event is triggered:
componentDidMount(){
let initCallBack = function(){
console.log('init callback..');
}
// listen here, before event is triggered.
MaintenanceStore.addInitListener(initCallBack);
//触发action
MaintenanceActions.initCarInfo({
data: [{test:'test'}],
source: settings.fluxSource.cache
});
}
It works as expected.
Awesome, glad you figured it out!