2016-07-29 23 views
0

我已經在「行動」中設置有效載荷,意圖分派API數據到商店。但是在Dispatcher.register中沒有觸發switch case。反應Dispatcher.dispatch的行動,而不是調度有效載荷存儲

流量版本: 「流量」: 「^ 2.1.1」,

1)操作文件:(注:已經證實,receivedAllServices通過使用調試器觸發)

"use strict" 

var Dispatcher = require('../dispatcher/appDispatcher'); 
// var requestActions = require('./requestActions'); 
var ActionTypes = require('../constants/actionTypes'); 

var ResponseActions = { 

    receivedAllServices: function(all_services){ 

     console.log('response received'); 
     debugger; 

     Dispatcher.dispatch({ 
      actionType: ActionTypes.RECEIVED_ALL_SERVICES, 
      services: all_servicess 
     }); 
    } 



}; 

module.exports = ResponseActions; 

2)店鋪(注:店內動作調試器內部沒有被觸發)

Dispatcher.register(function(action){ 
    switch(action.actionType){ 
     case ActionTypes.RECEIVED_ALL_SERVICES: 

      debugger; 

      // AuthorStore.emitChange(); 
      break; 
    } 
}); 

3)調度文件:

var Dispatcher = require('flux').Dispatcher; 

module.exports = new Dispatcher(); 

4)actionTypes.js文件

"use strict" 

var keyMirror = require('fbjs/lib/keyMirror'); 

module.exports = keyMirror({ 
    RECEIVED_ALL_SERVICES: null, 
}); 

回答

0

嗯,真奇怪。一切看起來正確。您可以檢查store.jsaction.js中的Dispatcher是否是相同的對象?

請參閱下面的動作/商店相同的簡短示例。所有作品都正確(按run並查看控制檯輸出)。

var appDispatcher = new Flux.Dispatcher(); 
 

 
// This code should be our action 
 
function receivedAllServices() { 
 
    appDispatcher.dispatch({ 
 
    actionType: 'RECEIVED_ALL_SERVICES', 
 
    services: ['serv1','serv2'], 
 
    }); 
 
    console.log('Done'); 
 
} 
 

 

 
// This code should be our store 
 
appDispatcher.register(action => { 
 
    console.log('action', action); 
 
    switch(action.actionType){ 
 
    case 'RECEIVED_ALL_SERVICES': 
 
     //debugger; 
 
     // AuthorStore.emitChange(); 
 
     console.log('AuthorStore.emitChange'); 
 
     break; 
 
    } 
 
}); 
 

 
// Call the action 
 
receivedAllServices();
<script src="https://cdnjs.cloudflare.com/ajax/libs/flux/2.1.1/Flux.js"></script>

相關問題