2017-07-13 32 views
1

我的reducer文件如下。Redux action.type給出@@ redux/INIT

import { AppConstants } from '../constants'; 

const initialState = { 
    state: [], 
    menu_items: [], 
    addon_items: [], 
    save_items: [], 
    un_mapped_menu_items: false, 
    error: '' 
}; 

export default (state = initialState, action) => { 
switch (action.type) { 
    case AppConstants.getMenuItems: 
    return { 
    ...state, 
    } 
    case AppConstants.getMenuItemsSuccess: 
    return { 
    ...state, 
    menu_items: action.menu_items 
    } 
    case AppConstants.getAddonsItems: 
    return { 
    ...state, 
    } 
    case AppConstants.getAddonsItemsSuccess: 
    return { 
    ...state, 
    addon_items: action.addon_items 
    } 
    case AppConstants.getMenuItemsEdit: 
    return { 
    ...state, 
    } 
    case AppConstants.getMenuItemsSave: 
    return { 
    ...state, 
    save_items: action.save_items 
    } 
    case AppConstants.getUnmappedMenuItems: 
    return { 
    ...state, 
    error: action.error, 
    un_mapped_menu_items: true 
    } 
    case AppConstants.getMenuItemsError: 
    return { 
    ...state, 
    error: action.error 
    } 
    default: 
    return state 
    } 
}; 

當我調試我的reducer文件時,action.type顯示'@@ redux/INIT'。我不明白 。爲什麼這樣做呢?調試時,我的操作文件提供了正確的數據。我如何刪除此錯誤?

+0

你如何調試?你什麼時候記錄動作類型?順便說一句,減速器不會生成動作,這就是爲什麼顯示動作創建者文件的原因。 –

+0

如果您是通過AJAX獲得的,請分享您實際獲得動作和AJAX調用代碼的代碼。 –

回答

4

當一個存儲中創建一個@@redux/INIT動作由createStore

時調度代碼:

export var ActionTypes = { 
    INIT: '@@redux/INIT' 
} 

    // When a store is created, an "INIT" action is dispatched so that every 
    // reducer returns their initial state. This effectively populates 
    // the initial state tree. 
    dispatch({ type: ActionTypes.INIT }) 

在這裏看到的代碼: https://github.com/reactjs/redux/blob/v3.0.6/src/createStore.js