From b37779b11fa0e5ca59fc717a55a7de83da66f912 Mon Sep 17 00:00:00 2001 From: RJ Zaworski Date: Fri, 1 Sep 2017 04:14:52 -0700 Subject: [PATCH] Drops unneeded namespace (fixes #19) --- src/actions/index.ts | 4 ++-- src/components/counter.tsx | 6 +++--- src/index.tsx | 11 ++++------- src/reducers/index.ts | 21 +++++++++------------ 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/actions/index.ts b/src/actions/index.ts index 07709cd..6b0ce2c 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -1,7 +1,7 @@ import * as redux from 'redux' import { api } from '../api' -import { Store } from '../reducers/index' +import * as state from '../reducers/index' type Q = { request: T } type S = { response: T } @@ -60,7 +60,7 @@ const _loadCount: ApiActionGroup = { type apiFunc = (q: Q) => Promise function apiActionGroupFactory(x: ApiActionGroup, go: apiFunc) { - return (request: Q) => (dispatch: redux.Dispatch) => { + return (request: Q) => (dispatch: redux.Dispatch) => { dispatch(x.request(request)) go(request) .then((response) => dispatch(x.success(response, request))) diff --git a/src/components/counter.tsx b/src/components/counter.tsx index 04bdcd5..2c6d1c9 100644 --- a/src/components/counter.tsx +++ b/src/components/counter.tsx @@ -8,7 +8,7 @@ import { saveCount, } from '../actions' -import { Store } from '../reducers' +import * as state from '../reducers' import loadable from '../decorators/loadable' @@ -28,14 +28,14 @@ type ConnectedDispatch = { load: () => void } -const mapStateToProps = (state: Store.All, ownProps: OwnProps): ConnectedState => ({ +const mapStateToProps = (state: state.All, ownProps: OwnProps): ConnectedState => ({ counter: state.counter, isSaving: state.isSaving, isLoading: state.isLoading, error: state.error, }) -const mapDispatchToProps = (dispatch: redux.Dispatch): ConnectedDispatch => ({ +const mapDispatchToProps = (dispatch: redux.Dispatch): ConnectedDispatch => ({ increment: (n: number) => dispatch(incrementCounter(n)), load: () => diff --git a/src/index.tsx b/src/index.tsx index 72399b9..99949e7 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -4,16 +4,13 @@ import * as redux from 'redux' import { Provider } from 'react-redux' import thunk from 'redux-thunk' -import { - reducers, - Store, -} from './reducers' +import * as state from './reducers' import { Counter } from './components/counter' -let store: redux.Store = redux.createStore( - reducers, - {} as Store.All, +let store: redux.Store = redux.createStore( + state.reducers, + {} as state.All, redux.applyMiddleware(thunk), ) diff --git a/src/reducers/index.ts b/src/reducers/index.ts index 3a16240..7f6ce62 100644 --- a/src/reducers/index.ts +++ b/src/reducers/index.ts @@ -2,16 +2,13 @@ import { combineReducers } from 'redux' import { Action } from '../actions' -export namespace Store { +export type Counter = { value: number } - export type Counter = { value: number } - - export type All = { - counter: Counter, - isSaving: boolean, - isLoading: boolean, - error: string, - } +export type All = { + counter: Counter, + isSaving: boolean, + isLoading: boolean, + error: string, } function isSaving (state: boolean = false, action: Action): boolean { @@ -51,11 +48,11 @@ function error (state: string = '', action: Action): string { } } -const initialState: Store.Counter = { +const initialState: Counter = { value: 0, } -function counter (state: Store.Counter = initialState, action: Action): Store.Counter { +function counter (state: Counter = initialState, action: Action): Counter { switch (action.type) { case 'INCREMENT_COUNTER': const { delta } = action @@ -72,7 +69,7 @@ function counter (state: Store.Counter = initialState, action: Action): Store.Co } } -export const reducers = combineReducers({ +export const reducers = combineReducers({ counter, isSaving, isLoading,