2020-06-18 09:48:45 +02:00
|
|
|
import { Action } from "redux";
|
|
|
|
|
|
|
|
export interface FlagsState {
|
|
|
|
actions: { [actionName: string]: ActionState }
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ActionState {
|
|
|
|
isLoading: boolean
|
|
|
|
}
|
|
|
|
|
2020-06-15 18:10:06 +02:00
|
|
|
const defaultState = {
|
|
|
|
actions: {}
|
|
|
|
};
|
|
|
|
|
2020-06-18 09:48:45 +02:00
|
|
|
export function flagsReducer(state = defaultState, action: Action): FlagsState {
|
2020-06-15 18:10:06 +02: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'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|