2018-02-12 20:43:07 +00:00
|
|
|
import {
|
|
|
|
TypeKeys,
|
|
|
|
CustomNodeAction,
|
|
|
|
AddCustomNodeAction,
|
|
|
|
RemoveCustomNodeAction
|
|
|
|
} from 'actions/config';
|
2018-04-05 20:53:36 +00:00
|
|
|
import { CustomNodesState as State } from './types';
|
2018-02-12 20:43:07 +00:00
|
|
|
|
|
|
|
const addCustomNode = (state: State, { payload }: AddCustomNodeAction): State => ({
|
|
|
|
...state,
|
2018-05-29 14:51:42 +00:00
|
|
|
[payload.id]: payload
|
2018-02-12 20:43:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function removeCustomNode(state: State, { payload }: RemoveCustomNodeAction): State {
|
|
|
|
const stateCopy = { ...state };
|
2018-05-29 14:51:42 +00:00
|
|
|
Reflect.deleteProperty(stateCopy, payload);
|
2018-02-12 20:43:07 +00:00
|
|
|
return stateCopy;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const customNodes = (state: State = {}, action: CustomNodeAction): State => {
|
|
|
|
switch (action.type) {
|
|
|
|
case TypeKeys.CONFIG_ADD_CUSTOM_NODE:
|
|
|
|
return addCustomNode(state, action);
|
|
|
|
case TypeKeys.CONFIG_REMOVE_CUSTOM_NODE:
|
|
|
|
return removeCustomNode(state, action);
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|