{"action":"created","issue":{"url":"https://api.github.com/repos/gaearon/redux/issues/368","labels_url":"https://api.github.com/repos/gaearon/redux/issues/368/labels{/name}","comments_url":"https://api.github.com/repos/gaearon/redux/issues/368/comments","events_url":"https://api.github.com/repos/gaearon/redux/issues/368/events","html_url":"https://github.com/gaearon/redux/issues/368","id":98256974,"number":368,"title":"Forbid dispatch from inside a reducer","user":{"login":"gaearon","id":810438,"avatar_url":"https://avatars.githubusercontent.com/u/810438?v=3","gravatar_id":"","url":"https://api.github.com/users/gaearon","html_url":"https://github.com/gaearon","followers_url":"https://api.github.com/users/gaearon/followers","following_url":"https://api.github.com/users/gaearon/following{/other_user}","gists_url":"https://api.github.com/users/gaearon/gists{/gist_id}","starred_url":"https://api.github.com/users/gaearon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gaearon/subscriptions","organizations_url":"https://api.github.com/users/gaearon/orgs","repos_url":"https://api.github.com/users/gaearon/repos","events_url":"https://api.github.com/users/gaearon/events{/privacy}","received_events_url":"https://api.github.com/users/gaearon/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/gaearon/redux/labels/help%20wanted","name":"help wanted","color":"159818"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/gaearon/redux/milestones/1","html_url":"https://github.com/gaearon/redux/milestones/1.0","labels_url":"https://api.github.com/repos/gaearon/redux/milestones/1/labels","id":1174630,"number":1,"title":"1.0","description":"","creator":{"login":"johanneslumpe","id":3470207,"avatar_url":"https://avatars.githubusercontent.com/u/3470207?v=3","gravatar_id":"","url":"https://api.github.com/users/johanneslumpe","html_url":"https://github.com/johanneslumpe","followers_url":"https://api.github.com/users/johanneslumpe/followers","following_url":"https://api.github.com/users/johanneslumpe/following{/other_user}","gists_url":"https://api.github.com/users/johanneslumpe/gists{/gist_id}","starred_url":"https://api.github.com/users/johanneslumpe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johanneslumpe/subscriptions","organizations_url":"https://api.github.com/users/johanneslumpe/orgs","repos_url":"https://api.github.com/users/johanneslumpe/repos","events_url":"https://api.github.com/users/johanneslumpe/events{/privacy}","received_events_url":"https://api.github.com/users/johanneslumpe/received_events","type":"User","site_admin":false},"open_issues":7,"closed_issues":5,"state":"open","created_at":"2015-06-22T07:47:23Z","updated_at":"2015-07-30T20:27:12Z","due_on":null,"closed_at":null},"comments":9,"created_at":"2015-07-30T20:27:12Z","updated_at":"2015-07-30T21:32:15Z","closed_at":null,"body":"We should throw if you attempt to dispatch while the reducer is being called.\r\n\r\nNote that this will *not* cause the dreaded `Cannot dispatch in a middle of dispatch` if you `dispatch` from component's `componentDidMount` or `componentWillReceiveProps`. Unlike Flux, we don't have this problem, because **we call all subscribers *after* the reducer is called**.\r\n\r\nThis means we can set a flag immediately before `currentState = reducer(currentState, action)` in `createStore` and reset it on the next line, so everything happens before the subscribers are called. The subscribers should be able to call `dispatch` just fine.\r\n\r\nI'd very much like to see this as a PR as I don't have much time. It needs to:\r\n\r\n* Introduce the error if you dispatch while the reducer is evaluating.\r\n* Include a test for this.\r\n* Should not fail the existing “should handle nested dispatches gracefully” test\r\n\r\nPlease build it on top of `breaking-changes-1.0` branch."},"comment":{"url":"https://api.github.com/repos/gaearon/redux/issues/comments/126496428","html_url":"https://github.com/gaearon/redux/issues/368#issuecomment-126496428","issue_url":"https://api.github.com/repos/gaearon/redux/issues/368","id":126496428,"user":{"login":"gaearon","id":810438,"avatar_url":"https://avatars.githubusercontent.com/u/810438?v=3","gravatar_id":"","url":"https://api.github.com/users/gaearon","html_url":"https://github.com/gaearon","followers_url":"https://api.github.com/users/gaearon/followers","following_url":"https://api.github.com/users/gaearon/following{/other_user}","gists_url":"https://api.github.com/users/gaearon/gists{/gist_id}","starred_url":"https://api.github.com/users/gaearon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gaearon/subscriptions","organizations_url":"https://api.github.com/users/gaearon/orgs","repos_url":"https://api.github.com/users/gaearon/repos","events_url":"https://api.github.com/users/gaearon/events{/privacy}","received_events_url":"https://api.github.com/users/gaearon/received_events","type":"User","site_admin":false},"created_at":"2015-07-30T21:32:15Z","updated_at":"2015-07-30T21:32:15Z","body":"If it's a middleware, I doubt anybody who'd be affected by the error (beginners) would know to use it.\r\nWhy would you want to dispatch inside a reducer? It's grossly misusing the library.\r\nIt's exactly the same as React doesn't allow you to `setState` inside `render`."}}