2016-07-29 1 views
0

api 데이터를 저장소에 전달하려는 의도로 "조치"에 설정 페이로드가 있습니다. Dispatcher.register에서는 스위치 케이스가 트리거되지 않습니다.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) 디스패처 파일 : (주는 저장 작업을 내부 디버거는 트리거되지 않습니다)

4) 그것은 이상한 파일을

"use strict" 

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

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

답변

0

흠을 actionTypes.js. 모든 것이 정확 해 보입니다. 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>