daddy/frontend/src/store/reducers/flags.ts

22 lines
407 B
TypeScript
Raw Normal View History

2020-06-15 18:10:06 +02:00
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'
}
}
};
}