搜索了一段时间这样的问题,但没有找到任何内容。基本上,当用户登录会话时,会从redux saga中调用设置获取,然后我将这些值放在适当的存储中,但当我执行另一个操作时,甚至不调用reducer中的函数,我会神奇地看到我的项目从存储中消失,只剩下15个对象中的3个。搜索了整个应用程序,看看我是否在其他地方调用了setSettings,但没有,只是在一个地方(传奇(。屏幕截图和代码如下:setadditionalinfo是接口reducer中的一个函数,它甚至没有传奇!
功能.saga.js
export function* settingsStartProcess() {
try {
const response = yield call(SYSTEMCALLS.fetchSettings)
yield put(setSettings(response.data));
} catch (error) {
yield put(setFetchSettingsFailure(error.message));
}
}
export function* fetchSettingsStart() {
yield takeLatest(
FunctionalityActionTypes.FETCH_SETTINGS_START,
settingsStartProcess
);
}
export function* functionalitySagas() {
yield all([
call(fetchSettingsStart),
]);
}
functionity.reducer.js
const functionalityReducer = (state = INITIAL_STATE, action) => {
switch (action.type) {
case FunctionalityActionTypes.SET_SETTINGS:
return {
...state,
isLoading: false,
functions: convertFunctions(action.payload.funzionalita, true),
branches: action.payload.sigleRami
};
case FunctionalityActionTypes.FETCH_SETTINGS_START:
return {
...state,
isLoading: true
};
case FunctionalityActionTypes.FETCH_SETTINGS_FAILURE:
return {
...state,
isLoading: false,
error: action.payload
};
default:
return state;
}
};
如果它可以干扰状态,但不应该添加这个user.selector代码:
export const selectCleanUserBranches = createSelector(
[selectUser, selectFunc],
(user, func) => createCleanDataFromUserSigle(user.currentUser.sigle, func.branches)
);
export const selectTreeDataUserBranches = createSelector(
[selectUser, selectFunc],
(user, func) => convertSigleToTreeData(createCleanDataFromUserSigle(user.currentUser.sigle, func.branches))
);
为任何有相同问题的人找到了解决方案。显然,我跳过了选择器返回引用而不是干净的物体。因此,将可能更改import{product}中选择器的函数从"immer"包装起来,或者在函数中调用Object.assign((以生成非ref克隆。