动作永远不会到达减速器?

时间:2019-11-20 18:51:36

标签: javascript reactjs react-native redux

我在我的应用程序中添加了一个新的reducer。为了测试它是否正常工作,我只是试图将其挂接到一个动作上。但是,当调用此动作时,我在devTools中正确执行了该动作,但是它从未到达减速器。我正在使用reduxpersist v6,并认为问题出在那儿,我的应用程序存在很多错误,因为我尝试保留多个reducer。

我的商店:

const todoPersistConfig = {
  key: 'TodoReducer',
  storage: AsyncStorage,
  whitelist: ['todos'],
  stateReconciler: autoMergeLevel2
};

const storageConfig = {
  key: 'StorageReducer',
  storage: AsyncStorage,
  whitelist: ['IDs'],
  stateReconciler: autoMergeLevel2
};

const rootPersistConfig = {
  key: 'root',
  storage: AsyncStorage,
  whitelist: ['TodoReducer', 'StorageReducer'],
  stateReconciler: autoMergeLevel2
};

const reducers = combineReducers({
  ModalReducer,
  StorageReducer: persistReducer(storageConfig, StorageReducer),
  TodoReducer: persistReducer(todoPersistConfig, TodoReducer),
  AuthReducer
});

const persistedReducer = persistReducer(rootPersistConfig, reducers);

export default function storeConfiguration() {
  const store = createStore(
    persistedReducer,
    {},
    composeEnhancers(
      applyMiddleware(ReduxThunk)
    )
  );

  const persistor = persistStore(store);

  return { persistor, store };
}

我的存储减速器:

import ADD_NOTIFICATION_ID from '../actions/types';

const initialState = {
  IDs: []
};

const storage = (state = initialState, action) => {
  switch (action.type) {
    case ADD_NOTIFICATION_ID:
      console.log('called on');
      return {
        ...state,
        IDs:
        [
          ...state.IDs,
          {
            itemID: action.item.id,
            reminderType: action.reminderType,
            notificationID: action.notificationID
          }
        ]
      };
    default:
      return state;
  }
};

export default storage;

正确调用的动作:

export const addNotificationID = (item, reminderType, notificationID) => {
  return {
    type: ADD_NOTIFICATION_ID,
    notificationID,
    item,
    reminderType
  };
};

我以前曾将此动作转到其他异径管上,但该虫已被窃听,因此我试图制作一个新的异径管并重新开始。但是现在,当操作完成时,Reducer中的控制台日志甚至都不会触发。它没有到达减速器。

2 个答案:

答案 0 :(得分:1)

距离我上次查看redux-persist已经有一段时间了,但是我怀疑这行可能是个问题

const persistedReducer = persistReducer(rootPersistConfig, reducers);

如果您要坚持使用儿童减压器,那么就不必同时坚持整个商店。

答案 1 :(得分:0)

answer是我的导入。 ListsViewController是我应该做的。