{"action":"created","issue":{"url":"https://api.github.com/repos/coderhaoxin/redux-action/issues/11","repository_url":"https://api.github.com/repos/coderhaoxin/redux-action","labels_url":"https://api.github.com/repos/coderhaoxin/redux-action/issues/11/labels{/name}","comments_url":"https://api.github.com/repos/coderhaoxin/redux-action/issues/11/comments","events_url":"https://api.github.com/repos/coderhaoxin/redux-action/issues/11/events","html_url":"https://github.com/coderhaoxin/redux-action/pull/11","id":186502197,"number":11,"title":"The \"right\" way of structuring action, reducer (and action types)","user":{"login":"oroce","id":462848,"avatar_url":"https://avatars.githubusercontent.com/u/462848?v=3","gravatar_id":"","url":"https://api.github.com/users/oroce","html_url":"https://github.com/oroce","followers_url":"https://api.github.com/users/oroce/followers","following_url":"https://api.github.com/users/oroce/following{/other_user}","gists_url":"https://api.github.com/users/oroce/gists{/gist_id}","starred_url":"https://api.github.com/users/oroce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oroce/subscriptions","organizations_url":"https://api.github.com/users/oroce/orgs","repos_url":"https://api.github.com/users/oroce/repos","events_url":"https://api.github.com/users/oroce/events{/privacy}","received_events_url":"https://api.github.com/users/oroce/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-01T10:27:06Z","updated_at":"2016-11-01T10:28:42Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/coderhaoxin/redux-action/pulls/11","html_url":"https://github.com/coderhaoxin/redux-action/pull/11","diff_url":"https://github.com/coderhaoxin/redux-action/pull/11.diff","patch_url":"https://github.com/coderhaoxin/redux-action/pull/11.patch"},"body":"I'm curious what's your opinion on how we should structure actions, action types and reducers.\r\n\r\nScenario 1: Having separated `action-types.js`, `actions.js`, `reducer.js`\r\n\r\n```\r\n//action-types.js\r\nconst GET_ITEMS = 'get items';\r\n```\r\n\r\n```\r\n//actions.js\r\nimport {\r\n  GET_ITEMS\r\n} from './action-types';\r\nimport { createAction } from 'redux-action';\r\n\r\nexport const getItems = createAction(GET_ITEMS);\r\n```\r\n\r\n```\r\n//reducer.js\r\nimport {\r\n  GET_ITEMS\r\n} from './action-types';\r\nimport { createReducer } from 'redux-action';\r\nexport default createReducer({}, {\r\n  [GET_ITEMS]: (payload, state) => ({...state, ...payload})\r\n});\r\n```\r\n\r\nScenario 2: Changing `createAction` by exporting the `type` of action, so we dont need `action-types.js`, just `actions.js` and `reducer.js`\r\n\r\n```\r\n//actions.js\r\nimport { createAction } from 'redux-action';\r\nexport const getItems = createAction('get items');\r\n```\r\n\r\n```\r\n//reducer.js\r\nimport { createReducer } from 'redux-action';\r\nimport {\r\n  getItems\r\n} from './actions';\r\nexport default createReducer({}, {\r\n  [getItems.type]: (payload, state) => ({...state, ...payload})\r\n});\r\n```\r\n\r\nI added changes for Scenario 2 (since `redux-action` already supports the first one), but I'm just looking for your opinions on this very topic. We've been using the first option for quite a long time (a year or so), but that requires us to keep both three files up-to-date (and the tests as well), which is - to be honest - a real pain.\r\nYou can even mix the two options, by creating an `action-types.js` which is used by the `actions.js`, but the reducer uses the `actions.js` instead of the `action-types.js`, this can be handy if you want to use your constants in middlewares without requiring `actions.js`.\r\n\r\nWhat's your take on this?"},"comment":{"url":"https://api.github.com/repos/coderhaoxin/redux-action/issues/comments/257533901","html_url":"https://github.com/coderhaoxin/redux-action/pull/11#issuecomment-257533901","issue_url":"https://api.github.com/repos/coderhaoxin/redux-action/issues/11","id":257533901,"user":{"login":"oroce","id":462848,"avatar_url":"https://avatars.githubusercontent.com/u/462848?v=3","gravatar_id":"","url":"https://api.github.com/users/oroce","html_url":"https://github.com/oroce","followers_url":"https://api.github.com/users/oroce/followers","following_url":"https://api.github.com/users/oroce/following{/other_user}","gists_url":"https://api.github.com/users/oroce/gists{/gist_id}","starred_url":"https://api.github.com/users/oroce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oroce/subscriptions","organizations_url":"https://api.github.com/users/oroce/orgs","repos_url":"https://api.github.com/users/oroce/repos","events_url":"https://api.github.com/users/oroce/events{/privacy}","received_events_url":"https://api.github.com/users/oroce/received_events","type":"User","site_admin":false},"created_at":"2016-11-01T10:28:42Z","updated_at":"2016-11-01T10:28:42Z","body":"Oh one more came to my mind, you can override `toString` method of a `Function` instance, so what you can do is:\r\n\r\n```\r\nconst fn = () => 'foo';\r\nfn.toString = () => 'bar';\r\n\r\nequal({\r\n  [fn]: true\r\n}, {\r\n  'bar': true\r\n}); // true\r\n```"}}
{"actor":{"display_login":"oroce"}}