Fluxible storeListeners事件发射器

时间:2015-03-12 05:57:48

标签: reactjs flux

有没有办法发现哪个处理程序触发了事件?

例如,我的商店:

handlers: {
        surahReceived(payload) {
            this._surah = payload.surah;
            this.emitChange();
        },
        ayahsReceived(payload) {
            this.dispatcher.waitFor('AyahStore', function() {
                this._surah.ayahs = this.dispatcher.getStore(AyahStore).getAyahs();
            }.bind(this));
            this.emitChange();
        },
        surahListReceived(payload) {
            this._surahs = payload.surahs;
            this.emitChange();
        }
    }

当最后一个函数触发时,我的听众:

statics: {
        storeListeners: {
            _onSurahReceived: [SurahStore]
        }
    },

我想知道哪个函数触发了事件

1 个答案:

答案 0 :(得分:1)

我找到了答案:

您可以将参数传递给emitChange

例如:

surahListReceived(payload) {
            this._surahs = payload.surahs;
            this.emitChange(1);
        }

然后在你看来:

statics: {
        storeListeners: {
            _onSurahReceived: [SurahStore]
        }
    },
_onSurahReceived: function(e) {
  console.log(e) // Should be 1
}