{"_id":"@actualwave/redux-create-reducer","_rev":"5-a6372c808fe12ed4d9396fe991bb9f59","name":"@actualwave/redux-create-reducer","dist-tags":{"latest":"1.0.1"},"versions":{"0.0.5":{"name":"@actualwave/redux-create-reducer","description":"Function that combines reducers and calls them when action of same name received","version":"0.0.5","main":"createReducer.js","keywords":["js","javascript","redux","reducer","action","type","reducers","combine"],"homepage":"https://gist.github.com/burdiuz/b9701e29ac8ed96a85f773c1b663d61d","bugs":{"url":"https://gist.github.com/burdiuz/b9701e29ac8ed96a85f773c1b663d61d","email":"burdiuz@gmail.com"},"license":"MIT","author":{"name":"Oleg Galaburda","email":"burdiuz@gmail.com","url":"http://actualwave.com/"},"_id":"@actualwave/redux-create-reducer@0.0.5","_npmVersion":"5.6.0","_nodeVersion":"10.2.1","_npmUser":{"name":"actualwave","email":"burdiuz@gmail.com"},"dist":{"integrity":"sha512-aQzQQac+pCGWOZuWw0kpn6RSbg/iZgTWQlc3JVqcrEeXSUbfp82InBHz4WzJXrlS7EbHJKMGoSNQNz6vil3bwg==","shasum":"09789db01325df901fa5ac5653685757d2478cd0","tarball":"https://registry.npmjs.org/@actualwave/redux-create-reducer/-/redux-create-reducer-0.0.5.tgz","fileCount":3,"unpackedSize":2102,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbDyJQCRA9TVsSAnZWagAAD38QAIW3TFRgOJue+IpYlUrH\nD8CNYNWMHurqYheF5ne2PVcu/E84pXWzNW0SeaBEWQ2oXgRTuCMO1ctImXOT\nsoMI+Ux47YT/WKowJ+xZ3XJu1+znHzVfciaDg1/TYmhbMkCOMTx2REjxdj9v\nFesDruU/cfsrDehFOZWRO7e/geojiZ1HTl/gUt//5fDZvwHUpwNrz4BkHrym\ns30QXpL/gKG3IQs71M8o17u9tf2F4guWFNaT/hIjVzcMG6YNHAR0oSlcF9kj\nNVig0JaiL4n2xj58vJ2YsBUKX1871y1crXny+/BjvKsq3oYg4jmnhH9lV40G\nUjHongGIC433xnTHKywob5737W1YXo4vxXwhF52EHSqcnF/jYASrFwD4pav+\nD0U0vyyCHOUqj1HlAKhOeRIRefXf9MwkBsoxJWXBHt5aUgczNrmbwiL+fqKN\neMtNVL2j74avsfUDzi55fdCWNjtoICr3QHOyrbfP6guDA3oxRTKoLlBvjEit\n0xEQwoaHHVrwWWIgFxhWE67hdJ4ciJxjKWFnuLWALnJthiGMGhPJNakxqsIK\nkBie3D3vISOnY/SfQ8seyb9785ZVH++3bMi6pbwl94T7Cv11NJZsZ9tUg+96\n2sr9oo8gYNJKvS2XOkQt2izGipg+QOG4pgUtCoEwJ/oR8a9cn4jfCbj2DJji\n62Px\r\n=2Iw2\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICUUfc7ekfs+kDLj3+/AfxAlivMh9t1K6Yl+vnY6/QFPAiB6nxcZHD2ka7UTuhxa0znK/tp1EuSISH36VJqtAHhJVg=="}]},"maintainers":[{"name":"actualwave","email":"burdiuz@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/redux-create-reducer_0.0.5_1527718479831_0.6934635430392311"},"_hasShrinkwrap":false},"0.0.6":{"name":"@actualwave/redux-create-reducer","description":"Function that combines reducers and calls them when action of same name received","version":"0.0.6","main":"createReducer.js","keywords":["js","javascript","redux","reducer","action","type","reducers","combine"],"homepage":"https://gist.github.com/burdiuz/b9701e29ac8ed96a85f773c1b663d61d","bugs":{"url":"https://gist.github.com/burdiuz/b9701e29ac8ed96a85f773c1b663d61d","email":"burdiuz@gmail.com"},"license":"MIT","author":{"name":"Oleg Galaburda","email":"burdiuz@gmail.com","url":"http://actualwave.com/"},"_id":"@actualwave/redux-create-reducer@0.0.6","_npmVersion":"5.6.0","_nodeVersion":"10.2.1","_npmUser":{"name":"actualwave","email":"burdiuz@gmail.com"},"dist":{"integrity":"sha512-8wPmWb77u4Maf6ayv+gLN6BqNqHkb4cuCoMJpaGiHYW15evynJMTENN5aEO43bIdIBaXrXBDEYbQwriecGG0KA==","shasum":"89a84937bf428b7852f572e4c1e047675b57410e","tarball":"https://registry.npmjs.org/@actualwave/redux-create-reducer/-/redux-create-reducer-0.0.6.tgz","fileCount":3,"unpackedSize":2228,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbEIT2CRA9TVsSAnZWagAAVbkP/1PHaXjGp/DFI6ZsnIvT\nKMl9gBKYaJPo9NzMSlz6I38HjRqxzk2GooyODcueRfcbDycGSa8RaHPv0pHg\nAAItbia4mAmFcoTMtZrmw9hF0LZ0Rz48yWVSsRfkttOJUB/YrOmgiGmLrzjY\nNM96rBTkRf4oQpxI9JqPu2O7nvmQMKMoX5OSlTQTR17IYHvZWMp7pKCWhV91\nQb9muyquGBttSGODFVMSffPOf0v06WFGTU+CGLIgcN7QJazHtQeMzgjPOfyj\nEE7it+3z/oC+o2GLqGCP2zp+GCrv/F1rfNeQF1qy2hjLgMJfIDDdnN8wiqmF\nwnTFywnhm5KJ+N0cqwCKYL1qqiEj/hJgA9hvjSjTo7qrAGdxC1agDyj9GdRv\n14R8FoNjmcVA/M95AgDdsK4Y97glRNaTlWVF44195B48zA1yOhSxahulQ5Xg\niFxMFunklI4J9R03s9MDuFHvUTZElcHayGU32XEmd4Ct+FHCYUaFXdEnpNwC\nSs465ojds2KrmpWJoQ6tdc+jJEqlZ9uWyy5lhGdlWdaFSypi/WH7D1b0W53v\nuFLXdzjaqXn2rev6qFcYgvNxAFU6GLCG5A6haFYSyaL3+sDt80cgHnk83XXl\noKQHKeJkHcdiIIPPaanQQv/Hycqp7gFxVIXoNRGslrvkmFY4K4jFMArXZSf0\n5OmR\r\n=iRCy\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHACLEOmaGVWfAdfYUGaSuIJohSMdcV4J41pHbAYkpp9AiEA2OXrzc9haZlJdfp2XSKoLshLq3h7bb6YDMMzLAa8FEw="}]},"maintainers":[{"name":"actualwave","email":"burdiuz@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/redux-create-reducer_0.0.6_1527809269375_0.8110910617371916"},"_hasShrinkwrap":false},"0.0.7":{"name":"@actualwave/redux-create-reducer","description":"Function that combines reducers and calls them when action of same name received","version":"0.0.7","main":"createReducer.js","keywords":["js","javascript","redux","reducer","action","type","reducers","combine"],"homepage":"https://gist.github.com/burdiuz/b9701e29ac8ed96a85f773c1b663d61d","bugs":{"url":"https://gist.github.com/burdiuz/b9701e29ac8ed96a85f773c1b663d61d","email":"burdiuz@gmail.com"},"license":"MIT","author":{"name":"Oleg Galaburda","email":"burdiuz@gmail.com","url":"http://actualwave.com/"},"_id":"@actualwave/redux-create-reducer@0.0.7","_npmVersion":"5.6.0","_nodeVersion":"8.11.2","_npmUser":{"name":"actualwave","email":"burdiuz@gmail.com"},"dist":{"integrity":"sha512-Us+Ea/Nsf9VLGvh4TEQ19MOjENA9uNmW/z6waki/hoB0iSQ2uNwZAhwXV0r5pN+f3I9L8Vo6TWWJqnoGDabEdg==","shasum":"8366536d3c9eb8938cce86ce07aad33733017850","tarball":"https://registry.npmjs.org/@actualwave/redux-create-reducer/-/redux-create-reducer-0.0.7.tgz","fileCount":3,"unpackedSize":2452,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbEJEGCRA9TVsSAnZWagAAzpsQAKUGmiPuDefvR3ZTkKNy\n3QQfHhSwQ796Xj7GNpl0d0fXRGZq6y/G/0YH6yQqmDXveUdiIk3lspEnwpTl\ndN4CzaEY1f2bLcpzwpXbc/xGhlPiBAlLz7yfzi8nd36BQl2ubU+HsvEZ587Y\nARexF04FtMBrntzwONaXqMT0IE51hNSxtWXlVlYN8K/5Inf9t1fKuKbDQl7u\nuFTYdyW0dIifll6b0xdFBCWtXxF364snzden3o0zqt+M2fkumLcB5nIqQ6Ax\n5lLt9moaunhRJAeP5oKwZCPV55RtjIVC+ir1lhnxUIQ2BNquwyBBoo3hN7lz\nJbtd8qWsOAOzxzPllzkJgQmJz2cEr9MyC+5J+oEBaJM1W5xPXPKhWhDd9/RF\ntQ0eXqr2iu1Ygp1AzLgD+nswS3U8HkYp7SC1BwkEYPhLX/ufuZTcjJbgzKpe\nlJAByGK4IOOcHkBoaEobmzgC02o3taLBHu2ooytF9d7ZWEOBd5x6MqzLwGAK\n3Q12ualuueb33sMxCgUigPFOpf+IYzXdcoLqmPzPr8ZT48yLINE+3cljvcvK\n/hWYr7qeGWng9MpTMgF0NZbIrHnHFRCsKe7QlWML4K9ro4ys5HolxgLJ5pfv\nA7vX7PUnov2p6Gt6d8UShr7jexFh8UZTcr+ewIZ2HF14f8tYXZ0lrbbmg2NZ\ntugS\r\n=y16C\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGP6uOSzUVFRP8K2o1UX2/pJWQoOmGe4LjZZ8WsEgltqAiEAyGnuPRer2HStHRChecEo6CEs+RwP15urZ3W9T7PS+ls="}]},"maintainers":[{"name":"actualwave","email":"burdiuz@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/redux-create-reducer_0.0.7_1527812358459_0.5366119106689902"},"_hasShrinkwrap":false},"1.0.0":{"name":"@actualwave/redux-create-reducer","description":"Function that combines reducers and calls them when action of same name received","version":"1.0.0","main":"createReducer.js","dependencies":{},"gitHead":"c114b2ace296ff4a38866b96afa2d8da754474e3","_id":"@actualwave/redux-create-reducer@1.0.0","_npmVersion":"6.5.0-next.0","_nodeVersion":"11.6.0","_npmUser":{"name":"actualwave","email":"burdiuz@gmail.com"},"dist":{"integrity":"sha512-6dgn/DUtaxev5eThXZV/VOuWM9SGKN55VFYExFHd23U53cq3AmtIhFyRgfxa7d4tLFIqBOxhArtpP75uknoteA==","shasum":"1afa0a6b2e82420504629cac292d0ddc13ca51c9","tarball":"https://registry.npmjs.org/@actualwave/redux-create-reducer/-/redux-create-reducer-1.0.0.tgz","fileCount":3,"unpackedSize":6536,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcUMR1CRA9TVsSAnZWagAAGkkP/0wPOvKhZ1DdlHfHnzVs\nbsYHKePkZyCtKnzS8E1XdDjYOTFNlP3WekANQzt/kt9CQhotd3qirhxtzs+c\nINPgeX5+jfQvvGY6uRDWvHloTutuCKaKnixGsqxy+zycbyUeOwu7Th9SD/gl\nyJ1pnd2mGHAJ8vFGowvSXBcu9iYZycJf7INro5Z1kKSKXeaDqBvlhwfmHbmi\n0pcz6u0M47NkJt9YSJKoQKlWYQctRr47lwUsp4CIIahjbSeT3cyfb18nlOnP\nfhFQJ5VlUABGF0Y7PhCfMeoLohhkQ8dP0tSFU9Apq8kwhn8UoXwJIbODuDx1\n75GmSEiL7Kybg7f2TKeezLKsERk5WtS31/cPYPAYc1px0MGkBveRMNo7hCmY\nBwJWDt+dCYcLeNweL25xKTV0xfBYNSGKusmm7nnbkzzFdARsLaKHxSl9TpcP\nAlYYjXz8YrY+tyi23AuoIFObLZQARzlWux6GOON5MbO9TLv38RKsKvZvJPEw\nWiV+5B0r4xayUrYn3GuD83ysWJDsRxFjhpfBmyRBiY56el66IV6uD4KUUbXc\nbYbl6OHVTIsnHVlx0sM2Zt+eelK42ugOoAns3QEmkKCrLdeXINsUFc3PWAAw\nlBxsjDxFL7pL6+DspUzHgZURCaQQdE1o246hy3j0wyyK8RlqlAd6qnAHtlji\n8VVh\r\n=uidy\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFYmERPOd1Jx2R6bBkW1+An7ife/tPbscVBSwc0dcmHUAiBMpYZLLZVb0auySZuco5a36pFOYdKkZDlETvx5p9iRAA=="}]},"maintainers":[{"name":"actualwave","email":"burdiuz@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/redux-create-reducer_1.0.0_1548797044353_0.5254109874732906"},"_hasShrinkwrap":false},"1.0.1":{"name":"@actualwave/redux-create-reducer","description":"Function that combines reducers and calls them when action of same name received","version":"1.0.1","main":"createReducer.js","dependencies":{},"keywords":["redux","reducer","combine","createReducer","combineReducers","createReducers","exports","default","structure","function"],"gitHead":"8c40780a4de72c143b71a12405989fd37c6a92b5","_id":"@actualwave/redux-create-reducer@1.0.1","_npmVersion":"6.5.0-next.0","_nodeVersion":"11.6.0","_npmUser":{"name":"actualwave","email":"burdiuz@gmail.com"},"dist":{"integrity":"sha512-Mtf0h26lW3eG3HpnJG9PiToG8fCkxyOdCLBzx3F9dHsh0f/8FY/whoX7/zzy84LGVkYBw7upqYbelD/SfndFVQ==","shasum":"f6794d21cf3fdba1000e9895a481587ea9c02d16","tarball":"https://registry.npmjs.org/@actualwave/redux-create-reducer/-/redux-create-reducer-1.0.1.tgz","fileCount":3,"unpackedSize":8670,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcWKwpCRA9TVsSAnZWagAAVHsP/0Xjb9Q723OGHWsB9hiw\nSXcRtS2aF2BznzsXjYaJmr4P8td76dSFJzKFJTdUr/ghIjLzNpHicJ9OtxoI\nlMELUxeBL0TsmLJ/fvYThgc799SSWqNmBUJ/EXAgBIKAoKUiWUfl7WH2HKxY\nnf+GMQv6eWHogzpkf1qdr0+0Kj/FLdTUDNQjSEAFej4ERZnqlCcHelLs/as0\noNXQIrDP+Z9fapc2vDa8S4rwJArlVReePCkG4qWomvdRb7NDUhUc1wWYX+0Y\nxm37VouwXlTkkSA3CYfxsHZ1/LHk6CmZij/C+XU/DPO76J9F1ozG3JVDtkpH\no5GXVSezHpGQ0XBxGZxppHI+6joKZdAAsOW3y/ADjm/DxA55QQMtWCUVLd1y\n2Hlj8BOGa6Po8aCeojb88d7emUctMXTRuYuAqiTKNymUzYHhSfd3FcA5+xKx\ns8djpY06LPMDKLUgKAFsEdb9AdtazhM1owqj2yEZ81imw2xfu+cn1/+VSM4R\n4DJVjavAthRhzNrQTnUA2NkaUfzOO+fNJr6+AaJHwJ4OMeqldnZDtcPZk+zx\nb9NmGqFqEyUtj20KPdF0BsQIgL3VtMGWdzj2srXWNYTYJC7dYCf/No8sloPc\na9aU0kgODNslkMikGVTCfvWNtZO+OLfM5RjulzHHYtIzHuT20Gr0TeUk0Kl/\n/m0Z\r\n=kQAa\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDmNl6Ex5OtGp2ClQQN0pNntbZ569EeNtFq2sjQS7VD0gIhAOpA0cjMXZGFgYyJ5D8BtulKQRdtql2KFgRVqqtRQlja"}]},"maintainers":[{"name":"actualwave","email":"burdiuz@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/redux-create-reducer_1.0.1_1549315113338_0.2411232849867313"},"_hasShrinkwrap":false}},"time":{"created":"2018-05-30T22:14:39.586Z","0.0.5":"2018-05-30T22:14:39.925Z","modified":"2022-04-04T11:20:15.046Z","0.0.6":"2018-05-31T23:27:49.515Z","0.0.7":"2018-06-01T00:19:18.569Z","1.0.0":"2019-01-29T21:24:04.650Z","1.0.1":"2019-02-04T21:18:33.546Z"},"maintainers":[{"name":"actualwave","email":"burdiuz@gmail.com"}],"description":"Function that combines reducers and calls them when action of same name received","readme":"# @actualwave/redux-create-reducer\n\nThis package contains two functions made to create a redux reducer function\nfrom smaller per-action functions. So instead of\n\n```javascript\nimport {\n  FETCH_DATA_SUCCESS,\n  FETCH_DATA_FAILURE,\n  UPDATE_DATA_SUCCESS,\n  UPDATE_DATA_FAILURE,\n  DELETE_DATA_SUCCESS,\n  DELETE_DATA_FAILURE,\n} from './actions';\n\nconst initialState = {};\n\nconst reducer = (state = initialState, action) => {\n  switch(action.type) {\n    case FETCH_DATA_SUCCESS:\n      ...\n    break;\n    case FETCH_DATA_FAILURE:\n     ...\n    break;\n    case UPDATE_DATA_SUCCESS:\n      ...\n    break;\n    case UPDATE_DATA_FAILURE:\n     ...\n    break;\n    case DELETE_DATA_SUCCESS:\n      ...\n    break;\n    case DELETE_DATA_FAILURE:\n     ...\n    break;\n  }\n}\n\nexport default reducer;\n```\n\nYou may have this structure\n\n```javascript\nconst getInitialState = () => ({});\n\nexport const fetchDataSuccess = (state, action) => {\n  ...\n};\n\nexport const fetchDataFailure = (state, action) => {\n  ...\n};\n\nexport const updateDataSuccess = (state, action) => {\n  ...\n};\n\nexport const updateDataFailure = (state, action) => {\n  ...\n};\n\nexport const deleteDataSuccess = (state, action) => {\n  ...\n};\n\nexport const deleteDataFailure = (state, action) => {\n  ...\n};\n\nexport default getInitialState;\n```\n\n## Install\n\nUse NPM\n\n```\nnpm install @actualwave/redux-create-reducer\n```\n\nYarn\n\n```\nyarn add @actualwave/redux-create-reducer\n```\n\nOr download source from [original gist](https://gist.github.com/burdiuz/b9701e29ac8ed96a85f773c1b663d61d).\n\n## How to use\n\nFor example, we have three files for actions, reducer and redux configuration in setup file.\n\n1. Define action types in actions file\n\n```javascript\nexport const FETCH_SETTINGS_SUCCESS = 'fetchSettingsSuccess';\n```\n\nThe value of action type will be used to determine which function should be called.\n\n2. Use action type to create a reducer function for it in reducer file\n\n```javascript\nexport const fetchSettingsSuccess = (state, { payload }) => ({\n  ...state,\n  ...payload,\n  initialized: true,\n});\n```\n\n3. If default export from reducer file exists, it must be a factory function for default state.\n   If not defined, function that always returns empty object will be used.\n   So, let's add default state factory to reducer file\n\n```javascript\nexport default () => {\n  return {\n    firstSetting: true,\n    secondSetting: false,\n    initialized: false,\n  };\n};\n```\n\n4. Add reducer to redux storage in setup file\n\n```javascript\nimport { createStore, combineReducers } from 'redux';\nimport { createReducer } from '@actualwave/redux-create-reducer';\nimport * as settings from './reducer';\n\nconst store = createStore(\n  combineReducers({\n    settings: createReducer(settings),\n  }),\n);\n```\n\nIf you have multiple reducers\n\n```javascript\nimport { createStore, combineReducers } from 'redux';\nimport { createReducers } from '@actualwave/redux-create-reducer';\nimport * as items from './items/reducer';\nimport * as settings from './settings/reducer';\nimport * as users from './users/reducer';\n\nconst store = createStore(\n  combineReducers(\n    createReducers({\n      items,\n      settings,\n      users,\n    }),\n  ),\n);\n```\n\n### API\n\nThis module exposes two functions\n\n- `createReducer()` -- create reducer function from an object with set of action handlers. Each action handler is assigned to action type by property key and will be called only when action of this type passed.\n\n```javascript\n/*\n  Will create a reducer function which accept \"fetchDataSuccess\" and \"fetchDataFailure\" actions.\n*/\nconst reducer = createReducer({\n  \n  /*\n    this function will be called only when action with type \"fetchDataSuccess\" is dispatched:\n    { type: \"fetchDataSuccess\" }\n  */\n  fetchDataSuccess: (state, action) => ...,\n  \n  /*\n    this function will be called only when action with type \"fetchDataFailure\" is dispatched:\n    { type: \"fetchDataFailure\" }\n  */\n  fetchDataFailure: (state, action) => ...,\n});\n```\n\n```javascript\n/*\n  Will create a reducer function which accept \"fetchDataSuccess\" and \"fetchDataFailure\" actions\n  and have empty `items` array in default state object.\n*/\nconst reducer = createReducer({\n  \n  // handles \"fetchDataSuccess\" actions\n  fetchDataSuccess: (state, action) => ...,\n  \n  // handles \"fetchDataFailure\" actions\n  fetchDataFailure: (state, action) => ...,\n  \n  // default state factory\n  default: () => ({items: []}),\n});\n```\n\nNormally its used against exports from one file that describes single reducer\n\n```javascript\n/*\n  contents of ./data/reducer file\n  \n  Every exported entity must be an action handling function and\n  `export default` must be a default state factory.\n*/\n\n// handles \"fetchDataSuccess\" actions\nexport const fetchDataSuccess: (state, action) => ...;\n\n// handles \"fetchDataFailure\" actions\nexport const fetchDataFailure: (state, action) => ...;\n\n// default state factory\nexport default () => ({items: []});\n```\n\nImport everything from a reducer file and create a reducer function from it.\n```javascript\nimport * data from './data/reducer';\n\nconst reducer = createReducer(data);\n```\n\n- `createReducers()` -- applies `createReducer()` to object properties.\n```javascript\n// create reducers for \"data\", \"settings\" and \"items\" properties\nconst reducers = createReducers({\n  data,\n  settings,\n  items,\n});\n```\n\nIs equivalent to\n```javascript\nconst reducers = {\n  data: createReducer(data),\n  settings: createReducer(settings),\n  items: createReducer(items),\n});\n```\n\nAccepts object of objects and returns object with same keys but reducer functions as values.\n```javascript\nconst reducers = createReducers({\n  data: {\n    fetchDataSuccess: (state, action) => ...,\n    fetchDataFailure: (state, action) => ...,\n    default: () => ({ items: [] }),\n  },\n});\n```\nThis code will result in creating a reducer for \"fetchDataSuccess\" and \"fetchDataFailure\" actions which will be stored in \"data\" property:\n```javascript\n{\n  data: (state, action) => {\n    /* \"fetchDataSuccess\" and \"fetchDataFailure\" handled here */\n    ...\n  },\n};\n```\nThen this object can be passed directly to redux's `combineReducers()`.\n```javascript\nconst reducers = combineReducers(\n  createReducers({\n    data: {\n      fetchDataSuccess: (state, action) => ({ ...state, loaded: true }),\n      fetchDataFailure: (state, action) => ({ ...state, loaded: false }),\n      default: () => ({ items: [], loaded: false }),\n    },\n  })\n);\n```\n\n### Notes\n\nFrom my experience, `createReducer()` best works with camel-cased action types\n\n```javascript\n// good\nconst MY_FIRST_ACTION = 'myFirstAction';\n\n// bad\nconst MY_SECOND_ACTION = 'MY_SECOND_ACTION';\n```\n\nIn this case you will get these function names for action handlers in reducer file:\n\n```javascript\n// for \"myFirstAction\" action type\nexport const myFirstAction = (state, action) => {\n  ...\n};\n\n// for \"MY_SECOND_ACTION\" action type\nexport const MY_SECOND_ACTION = (state, action) => {\n  ...\n};\n```\n\nBut its all up to developer how to generate action types, they just need to be valid JS identifiers.  \n  \n  \n> If you like such way of structuring reducers, check [redux-actions](https://redux-actions.js.org/) library, it gives tools for complex and standartized approach for managing actions and reducers.","readmeFilename":"readme.md","keywords":["redux","reducer","combine","createReducer","combineReducers","createReducers","exports","default","structure","function"]}