Redux action.type给出@@ redux / INIT

时间:2017-07-13 11:12:54

标签: reactjs redux

我的reducer文件如下。

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'。我不明白 。为什么会这样呢?我的操作文件在调试时提供了正确的数据。如何删除此错误?

1 个答案:

答案 0 :(得分:6)

创建商店后,@@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