{"action":"opened","issue":{"url":"https://api.github.com/repos/gaearon/redux/issues/180","labels_url":"https://api.github.com/repos/gaearon/redux/issues/180/labels{/name}","comments_url":"https://api.github.com/repos/gaearon/redux/issues/180/comments","events_url":"https://api.github.com/repos/gaearon/redux/issues/180/events","html_url":"https://github.com/gaearon/redux/issues/180","id":91045387,"number":180,"title":"getState for all action creators","user":{"login":"itrelease","id":41234,"avatar_url":"https://avatars.githubusercontent.com/u/41234?v=3","gravatar_id":"","url":"https://api.github.com/users/itrelease","html_url":"https://github.com/itrelease","followers_url":"https://api.github.com/users/itrelease/followers","following_url":"https://api.github.com/users/itrelease/following{/other_user}","gists_url":"https://api.github.com/users/itrelease/gists{/gist_id}","starred_url":"https://api.github.com/users/itrelease/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/itrelease/subscriptions","organizations_url":"https://api.github.com/users/itrelease/orgs","repos_url":"https://api.github.com/users/itrelease/repos","events_url":"https://api.github.com/users/itrelease/events{/privacy}","received_events_url":"https://api.github.com/users/itrelease/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-06-25T18:47:29Z","updated_at":"2015-06-25T18:47:29Z","closed_at":null,"body":"So suppose we create dispatcher with promise middleware:\r\n\r\n```\r\nimport { createDispatcher, composeStores, createRedux } from 'redux';\r\nimport { Provider } from 'redux/react';\r\nimport * as stores from './stores/index';\r\nimport { thunkMiddleware, promiseMiddleware } from './middlewares';\r\n\r\nconst dispatcher = createDispatcher(\r\n  composeStores(stores),\r\n  getState => [promiseMiddleware, thunkMiddleware(getState)]\r\n);\r\nconst redux = createRedux(dispatcher);\r\n```\r\n\r\nand we have some action:\r\n\r\n```\r\nfunction fetchTodoItem(todoItemId) {\r\n  return {\r\n    types: [FETCH_TODO_ITEM, FETCH_TODO_ITEM_OK, FETCH_TODO_ITEM_FAIL],\r\n    promise: apiFetchTodoItem(todoItemId),\r\n    todoItemId\r\n  }\r\n}\r\n```\r\n\r\nbut in this action I want to check local store on presence this todo item to eliminate request, like this:\r\n\r\n```\r\nfunction fetchTodoItem(todoItemId, getState) {\r\n  const { todos } = getState();\r\n\r\n  if (todos[todoItemId]) {\r\n    return'\r\n  }\r\n\r\n  return {\r\n    types: [FETCH_TODO_ITEM, FETCH_TODO_ITEM_OK, FETCH_TODO_ITEM_FAIL],\r\n    promise: apiFetchTodoItem(todoItemId),\r\n    todoItemId\r\n  }\r\n}\r\n```\r\n\r\nThe problem that I have no access to `getState` function.\r\n\r\nOne of the solutions is to pass to `bindActionCreators` optional argument `getState` function:\r\n\r\n```\r\nexport default function bindActionCreators(actionCreators, dispatch, getState) {\r\n return mapValues(actionCreators, actionCreator =>\r\n   (...args) => dispatch(actionCreator(...args, getState))\r\n );\r\n}\r\n```\r\n\r\nso all actions can get state if they need it.\r\n"}}