index.community/frontend/src/redux/reducers.ts

51 lines
1.3 KiB
TypeScript
Raw Normal View History

2018-08-27 15:27:09 +00:00
import { combineReducers } from 'redux';
import { ActionType, IAction, IDataState } from './types';
2018-08-27 15:27:09 +00:00
const initialDataState = {
isLoadingGraph: false,
2018-08-27 15:27:09 +00:00
isLoadingInstances: false,
}
const data = (state: IDataState = initialDataState, action: IAction) => {
switch (action.type) {
case ActionType.REQUEST_INSTANCES:
return {
...state,
instances: [],
isLoadingInstances: true,
};
case ActionType.RECEIVE_INSTANCES:
return {
...state,
instances: action.payload,
isLoadingInstances: false,
};
case ActionType.REQUEST_GRAPH:
return {
...state,
isLoadingGraph: true,
};
case ActionType.RECEIVE_GRAPH:
return {
...state,
graph: action.payload,
isLoadingGraph: false,
};
2018-08-27 15:27:09 +00:00
default:
return state;
}
}
const currentInstanceName = (state: string | null = null, action: IAction): string | null => {
2018-08-27 15:27:09 +00:00
switch (action.type) {
case ActionType.SELECT_INSTANCE:
return action.payload;
default:
return state;
}
}
export const rootReducer = combineReducers({
currentInstanceName,
2018-08-27 15:27:09 +00:00
data,
})