PromucFlow_constructor/app/client/src/utils/ReducerUtils.ts

41 lines
1.5 KiB
TypeScript
Raw Normal View History

import type { ReduxAction } from "ee/constants/ReduxActionConstants";
2022-08-04 05:40:44 +00:00
import produce from "immer";
export const createReducer = (
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2022-08-04 05:40:44 +00:00
initialState: any,
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2022-08-04 05:40:44 +00:00
handlers: { [type: string]: (state: any, action: any) => any },
) => {
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2022-08-04 05:40:44 +00:00
return function reducer(state = initialState, action: ReduxAction<any>) {
if (handlers.hasOwnProperty(action.type)) {
return handlers[action.type](state, action);
} else {
return state;
}
};
};
export const createImmerReducer = (
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2022-08-04 05:40:44 +00:00
initialState: any,
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2022-08-04 05:40:44 +00:00
handlers: { [type: string]: any },
) => {
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2022-08-04 05:40:44 +00:00
return function reducer(state = initialState, action: ReduxAction<any>) {
if (handlers.hasOwnProperty(action.type)) {
return produce(handlers[action.type])(state, action);
} else {
return state;
}
};
};