0
我有一個操作需要在自己的商店中流動數據,但也需要在配置商店中流動。我需要這個,因爲添加的數據不同&它也得到了不同的清除。作用於多個商店的行爲
我想知道在這種情況下,如果它會更好地使用聯合減速機?或者在多個商店採取行動是可接受的解決方案
import { PAGE_CHANGE_TITLE } from 'actions/types/page.types';
import { PROJECT_SELECTED } from 'actions/types/projects.types';
const initialState = {
pages: {
last: {},
current: {},
last5: [],
},
project: localStorage.getItem('project') || {},
};
export function configs(state = initialState, action) {
switch (action.type) {
case PAGE_CHANGE_TITLE:
const last5 = [...state.pages.last5];
last5.unshift(action.data);
if (last5.length > 5) {
last5.pop();
}
return {
...state,
pages: {
last: {
...state.pages.current,
},
current: {
...action.data,
},
last5: last5,
},
};
case PROJECT_SELECTED:
return {
...state,
project: {
...action.data,
},
};
default:
return state;
}
}