mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-30 08:09:35 +02:00
36 lines
770 B
TypeScript
36 lines
770 B
TypeScript
|
import { ActionTypes, Action } from '../actions';
|
||
|
import { Config } from '../../interfaces';
|
||
|
|
||
|
export interface State {
|
||
|
loading: boolean;
|
||
|
config: Config[];
|
||
|
}
|
||
|
|
||
|
const initialState: State = {
|
||
|
loading: true,
|
||
|
config: []
|
||
|
}
|
||
|
|
||
|
const getConfig = (state: State, action: Action): State => {
|
||
|
return {
|
||
|
loading: false,
|
||
|
config: action.payload
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const updateConfig = (state: State, action: Action): State => {
|
||
|
return {
|
||
|
...state,
|
||
|
config: action.payload
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const configReducer = (state: State = initialState, action: Action) => {
|
||
|
switch(action.type) {
|
||
|
case ActionTypes.getConfig: return getConfig(state, action);
|
||
|
case ActionTypes.updateConfig: return updateConfig(state, action);
|
||
|
default: return state;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default configReducer;
|