22 lines
407 B
TypeScript
22 lines
407 B
TypeScript
|
const defaultState = {
|
||
|
actions: {}
|
||
|
};
|
||
|
|
||
|
export function flagsReducer(state = defaultState, action: any) {
|
||
|
const matches = (/^(.*)_((SUCCESS)|(FAILURE)|(REQUEST))$/).exec(action.type);
|
||
|
|
||
|
if(!matches) return state;
|
||
|
|
||
|
const actionPrefix = matches[1];
|
||
|
|
||
|
return {
|
||
|
...state,
|
||
|
actions: {
|
||
|
...state.actions,
|
||
|
[actionPrefix]: {
|
||
|
isLoading: matches[2] === 'REQUEST'
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
}
|