{"_id":"@anubhavsahoo/reduxsauce","_rev":"2-4586d605276333b9a62f05995f83e0f4","name":"@anubhavsahoo/reduxsauce","dist-tags":{"latest":"1.1.2-f1"},"versions":{"1.1.2":{"name":"@anubhavsahoo/reduxsauce","version":"1.1.2","description":"Some aesthetic toppings for your Redux meal.","repository":{"type":"git","url":"git+https://github.com/jkeam/reduxsauce.git"},"main":"./dist/reduxsauce.js","scripts":{"test":"ava","watch":"ava --watch","coverage":"nyc ava","coveralls":"nyc --reporter=text-lcov ava | coveralls","build":"rollup -c","lint":"standard","prepublishOnly":"npm run build","ci:publish":"yarn semantic-release","semantic-release":"semantic-release"},"keywords":["redux"],"author":{"name":"Steve Kellock","email":"steve@kellock.ca"},"license":"MIT","dependencies":{"ramda":"^0.26.1"},"devDependencies":{"@semantic-release/git":"^7.0.18","ava":"^2.4.0","babel-cli":"^6.24.0","babel-eslint":"^7.2.1","babel-plugin-external-helpers":"^6.18.0","babel-plugin-transform-object-rest-spread":"^6.23.0","babel-preset-es2015":"^6.24.0","babel-preset-es2015-rollup":"^3.0.0","babel-preset-stage-0":"^6.22.0","coveralls":"^3.0.9","nyc":"^14.1.1","rollup":"^0.47.6","rollup-plugin-babel":"^3.0.1","rollup-plugin-filesize":"^1.5.0","rollup-plugin-ramda":"^1.0.5","semantic-release":"^15.14.0","standard":"^14.3.1"},"peerDependencies":{"redux":"4.x"},"ava":{"require":["babel-core/register"],"babel":{"testOptions":{"babelrc":false}}},"standard":{"parser":"babel-eslint"},"release":{"plugins":["@semantic-release/commit-analyzer","@semantic-release/release-notes-generator","@semantic-release/npm","@semantic-release/github",["@semantic-release/git",{"assets":"package.json","message":"chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"}]]},"gitHead":"8e715a88c28f5e7e4a84db3a86c5096981b7a048","bugs":{"url":"https://github.com/jkeam/reduxsauce/issues"},"homepage":"https://github.com/jkeam/reduxsauce#readme","_id":"@anubhavsahoo/reduxsauce@1.1.2","_nodeVersion":"10.16.3","_npmVersion":"6.9.0","dist":{"integrity":"sha512-XytpojNadukCWsz8UBtJSgqXsP/CquZ70v2xX8IpnRd+Mg/4HELuPe87kvTnZmw30lEV3YFrRYhaWrpLDu+YUw==","shasum":"fb803b9a41a5ada0bde7a5cf47136efea92ee7d5","tarball":"https://registry.npmjs.org/@anubhavsahoo/reduxsauce/-/reduxsauce-1.1.2.tgz","fileCount":11,"unpackedSize":27331,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJey5xZCRA9TVsSAnZWagAAtvMP/1P3PqP5mtYp4XXi0yq2\noony9PtTptl7N4rDCfciN+7FydU6M70RcjzfKrnhS23kuoBjZTTktVVwzHy6\nLmX+Y8ZZGcjfuVak8e6S3Ekoz0RDszQEC7vCa6H+7i7t8kq9yLcnHYTShkSn\n+hYd+9zWaFnpNY8M1YZv9i4w9os+bXhmcKm2V4dEAM999ELXvIb405zxMWh4\nFFBjAJHf+5p3Omxn+U2L47iKiojaXFAmEp6lnD4kErlD7x8GWBRpiyGufK7g\n8uON72i3kzCTyTwkth349IrxtdZd2YDURMujW48iaHKBWk6zPGYwBqJGfsuF\nKUmGjD7hOPC+8Ar7qHk6gmaW2tiqzGvP+RZo5sZea5G1Qctm9i/fnl3vZyvp\n8+4+ufO8tYuVKqhqDrAqx2MzEOuA5mVJcW0BVp3ZYLNPe0KR0xSSEt5Cj10e\nd2aooXnRdPayj+n4TkHls547+XhsIC38LFvQC6SMH0a9Po1sQK9A3qOlMi2+\n4OevB6u0fyvvL3znIaGq4iyla45D+2GZB+PIbs3sxVZ9eEWTKGrla7C4ux+8\nb+SqmnFsbpG0Prrw2X8iF3oCrFG8L8T5WAoMJuYHcgYYp8vV7VfaDpUmWs+c\nQ8keKqmK6l9cZv3JHUjvZIsBwvvyUm5iBbVZBueNE8r0Dhaf93YGvVIMNKhj\nHg11\r\n=vyFE\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHONVIiUCBZJx7NCxxY3uFoRn0T6ZbppeTl0csQvz8xdAiBgGC87Y0TIQ5GLAGlAV354K1vGDK1ZMOii1IuPkqC4oQ=="}]},"maintainers":[{"name":"anubhavsahoo","email":"anubhav.sahoo@gmail.com"}],"_npmUser":{"name":"anubhavsahoo","email":"anubhav.sahoo@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/reduxsauce_1.1.2_1590402137403_0.47781624492473385"},"_hasShrinkwrap":false},"1.1.2-f1":{"name":"@anubhavsahoo/reduxsauce","version":"1.1.2-f1","description":"Some aesthetic toppings for your Redux meal.","repository":{"type":"git","url":"git+https://github.com/jkeam/reduxsauce.git"},"main":"./dist/reduxsauce.js","scripts":{"test":"ava","watch":"ava --watch","coverage":"nyc ava","coveralls":"nyc --reporter=text-lcov ava | coveralls","build":"rollup -c","lint":"standard","prepublishOnly":"npm run build","ci:publish":"yarn semantic-release","semantic-release":"semantic-release"},"keywords":["redux"],"author":{"name":"Steve Kellock","email":"steve@kellock.ca"},"license":"MIT","dependencies":{"ramda":"^0.26.1"},"devDependencies":{"@semantic-release/git":"^7.0.18","ava":"^2.4.0","babel-cli":"^6.24.0","babel-eslint":"^7.2.1","babel-plugin-external-helpers":"^6.18.0","babel-plugin-transform-object-rest-spread":"^6.23.0","babel-preset-es2015":"^6.24.0","babel-preset-es2015-rollup":"^3.0.0","babel-preset-stage-0":"^6.22.0","coveralls":"^3.0.9","nyc":"^14.1.1","rollup":"^0.47.6","rollup-plugin-babel":"^3.0.1","rollup-plugin-filesize":"^1.5.0","rollup-plugin-ramda":"^1.0.5","semantic-release":"^15.14.0","standard":"^14.3.1"},"peerDependencies":{"redux":"4.x"},"ava":{"require":["babel-core/register"],"babel":{"testOptions":{"babelrc":false}}},"standard":{"parser":"babel-eslint"},"release":{"plugins":["@semantic-release/commit-analyzer","@semantic-release/release-notes-generator","@semantic-release/npm","@semantic-release/github",["@semantic-release/git",{"assets":"package.json","message":"chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"}]]},"gitHead":"c2ae1b076390bacc5a9b25879dcbc7027dbbb25f","bugs":{"url":"https://github.com/jkeam/reduxsauce/issues"},"homepage":"https://github.com/jkeam/reduxsauce#readme","_id":"@anubhavsahoo/reduxsauce@1.1.2-f1","_nodeVersion":"10.16.3","_npmVersion":"6.9.0","dist":{"integrity":"sha512-C5ria0AjWkQR1j8Zkjw0XYAkzHxzMzw/uA6BsHRic+4u88boCMoOsOo5vQVB4fyAdrjZudcW86r7vTGXXRZPqw==","shasum":"30b58de19b616f7762e1d78da110b9dc41a873d8","tarball":"https://registry.npmjs.org/@anubhavsahoo/reduxsauce/-/reduxsauce-1.1.2-f1.tgz","fileCount":11,"unpackedSize":27424,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJey56OCRA9TVsSAnZWagAADx8P/jw5wUYNl2P5AfKM500f\n50DAT5x+MwLDrWWulAJQEkdNXh/LI94jwQXo9N9mnm59Kqc+CylL3bwkByhC\ndKbmy4Yw5wMw9Ie1U6ezP5iwjg67TZ03HfjsVa3qU/v5+zOA6+mEkTfh4VQD\nex2JJ1ccrX1b95bKIOm+KC4XeXCFLZOiuKUygLJll3DvrIFCF5SLqewrHf5Z\nWUHxLGJ7n4HjDsTUeK7LGwpknnHOLoz0MNZwiKfbBp03IIrjD6An6EKnxuDI\n+ovZkVlTlTSBoLgtriWY7RW9u6CQ/3Y6Z1bUdLezwOJDr4DX9J5ZLwOxleOV\nvyOXSlu7gX/hS7VCTvYp68SLFnOmX7cxJhuJemHKlzAwa9clDDV0C9LoYATG\nI91by83v7ElJsNFbQohWwxG9V71YiwMJVahKYuur4V0Wa5bmYUa2di0lh7xg\nVJh4a4TJcEzSjoMIa93JqWcxXkyCq+PUZQ8qt5KF/hV3nILC4Tj79AIK3EBM\n4sV6MMdzkUbsF0n68PnJxMBOJwy+BfC9v0O2DJZ3p90dSJFQ/7m4sNPyi1nt\nYYnsPu6/bfV1l6dYV/f3o1zbpdVxFthwGQMl1Sbj1Ux1LrhNztztk4S9R93T\nwyLVYCAch78VbYzZTA8PhLuC5ElFSm5YYFrXFkGEHujRu29XZd3lbEqQkgbL\nhk1Y\r\n=Sb13\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCXmb6Qlu1Qz6gAqp6O4Zd6FnDdQEmxK3GzQMstiaOh8gIgaPvRNQuCCAI43Wc2Li1VCzbJRbFQHNBcZee0b6m6mnE="}]},"maintainers":[{"name":"anubhavsahoo","email":"anubhav.sahoo@gmail.com"}],"_npmUser":{"name":"anubhavsahoo","email":"anubhav.sahoo@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/reduxsauce_1.1.2-f1_1590402702262_0.8541569523122272"},"_hasShrinkwrap":false}},"time":{"created":"2020-05-25T10:22:17.366Z","1.1.2":"2020-05-25T10:22:17.662Z","modified":"2022-04-04T14:25:43.556Z","1.1.2-f1":"2020-05-25T10:31:42.392Z"},"maintainers":[{"name":"anubhavsahoo","email":"anubhav.sahoo@gmail.com"}],"description":"Some aesthetic toppings for your Redux meal.","homepage":"https://github.com/jkeam/reduxsauce#readme","keywords":["redux"],"repository":{"type":"git","url":"git+https://github.com/jkeam/reduxsauce.git"},"author":{"name":"Steve Kellock","email":"steve@kellock.ca"},"bugs":{"url":"https://github.com/jkeam/reduxsauce/issues"},"license":"MIT","readme":"<img src='./_art/redux_sauce.png' align='left' />\n\n[![npm module](https://badge.fury.io/js/reduxsauce.svg)](https://www.npmjs.org/package/reduxsauce)\n[![Build Status](https://travis-ci.org/jkeam/reduxsauce.svg?branch=master)](https://travis-ci.org/jkeam/reduxsauce)\n[![Coverage Status](https://coveralls.io/repos/github/jkeam/reduxsauce/badge.svg?branch=master)](https://coveralls.io/github/jkeam/reduxsauce?branch=master)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n\n# What's The Story?\n\nProvides a few tools for working with Redux-based codebases.\n\n**Currently includes:**\n\n1. `createReducer` - declutter reducers for readability and testing\n1. `createTypes` - DRY define your types object from a string\n1. `createActions` - builds your Action Types and Action Creators at the same time\n1. `resettableReducer` - allows your reducers to be reset\n\n# createReducer\n\nWe're all familiar with the large switch statement and noise in our reducers, and because we all know this clutter, we can use `createReducer` to assume and clear it up!  There are a few patterns I've learned (and was taught), but let's break down the parts of a reducer first:\n\n1. Determining the initial state.\n1. Running\n1. Knowing when to run.\n1. Injecting into the global state tree\n\n#### Initial State\n\nEvery reducer I've written has a known and expected state.  And it's always an object.\n\n```js\nconst INITIAL_STATE = { name: null, age: null }\n```\n\nIf you're using seamless-immutable, this just get's wrapped. This is optional.\n\n```js\nconst INITIAL_STATE = Immutable({ name: null, age: null })\n```\n\n#### Running\n\nA reducer is a function.  It has 2 inbound parameters and returns the new state.\n\n```js\nexport const sayHello = (state = INITIAL_STATE, action) => {\n  const { age, name } = action\n  return { ...state, age, name }\n}\n```\n\nNotice the `export`?  That's only needed if you would like to write some tests for your reducer.\n\n#### Knowing When To Run\n\nIn Redux, all reducers fire in response to *any* action. It's up to the reducer to determine if it should run in response.  This is usually driven by a `switch` on `action.type`.\n\nThis works great until you start adding a bunch of code, so, I like to break out \"routing\" from \"running\" by registering reducers.\n\nWe can use a simple object registry to map action types to our reducer functions.\n\n```js\nimport Types from './actionTypes'\n\nexport const HANDLERS = {\n  [Types.SAY_HELLO]: sayHello,\n  [Types.SAY_GOODBYE]: sayGoodbye\n}\n```\n\nThe `export` is only needed for testing.  It's optional.\n\n#### Default handler\n\nSometimes you want to add a default handler to your reducers (such as delegating actions to sub reducers). To achieve that you can use `DEFAULT` action type in your configuration.\n\n```js\nimport Types from './actionTypes'\nimport { Types as ReduxSauceTypes } from 'reduxsauce'\n\nexport const HANDLERS = {\n  [Types.SAY_GOODBYE]: sayGoodbye,\n  [ReduxSauceTypes.DEFAULT]: defaultHandler,\n}\n```\n\nWith code above `defaultHandler` will be invoked in case the action didn't match any type in the configuration.\n\n#### Injecting Into The Global State Tree\n\nI like to keep this in the root reducer.  Since reducers can't access other reducers (lies -- it can, but it's complicated), my preference is to not have the reducer file have an opinion.\n\nI like to move that decision upstream.  Up to the root reducer where you use Redux's `combineReducers()`.\n\nSo, that brings us back to reduxsauce.  Here's how we handle exporting the reducer from our file:\n\n```js\nexport default createReducer(INITIAL_STATE, HANDLERS)\n```\n\nThat's it.\n\n\n#### Complete Example\n\nHere's a quick full example in action.\n\n```js\n// sampleReducer.js\nimport { createReducer } from 'reduxsauce'\nimport Types from './actionTypes'\n\n// the initial state of this reducer\nexport const INITIAL_STATE = { error: false, goodies: null }\n\n// the eagle has landed\nexport const success = (state = INITIAL_STATE, action) => {\n  return { ...state, error: false, goodies: action.goodies }\n}\n\n// uh oh\nexport const failure = (state = INITIAL_STATE, action) => {\n  return { ...state, error: true, goodies: null }\n}\n\n// map our action types to our reducer functions\nexport const HANDLERS = {\n  [Types.GOODS_SUCCESS]: success,\n  [Types.GOODS_FAILURE]: failure\n}\n\nexport default createReducer(INITIAL_STATE, HANDLERS)\n```\n\nThis becomes much more readable, testable, and manageable when your reducers start to grow in complexity or volume.\n\n#  createTypes\n\nUse `createTypes()` to create the object representing your action types.  It's whitespace friendly.\n\n```js\n// Types.js\nimport { createTypes } from 'reduxsauce'\n\nexport default createTypes(`\n  LOGIN_REQUEST\n  LOGIN_SUCCESS\n  LOGIN_FAILURE\n\n  CHANGE_PASSWORD_REQUEST\n  CHANGE_PASSWORD_SUCCESS\n  CHANGE_PASSWORD_FAILURE\n\n  LOGOUT\n`, {}) // options - the 2nd parameter is optional\n\n```\n\n### Options\n\n * `prefix`: prepend the string to all created types. This is handy if you're looking to namespace your actions.\n\n# createActions\n\nUse `createActions()` to build yourself an object which contains `Types` and `Creators`.\n\n```js\nimport { createActions } from 'reduxsauce'\n\nconst { Types, Creators } = createActions({\n  loginRequest: ['username', 'password'],\n  loginSuccess: ['username'],\n  loginFailure: ['error'],\n  requestWithDefaultValues: { username: 'guest', password: null },\n  logout: null,\n  custom: (a, b) => ({ type: 'CUSTOM', total: a + b })\n}, {}) // options - the 2nd parameter is optional\n```\n\nThe keys of the object will become keys of the `Creators`.  They will also become the keys of the `Types` after being converted to SCREAMING_SNAKE_CASE.\n\nThe values will control the flavour of the action creator.  When null is passed, an action creator will be made that only has the type.  For example:\n\n```js\nCreators.logout() // { type: 'LOGOUT' }\n```\n\nBy passing an array of items, these become the parameters of the creator and are attached to the action.\n\n```js\nCreators.loginRequest('steve', 'secret') // { type: 'LOGIN_REQUEST', username: 'steve', password: 'secret' }\n```\n\nBy passing an object of `{ key: defaultValue }`, default values are applied.\n\nIn this case, invoke the action by putting all parameters into an object as the first argument.\n\n```js\nCreators.requestWithDefaultValues({\n  password: '123456',\n  undefinedKeyWontBeUsed: true\n})\n// { type: 'REQUEST_WITH_DEFAULT_VALUES', username: 'guest', password: '123456' }\n```\n\n### Options\n\n * `prefix`: prepend the string to all created types. This is handy if you're looking to namespace your actions.\n\n# resettableReducer\n\nProvides a \"higher-order reducer\" to help reset your state.  Instead of adding an additional reset command to your individual reducers, you can wrap them with this.\n\nCheck it out.\n\n```js\nimport { resettableReducer } from 'reduxsauce'\nimport { combineReducers } from 'redux'\n\n// some reducers you have already created\nimport firstReducer from './firstReducer'\nimport secondReducer from './secondReducer'\nimport thirdReducer from './thirdReducer'\n\n// listen for the action type of 'RESET', you can change this.\nconst resettable = resettableReducer('RESET')\n\n// reducers 1 & 3 will be resettable, but 2 won't.\nexport default combineReducers({\n  first: resettable(firstReducer),\n  second: secondReducer,\n  third: resettable(thirdReducer)\n})\n```\n\n# Changes\n\n### Oct 23, 2019 - 1.1.1\n\n* `FIX` Upgrade dependencies\n* `FIX` Add more tests\n* `DOCS` Add badges\n\n\n### May 10, 2018 - 1.0.0 - 💃\n\n* `NEW` drops redux dependency sinc we weren't using it @pewniak747\n\n\n### September 26, 2017 - 0.7.0\n\n* `NEW` Adds ability to have a default or fallback reducer for nesting reducers or catch-alls. @vaukalak\n* `NEW` Adds default values to `createActions` if passed an object instead of an array or function. @zhang-z\n* `DOCS` Fixes typos. @quajo\n\n### July 10, 2017 - 0.6.0\n\n* `NEW` Makes unbundled code available for all you tree-shakers out there. @skellock & @messense\n* `FIX` Corrects issue with prefixed action names. @skellock\n* `FIX` Upgrades dependencies. @messense\n\n### April 7, 2017 - 0.5.0\n\n* `NEW` adds `resettableReducer` for easier reducer uh... resetting. @skellock\n\n### December 12, 2016 - 0.4.1\n\n* `FIX` creators now get the `prefix` as well. @jbblanchet\n\n### December 8, 2016 - 0.4.0\n\n* `NEW` createActions and createTypes now take optional `options` object with `prefix` key. @jbblanchet & @skellock\n\n### September 8, 2016 - 0.2.0\n\n* `NEW` adds createActions for building your types & action creators. @gantman & @skellock\n\n### May 17, 2016 - 0.1.0\n\n* `NEW` adds createTypes for clean type object creation. @skellock\n\n### May 17, 2016 - 0.0.3\n\n* `DEL` removes the useless createAction function. @skellock\n\n### May 17, 2016 - 0.0.2\n\n* `FIX` removes the babel node from package.json as it was breaking stuff upstream. @skellock\n\n### May 17, 2016 - 0.0.1\n\n* `NEW` initial release. @skellock\n","readmeFilename":"README.md"}