{"action":"created","issue":{"url":"https://api.github.com/repos/zalmoxisus/redux-devtools-extension/issues/281","repository_url":"https://api.github.com/repos/zalmoxisus/redux-devtools-extension","labels_url":"https://api.github.com/repos/zalmoxisus/redux-devtools-extension/issues/281/labels{/name}","comments_url":"https://api.github.com/repos/zalmoxisus/redux-devtools-extension/issues/281/comments","events_url":"https://api.github.com/repos/zalmoxisus/redux-devtools-extension/issues/281/events","html_url":"https://github.com/zalmoxisus/redux-devtools-extension/issues/281","id":199510984,"number":281,"title":"getState() returns old state for multiple dispatchs on replaying actions","user":{"login":"narak","id":803063,"avatar_url":"https://avatars.githubusercontent.com/u/803063?v=3","gravatar_id":"","url":"https://api.github.com/users/narak","html_url":"https://github.com/narak","followers_url":"https://api.github.com/users/narak/followers","following_url":"https://api.github.com/users/narak/following{/other_user}","gists_url":"https://api.github.com/users/narak/gists{/gist_id}","starred_url":"https://api.github.com/users/narak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/narak/subscriptions","organizations_url":"https://api.github.com/users/narak/orgs","repos_url":"https://api.github.com/users/narak/repos","events_url":"https://api.github.com/users/narak/events{/privacy}","received_events_url":"https://api.github.com/users/narak/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-01-09T09:45:32Z","updated_at":"2017-01-10T09:56:38Z","closed_at":null,"body":"Not sure if this should go in devtool-instrument or, devtools or devtools-extension repo.\r\n\r\nI tried debugging it, to check if there is some issue with my code. What I figured was that currentStateIndex isn't incrementing to the latest value and continues returning the old state.\r\nTo make it clear, this only happens when I'm trying to replay actions using the devtools extension.\r\n\r\n*Here is what I'm doing:*\r\nI'm not using any middleware or any package other than `redux` itself.\r\nFollowing is what my code more or less looks like, its untested but it represents what I'm trying to do more or less accurately:\r\n\r\n\r\n#### Container component\r\n```\r\n...\r\ngetState = () = {\r\n    const { store } = this.context,\r\n    const state = store.getState();\r\n    if (!state.users['id1']) {\r\n        store.dispatch({type: 'USERS_GET', isPending: true});\r\n        getUser('id1', function(error, response) {\r\n            store.dispatch({type: 'USERS_GET', isPending: false, error, response});\r\n        });\r\n    }\r\n    return  { user: state.users['id1'] };\r\n}\r\nconstructor() {\r\n    this.state = this.getState();\r\n}\r\ncomponentWillRecieveProps() {\r\n    this.setState(this.getState());\r\n}\r\n...\r\n```\r\n\r\n#### Reducer\r\n```\r\nfunction usersReducer(state = {}, action) {\r\n    if (action.type === 'USERS_GET') {\r\n        const id = action.filters.id;\r\n\r\n        if (action.isPending) {\r\n            state = {\r\n                ...state,\r\n                [id]: { isPending: true }\r\n            };\r\n        } else {\r\n            state = {\r\n                ...state,\r\n                [id]: action.response\r\n            };\r\n        }\r\n    }\r\n    return state;\r\n}\r\n\r\nconst store = createStore(\r\n    combineReducers({users: usersReducer}),\r\n    composeWithDevTools()\r\n)\r\n```\r\n\r\nThis works fine as long as I'm not replaying actions. When I replay actions from the beginning, the store.getState() returns the initial `users = {}` state even when the reducer has successfully returned `users = {id1: {isPending: true}}` and when I debug through it, I see the combineReducers successfully updates the state.\r\n\r\nWhen I step into store.getState(), I reach the following instrumented code\r\n```\r\n    function s(t) {\r\n        var e = t.computedStates\r\n          , n = t.currentStateIndex\r\n          , r = e[n].state;\r\n        return r\r\n    }\r\n```\r\nHere the values of e contain the newer values. But since currentStateIndex === 0, it keeps returning the old state.\r\n\r\nAm I missing some 'switch' or config somewhere? I feel like I'm missing some trivial setting option which I should be seeing in the docs."},"comment":{"url":"https://api.github.com/repos/zalmoxisus/redux-devtools-extension/issues/comments/271533188","html_url":"https://github.com/zalmoxisus/redux-devtools-extension/issues/281#issuecomment-271533188","issue_url":"https://api.github.com/repos/zalmoxisus/redux-devtools-extension/issues/281","id":271533188,"user":{"login":"narak","id":803063,"avatar_url":"https://avatars.githubusercontent.com/u/803063?v=3","gravatar_id":"","url":"https://api.github.com/users/narak","html_url":"https://github.com/narak","followers_url":"https://api.github.com/users/narak/followers","following_url":"https://api.github.com/users/narak/following{/other_user}","gists_url":"https://api.github.com/users/narak/gists{/gist_id}","starred_url":"https://api.github.com/users/narak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/narak/subscriptions","organizations_url":"https://api.github.com/users/narak/orgs","repos_url":"https://api.github.com/users/narak/repos","events_url":"https://api.github.com/users/narak/events{/privacy}","received_events_url":"https://api.github.com/users/narak/received_events","type":"User","site_admin":false},"created_at":"2017-01-10T09:56:38Z","updated_at":"2017-01-10T09:56:38Z","body":"Yeah, not saying its a bug. Just wondering if there is a way to configure devtools so that it doesn't trigger the same action endlessly because the overridden getState is constantly returning the old state."}}
{"actor":{"display_login":"narak"}}