Daniel Ternyak 7930ab6611
Revert "Upgrade to Webpack 4 (#1386)" (#1406)
This reverts commit d19c4f44e6b74fee412e69019cb2c98c876e1c8e.
2018-03-28 14:34:29 -05:00

34 lines
884 B
TypeScript

import {
TypeKeys,
CustomNodeAction,
AddCustomNodeAction,
RemoveCustomNodeAction
} from 'actions/config';
import { CustomNodeConfig } from 'types/node';
export interface State {
[customNodeId: string]: CustomNodeConfig;
}
const addCustomNode = (state: State, { payload }: AddCustomNodeAction): State => ({
...state,
[payload.id]: payload.config
});
function removeCustomNode(state: State, { payload }: RemoveCustomNodeAction): State {
const stateCopy = { ...state };
Reflect.deleteProperty(stateCopy, payload.id);
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;
}
};