Flux React gulp

时间:2015-12-07 17:11:17

标签: javascript reactjs flux reactjs-flux

尝试创建Flux商店。当我运行gulp并检查我的index.html时,我收到一个错误" Uncaught TypeError:listener必须是一个函数"

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        // Respond to the action bar's Up/Home button
        case android.R.id.home:
            goBack();
            return true;
    }
    return super.onOptionsItemSelected(item);
}

private void goBack(){
    super.onBackPressed();
    overridePendingTransition(R.anim.trans_right_in, R.anim.trans_right_out);
    Log.d("Activity:", "EXIT");
}

@Override
public void onBackPressed() {
    goBack();
}

以下是唯一具有监听器的组件

var AppDispatcher = require('../dispatchers/app-dispatcher');
var AppConstants = require('../constants/app-constants');
var assign = require('object-assign'); 
var EventEmitterProto = require('events').EventEmitter.prototype;
var CHANGE_EVENT = 'CHANGE'; //broadcast this everytime there is a change

var _catalog = [];
var _cartItems = [];

var AppStore = assign(EventEmitterProto, {
    emitChange: function(){
    this.emit(CHANGE_EVENT)
},
addChangeListener: function(callback){
    this.on(CHANGE_EVENT, callback); //<---if I comment this out code runs perfect
},
removeChangeListener: function(callback){
    this.removeListener(CHANGE_EVENT, callback)
},
getCart: function(){
    return _cartItems
},
getCatalog: function(){
    return _catalog
},
getCartTotals: function(){
    return _cartTotals()
}

});
module.exports = AppStore;

请帮忙。这真是伤害了我的脑袋

1 个答案:

答案 0 :(得分:1)

您可能需要更改

AppStore.addChangeListener(this._onChange)

componentDidMount函数的逻辑,如

   componentDidMount:function(){
      AppStore.addChangeListener(this._onChange)
    }