用RefluxJS (异步)初始化数据的正确方法是什么?是否有类似于AngularJS的解析,或者Flux实现与此无关(路由器应该处理此响应性)?
发布于 2015-01-23 01:13:19
在应用程序的顶层组件中,使用comoponentWillMount方法(docs)来触发获取数据的操作。该方法将在组件最初呈现时被调用。
例如:
// Create an async action, that will request data using a promise
// Using the recently released (v0.2.2) helpers for async actions
var actions = Reflux.createActions({
init: {asyncResult: true}
});
actions.init.listenAndPromise(promiseToGetData);
// Update the store when the init action's promise is completed
var store = Reflux.createStore({
listenables: actions,
onInitCompleted: function (data) {
// do stuff
this.trigger(data)
}
});
var App = React.createClass({
mixins: [Reflux.connect(store)],
componentWillMount: function () {
// When this component is loaded, fetch initial data
actions.init()
}
});发布于 2015-08-01 03:32:05
https://stackoverflow.com/questions/28012356
复制相似问题