refle中Action.do...();的事件执行顺序

场景

page文件里:

mixins:[Reflux.connect(Store)],
getInitialState: function () {
    Action.getInitData();
},

store文件里:

var Store = Reflux.createStore({

    listenables: [Action],

    data: {},

    onGetInitData : function(){
        var t = this;
        DB.Gate.getInitData().then(function (data) {

            t.updateComponent();
        });
    },

    updateComponent: function () {
        this.trigger(this.data);
    },

    getInitialState: function() {
        var t = this;
        this.data = {

        };
        return this.data;
    }
});

module.exports = Store;

顺序

  1. 首先执行store里的getInitialState,

  2. 再执行react的componentDidMount,如果在componentDidMount里执行console.log(this.state),会输出空的state,render里console.log的话也是同样效果。

  3. 当DB.Gate.getInitData()执行完后,会更新state,但是componentDidMount不会执行第二遍,但是render里的console.log()会输出新的state。

关键字:JavaScript, react.js, function, data


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部