{"action":"created","issue":{"url":"https://api.github.com/repos/reactjs/redux/issues/580","repository_url":"https://api.github.com/repos/reactjs/redux","labels_url":"https://api.github.com/repos/reactjs/redux/issues/580/labels{/name}","comments_url":"https://api.github.com/repos/reactjs/redux/issues/580/comments","events_url":"https://api.github.com/repos/reactjs/redux/issues/580/events","html_url":"https://github.com/reactjs/redux/issues/580","id":101958114,"number":580,"title":"Is it possible to get action and state in store.subscribe?","user":{"login":"antonmedv","id":141232,"avatar_url":"https://avatars0.githubusercontent.com/u/141232?v=4","gravatar_id":"","url":"https://api.github.com/users/antonmedv","html_url":"https://github.com/antonmedv","followers_url":"https://api.github.com/users/antonmedv/followers","following_url":"https://api.github.com/users/antonmedv/following{/other_user}","gists_url":"https://api.github.com/users/antonmedv/gists{/gist_id}","starred_url":"https://api.github.com/users/antonmedv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antonmedv/subscriptions","organizations_url":"https://api.github.com/users/antonmedv/orgs","repos_url":"https://api.github.com/users/antonmedv/repos","events_url":"https://api.github.com/users/antonmedv/events{/privacy}","received_events_url":"https://api.github.com/users/antonmedv/received_events","type":"User","site_admin":false},"labels":[{"id":218057860,"url":"https://api.github.com/repos/reactjs/redux/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2015-08-19T17:50:47Z","updated_at":"2017-10-22T21:14:39Z","closed_at":"2015-08-20T21:51:48Z","author_association":"NONE","body":"I want to update my view in listener:\n\n``` js\nstore.subscribe(() => {\n    updateView(store.getState()); // Some DOM api calls.\n});\n```\n\nBut if it possible to get last action what triggered state change, i can do some think like this:\n\n``` js\nstore.subscribe(() => {\n    switch (action.type) {\n        case UPDATE_TITLE:\n            updateTitle(store.getState().some.title); // Optimize rendering of view. Only one DOM api call.\n        break;\n        default:\n            updateView(store.getState()); // Some DOM api calls.\n    }\n});\n```\n\nIs it possible to get action and state in store.subscribe?\n"},"comment":{"url":"https://api.github.com/repos/reactjs/redux/issues/comments/338509660","html_url":"https://github.com/reactjs/redux/issues/580#issuecomment-338509660","issue_url":"https://api.github.com/repos/reactjs/redux/issues/580","id":338509660,"user":{"login":"matigda","id":5388804,"avatar_url":"https://avatars0.githubusercontent.com/u/5388804?v=4","gravatar_id":"","url":"https://api.github.com/users/matigda","html_url":"https://github.com/matigda","followers_url":"https://api.github.com/users/matigda/followers","following_url":"https://api.github.com/users/matigda/following{/other_user}","gists_url":"https://api.github.com/users/matigda/gists{/gist_id}","starred_url":"https://api.github.com/users/matigda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matigda/subscriptions","organizations_url":"https://api.github.com/users/matigda/orgs","repos_url":"https://api.github.com/users/matigda/repos","events_url":"https://api.github.com/users/matigda/events{/privacy}","received_events_url":"https://api.github.com/users/matigda/received_events","type":"User","site_admin":false},"created_at":"2017-10-22T21:14:39Z","updated_at":"2017-10-22T21:14:39Z","author_association":"NONE","body":"Can somebody please explain a little better the idea behind this?\r\nBecause IMO it would make a lot easier implementing some UI changes ( like lazy load reloading ) if the action is passed to the listener. Right now it is being fired on every state change ( that's ok ) but without any data provided you actually need to have some global variable to compare, as it is given in example above ( and that's not quite ok ). And without previous state or action being passed I can't really see the real usage of that method anyways. Judging from examples of that method usage it seems like there wasn't a clear idea how it can be used in real world application without violating any rule. So again... what exactly would be broken here if the action is passed to the listener? "}}
{"actor":{"display_login":"matigda"}}