{"action":"opened","issue":{"url":"https://api.github.com/repos/zeit/next.js/issues/112","repository_url":"https://api.github.com/repos/zeit/next.js","labels_url":"https://api.github.com/repos/zeit/next.js/issues/112/labels{/name}","comments_url":"https://api.github.com/repos/zeit/next.js/issues/112/comments","events_url":"https://api.github.com/repos/zeit/next.js/issues/112/events","html_url":"https://github.com/zeit/next.js/issues/112","id":185651249,"number":112,"title":"[Wiki] Reducer in Redux Example is not a pure function","user":{"login":"chabou","id":4137761,"avatar_url":"https://avatars.githubusercontent.com/u/4137761?v=3","gravatar_id":"","url":"https://api.github.com/users/chabou","html_url":"https://github.com/chabou","followers_url":"https://api.github.com/users/chabou/followers","following_url":"https://api.github.com/users/chabou/following{/other_user}","gists_url":"https://api.github.com/users/chabou/gists{/gist_id}","starred_url":"https://api.github.com/users/chabou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chabou/subscriptions","organizations_url":"https://api.github.com/users/chabou/orgs","repos_url":"https://api.github.com/users/chabou/repos","events_url":"https://api.github.com/users/chabou/events{/privacy}","received_events_url":"https://api.github.com/users/chabou/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-10-27T12:13:43Z","updated_at":"2016-10-27T12:13:43Z","closed_at":null,"body":"We can't use Date.now() in a reducer. Reducer should bu pure function. LastUpdate should be computed \r\n\r\n```javascript\r\nexport const reducer = (state = { lastUpdate: 0, light: false }, action) => {\r\n  switch (action.type) {\r\n    case 'TICK': return { lastUpdate: Date.now(), light: !!action.light }\r\n    default: return state\r\n  }\r\n}\r\n\r\nexport const startClock = () => dispatch => {\r\n  setInterval(() => dispatch({ type: 'TICK', light: true }), 800)\r\n}\r\n```\r\nshould be\r\n```javascript\r\nexport const reducer = (state = { lastUpdate: 0, light: false }, action) => {\r\n  switch (action.type) {\r\n    case 'TICK': return { lastUpdate: action.ts, light: !!action.light }\r\n    default: return state\r\n  }\r\n}\r\n\r\nexport const startClock = () => dispatch => {\r\n  setInterval(() => dispatch({ type: 'TICK', light: true, ts: Date.now() }), 800)\r\n}\r\n```\r\n\r\nOr we can remove lastUpdate field."}}
{"actor":{"display_login":"chabou"}}