From 05f8e5a53b837400dc180d404b78b794a9179128 Mon Sep 17 00:00:00 2001 From: Connor Bryan Date: Fri, 13 Jul 2018 18:36:29 -0500 Subject: [PATCH] Refactor configNodes --- common/features/config/nodes/custom/reducer.ts | 12 ++++++------ common/features/config/nodes/custom/types.ts | 2 +- common/features/config/nodes/index.ts | 8 +++++--- common/features/config/nodes/reducer.ts | 16 ++++++++-------- common/features/config/nodes/selectors.ts | 16 +++++++++------- common/features/config/nodes/types.ts | 14 +++++++------- 6 files changed, 36 insertions(+), 32 deletions(-) diff --git a/common/features/config/nodes/custom/reducer.ts b/common/features/config/nodes/custom/reducer.ts index 04fbe41a..640ad9fc 100644 --- a/common/features/config/nodes/custom/reducer.ts +++ b/common/features/config/nodes/custom/reducer.ts @@ -1,26 +1,26 @@ import * as types from './types'; const addCustomNode = ( - state: types.CustomNodesState, + state: types.ConfigCustomNodesState, { payload }: types.AddCustomNodeAction -): types.CustomNodesState => ({ +): types.ConfigCustomNodesState => ({ ...state, [payload.id]: payload }); function removeCustomNode( - state: types.CustomNodesState, + state: types.ConfigCustomNodesState, { payload }: types.RemoveCustomNodeAction -): types.CustomNodesState { +): types.ConfigCustomNodesState { const stateCopy = { ...state }; Reflect.deleteProperty(stateCopy, payload); return stateCopy; } export function customNodesReducer( - state: types.CustomNodesState = {}, + state: types.ConfigCustomNodesState = {}, action: types.CustomNodeAction -): types.CustomNodesState { +): types.ConfigCustomNodesState { switch (action.type) { case types.ConfigNodesCustomActions.ADD: return addCustomNode(state, action); diff --git a/common/features/config/nodes/custom/types.ts b/common/features/config/nodes/custom/types.ts index 3c06f7d6..ad9f0c65 100644 --- a/common/features/config/nodes/custom/types.ts +++ b/common/features/config/nodes/custom/types.ts @@ -1,6 +1,6 @@ import { CustomNodeConfig } from 'types/node'; -export interface CustomNodesState { +export interface ConfigCustomNodesState { [customNodeId: string]: CustomNodeConfig; } diff --git a/common/features/config/nodes/index.ts b/common/features/config/nodes/index.ts index 70eae1b5..81fc5bb6 100644 --- a/common/features/config/nodes/index.ts +++ b/common/features/config/nodes/index.ts @@ -1,6 +1,8 @@ -export * from './types'; -export * from './reducer'; -export * from './selectors'; +import * as configNodesTypes from './types'; +import * as configNodesReducer from './reducer'; +import * as configNodesSelectors from './selectors'; + +export { configNodesTypes, configNodesReducer, configNodesSelectors }; export * from './custom'; export * from './selected'; diff --git a/common/features/config/nodes/reducer.ts b/common/features/config/nodes/reducer.ts index cedff3fb..ddff1817 100644 --- a/common/features/config/nodes/reducer.ts +++ b/common/features/config/nodes/reducer.ts @@ -1,12 +1,12 @@ import { combineReducers } from 'redux'; -import { customNodesReducer } from './custom/reducer'; -import { staticNodesReducer } from './static/reducer'; -import { selectedNodeReducer } from './selected/reducer'; -import { NodesState } from './types'; +import * as configNodesCustomReducer from './custom/reducer'; +import * as configNodesStaticReducer from './static/reducer'; +import * as configNodesSelectedReducer from './selected/reducer'; +import * as types from './types'; -export const nodesReducer = combineReducers({ - customNodes: customNodesReducer, - staticNodes: staticNodesReducer, - selectedNode: selectedNodeReducer +export const nodesReducer = combineReducers({ + customNodes: configNodesCustomReducer.customNodesReducer, + staticNodes: configNodesStaticReducer.staticNodesReducer, + selectedNode: configNodesSelectedReducer.selectedNodeReducer }); diff --git a/common/features/config/nodes/selectors.ts b/common/features/config/nodes/selectors.ts index 561a8fbd..5680fc5b 100644 --- a/common/features/config/nodes/selectors.ts +++ b/common/features/config/nodes/selectors.ts @@ -1,9 +1,9 @@ import { shepherdProvider, INode } from 'libs/nodes'; import { CustomNodeConfig, StaticNodeConfig } from 'types/node'; import { AppState } from 'features/reducers'; -import { getCustomNodeConfig } from './custom/selectors'; -import { getNodeId } from './selected/selectors'; -import { getStaticNodeConfig } from './static/selectors'; +import * as configNodesCustomSelectors from './custom/selectors'; +import * as configNodesSelectedSelectors from './selected/selectors'; +import * as configNodesStaticSelectors from './static/selectors'; function getConfig(state: AppState) { return state.config; @@ -15,8 +15,8 @@ export function getNodes(state: AppState) { export const getWeb3Node = (state: AppState): StaticNodeConfig | null => { const isWeb3Node = (nodeId: string) => nodeId === 'web3'; - const currNode = getStaticNodeConfig(state); - const currNodeId = getNodeId(state); + const currNode = configNodesStaticSelectors.getStaticNodeConfig(state); + const currNodeId = configNodesSelectedSelectors.getNodeId(state); if (currNode && currNodeId && isWeb3Node(currNodeId)) { return currNode; } @@ -24,7 +24,7 @@ export const getWeb3Node = (state: AppState): StaticNodeConfig | null => { }; export function getIsWeb3Node(state: AppState): boolean { - return getNodeId(state) === 'web3'; + return configNodesSelectedSelectors.getNodeId(state) === 'web3'; } export function getNodeLib(_: AppState): INode { @@ -32,7 +32,9 @@ export function getNodeLib(_: AppState): INode { } export function getNodeConfig(state: AppState): StaticNodeConfig | CustomNodeConfig { - const config = getStaticNodeConfig(state) || getCustomNodeConfig(state); + const config = + configNodesStaticSelectors.getStaticNodeConfig(state) || + configNodesCustomSelectors.getCustomNodeConfig(state); if (!config) { const { selectedNode } = getNodes(state); diff --git a/common/features/config/nodes/types.ts b/common/features/config/nodes/types.ts index e37e66d4..f7b0d7e4 100644 --- a/common/features/config/nodes/types.ts +++ b/common/features/config/nodes/types.ts @@ -1,9 +1,9 @@ -import { CustomNodesState } from './custom/types'; -import { StaticNodesState } from './static/types'; -import { SelectedNodeState } from './selected/types'; +import * as configNodesCustomTypes from './custom/types'; +import * as configNodesStaticTypes from './static/types'; +import * as configNodesSelectedTypes from './selected/types'; -export interface NodesState { - customNodes: CustomNodesState; - staticNodes: StaticNodesState; - selectedNode: SelectedNodeState; +export interface ConfigNodesState { + customNodes: configNodesCustomTypes.ConfigCustomNodesState; + staticNodes: configNodesStaticTypes.ConfigStaticNodesState; + selectedNode: configNodesSelectedTypes.ConfigNodesSelectedState; }