Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -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<T> = { request: T }
type S<T> = { response: T }
Expand Down Expand Up @@ -60,7 +60,7 @@ const _loadCount: ApiActionGroup<null, { value: number }> = {
type apiFunc<Q, S> = (q: Q) => Promise<S>

function apiActionGroupFactory<Q, S>(x: ApiActionGroup<Q, S>, go: apiFunc<Q, S>) {
return (request: Q) => (dispatch: redux.Dispatch<Store.All>) => {
return (request: Q) => (dispatch: redux.Dispatch<state.All>) => {
dispatch(x.request(request))
go(request)
.then((response) => dispatch(x.success(response, request)))
Expand Down
6 changes: 3 additions & 3 deletions src/components/counter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
saveCount,
} from '../actions'

import { Store } from '../reducers'
import * as state from '../reducers'

import loadable from '../decorators/loadable'

Expand All @@ -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<Store.All>): ConnectedDispatch => ({
const mapDispatchToProps = (dispatch: redux.Dispatch<state.All>): ConnectedDispatch => ({
increment: (n: number) =>
dispatch(incrementCounter(n)),
load: () =>
Expand Down
11 changes: 4 additions & 7 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Store.All> = redux.createStore(
reducers,
{} as Store.All,
let store: redux.Store<state.All> = redux.createStore(
state.reducers,
{} as state.All,
redux.applyMiddleware(thunk),
)

Expand Down
21 changes: 9 additions & 12 deletions src/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -72,7 +69,7 @@ function counter (state: Store.Counter = initialState, action: Action): Store.Co
}
}

export const reducers = combineReducers<Store.All>({
export const reducers = combineReducers<All>({
counter,
isSaving,
isLoading,
Expand Down