diff --git a/README.md b/README.md index e0f2e3c..08b12f0 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ with actions ### Reducer Composition A common pattern used in Redux that has different *reducers* specify how -different parts of the *state* tree are updated in response to *acitons*. +different parts of the *state* tree are updated in response to *actions*. *Reducers* are normal JavaScript functions, so they can call other *reducers* to delegate and abstract away handling of updates of some parts of the *state* they manage. The updates are then combined into one larger state object. diff --git a/src/store/Todos/actions.js b/src/store/Todos/actions.js index 376036a..82aab65 100644 --- a/src/store/Todos/actions.js +++ b/src/store/Todos/actions.js @@ -2,9 +2,8 @@ import { normalize } from 'normalizr' import * as schema from '../schema' import { getIsFetching } from './selectors' -import * as api from '../../api' -export const fetchTodos = (filter) => (dispatch, getState) => { +export const fetchTodos = (filter) => (dispatch, getState, api) => { if (getIsFetching(getState(), filter)) { return Promise.resolve() } @@ -28,7 +27,7 @@ export const fetchTodos = (filter) => (dispatch, getState) => { ) } -export const addTodo = (text) => (dispatch) => +export const addTodo = (text) => (dispatch, getState, api) => api.addTodo(text).then(response => { dispatch({ type: 'ADD_TODO_SUCCESS', @@ -36,7 +35,7 @@ export const addTodo = (text) => (dispatch) => }) }) -export const toggleTodo = (id) => (dispatch) => +export const toggleTodo = (id) => (dispatch, getState, api) => api.toggleTodo(id).then(response => { dispatch({ type: 'TOGGLE_TODO_SUCCESS', diff --git a/src/store/index.js b/src/store/index.js index 167bbcf..b3b3762 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -3,9 +3,10 @@ import thunk from 'redux-thunk' import createLogger from 'redux-logger' import todos from './Todos/reducers' +import * as api from '../api' const configureStore = () => { - let middlewares = [thunk] + let middlewares = [thunk.withExtraArgument(api)] if (process.env.NODE_ENV !== 'production') { middlewares.push(createLogger())