Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 3 additions & 4 deletions src/store/Todos/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -28,15 +27,15 @@ 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',
response: normalize(response, schema.todoSchema)
})
})

export const toggleTodo = (id) => (dispatch) =>
export const toggleTodo = (id) => (dispatch, getState, api) =>
api.toggleTodo(id).then(response => {
dispatch({
type: 'TOGGLE_TODO_SUCCESS',
Expand Down
3 changes: 2 additions & 1 deletion src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down