srp*_*rph 7 javascript flux reactjs refluxjs
使用RefluxJS初始化数据(异步)的正确方法是什么?是否有类似于AngularJS的解决方案,或者Flux实现与此无关(路由器应该处理这种可靠性)?
Mat*_*ohn 10
在应用程序的顶级组件中,使用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()
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4249 次 |
| 最近记录: |