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

22 lines
402 B
JavaScript
Raw Normal View History

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