gengitkan/client/src/store/reducers/flags.ts

22 lines
407 B
TypeScript
Raw Normal View History

2019-12-01 22:12:13 +01:00
const defaultState = {
actions: {}
};
2020-04-30 13:02:56 +02:00
export function flagsReducer(state = defaultState, action: any) {
2019-12-01 22:12:13 +01:00
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'
}
}
};
}