{"_id":"redux-toolkit","_rev":"11-4cc485b0c37e4daf83a4af08a7d22335","name":"redux-toolkit","description":"supply useful utils for redux","dist-tags":{"latest":"1.1.2"},"versions":{"1.0.2":{"name":"redux-toolkit","version":"1.0.2","description":"supply useful tool functions for redux","main":"index.js","scripts":{"build":"rm -rf lib && babel src --out-dir lib","test":"mocha"},"repository":{"type":"git","url":"git+https://github.com/yeatszhang/redux-toolkit.git"},"keywords":["redux","utils","helper"],"author":{"name":"yeatszhang"},"license":"ISC","bugs":{"url":"https://github.com/yeatszhang/redux-toolkit/issues"},"homepage":"https://github.com/yeatszhang/redux-toolkit#readme","dependencies":{"lodash":"^3.10.1"},"gitHead":"51f5bf55475401c98e1a17d6d665eed4db941c7d","_id":"redux-toolkit@1.0.2","_shasum":"517bcdc84901270036c88061fb74bbdaa8a0898c","_from":".","_npmVersion":"2.10.1","_nodeVersion":"0.12.4","_npmUser":{"name":"yeatszhang","email":"yichi.coder@foxmail.com"},"dist":{"shasum":"517bcdc84901270036c88061fb74bbdaa8a0898c","tarball":"https://registry.npmjs.org/redux-toolkit/-/redux-toolkit-1.0.2.tgz","integrity":"sha512-fEL7hAHfiFsXtgp8pMxu0VAkYrwRzckq+P9r2qk6Je3s4t1mztCOX4MzlxQMhApKlqr6QuKDOc+j3leaYT4qVQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCHNyN6wAgutt1bljMSsBdMOwWA9gO/1lfDYcOLgqPUewIhAMkrKjIig7fU9Mr7wjiFmd1RZOpM3bOMk29hPRlXeTzj"}]},"maintainers":[{"name":"yeatszhang","email":"yichi.coder@foxmail.com"}],"directories":{}},"1.0.3":{"name":"redux-toolkit","version":"1.0.3","description":"supply useful tool functions for redux","main":"index.js","scripts":{"build":"rm -rf lib && babel src --out-dir lib","test":"mocha"},"repository":{"type":"git","url":"git+https://github.com/yeatszhang/redux-toolkit.git"},"keywords":["redux","utils","helper"],"author":{"name":"yeatszhang"},"license":"ISC","bugs":{"url":"https://github.com/yeatszhang/redux-toolkit/issues"},"homepage":"https://github.com/yeatszhang/redux-toolkit#readme","dependencies":{"lodash":"^3.10.1"},"gitHead":"b073e5bb927973f40a9b8da9c379ec632f7c27f9","_id":"redux-toolkit@1.0.3","_shasum":"58ce619d4c15aab6483d23386b5e72f04270be37","_from":".","_npmVersion":"2.10.1","_nodeVersion":"0.12.4","_npmUser":{"name":"yeatszhang","email":"yichi.coder@foxmail.com"},"dist":{"shasum":"58ce619d4c15aab6483d23386b5e72f04270be37","tarball":"https://registry.npmjs.org/redux-toolkit/-/redux-toolkit-1.0.3.tgz","integrity":"sha512-yRJr2ILDoj3WI1hdSDGamNz6A66d1XSRL76onhIlaNfDwLRJka3yUh7oVJGPWiEjvwbzSavkrkDXVN5ERgHVHw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAaUNvyOY/O/PqlOVAMxd5yx0MNE41Q/txoaQ6GUyKzGAiBAHx3LBffaQglYki4dwUhdZOs5VPfbsHiaEqrgXAirSw=="}]},"maintainers":[{"name":"yeatszhang","email":"yichi.coder@foxmail.com"}],"directories":{}},"1.0.4":{"name":"redux-toolkit","version":"1.0.4","description":"supply useful tool functions for redux","main":"lib/index.js","scripts":{"build":"rm -rf lib && babel src --out-dir lib","test":"mocha"},"repository":{"type":"git","url":"git+https://github.com/yeatszhang/redux-toolkit.git"},"keywords":["redux","utils","helper"],"author":{"name":"yeatszhang"},"license":"ISC","bugs":{"url":"https://github.com/yeatszhang/redux-toolkit/issues"},"homepage":"https://github.com/yeatszhang/redux-toolkit#readme","dependencies":{"lodash":"^3.10.1"},"gitHead":"e9b276994c7dbada7c0b7b44b4cc3ff84d8a1dd0","_id":"redux-toolkit@1.0.4","_shasum":"9558c2114b809c87df6d18b5b811b5f4a8074108","_from":".","_npmVersion":"2.10.1","_nodeVersion":"0.12.4","_npmUser":{"name":"yeatszhang","email":"yichi.coder@foxmail.com"},"dist":{"shasum":"9558c2114b809c87df6d18b5b811b5f4a8074108","tarball":"https://registry.npmjs.org/redux-toolkit/-/redux-toolkit-1.0.4.tgz","integrity":"sha512-GBfxU+eQ61wJdKjYtEZk8gw4nPC7OU/sfOMZrOqNa/af5/khQvURg1dDdqDp3Oz2sj9XAbStzWxSK/lTHHJAvA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCVhj/iN3f8QecfU65GqmTZz+jmpf1ev9zYBqRhZ+geYQIgGxEcrIB8L1/AOIU/RFplZaSBp65mAkmCNiF0A3BD2kA="}]},"maintainers":[{"name":"yeatszhang","email":"yichi.coder@foxmail.com"}],"directories":{}},"1.1.0":{"name":"redux-toolkit","version":"1.1.0","description":"supply useful utils for redux","main":"lib/index.js","scripts":{"build":"rm -rf lib && babel src --out-dir lib","test":"mocha"},"keywords":["redux","utils","helper"],"author":{"name":"yeatszhang"},"dependencies":{"debug":"^2.2.0","flux-standard-action":"^0.6.0","invariant":"^2.1.1","lodash":"^3.10.1"},"gitHead":"5e415fff76f1019e73b2a44fcd91d3ca6aa59b95","_id":"redux-toolkit@1.1.0","_shasum":"698ee090128a63888ddf54b69b23c2e7d1443300","_from":".","_npmVersion":"2.14.7","_nodeVersion":"4.2.1","_npmUser":{"name":"yeatszhang","email":"yichi.coder@foxmail.com"},"dist":{"shasum":"698ee090128a63888ddf54b69b23c2e7d1443300","tarball":"https://registry.npmjs.org/redux-toolkit/-/redux-toolkit-1.1.0.tgz","integrity":"sha512-Z+YOZ+vggQGpH2k+QsHoBFpbphi7Pypt2TUwxV7znQ0I6e/yDOZSG7x4a8/JJmdTnRotXsvY7vZ1GYLIBZIrLg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCJf+FOK9yAVJjI+ocO3b+4aJyuhWy7r1R/5XP8xjQLhgIgbk9oDe5WaAfjVRrTHEXYViwE3Ce7vCRO3wf49bPC/OU="}]},"maintainers":[{"name":"yeatszhang","email":"yichi.coder@foxmail.com"}],"directories":{}},"1.1.1":{"name":"redux-toolkit","version":"1.1.1","description":"supply useful utils for redux","main":"lib/index.js","scripts":{"build":"rm -rf lib && babel src --out-dir lib","test":"mocha"},"repository":{"type":"git","url":"git+https://github.com/yeatszhang/redux-toolkit.git"},"keywords":["redux","utils","helper"],"author":{"name":"yeatszhang"},"dependencies":{"debug":"^2.2.0","flux-standard-action":"^0.6.0","invariant":"^2.1.1","lodash":"^3.10.1"},"gitHead":"8eaacf480f6ed9f1a5ee313724eff8d03f2a7080","bugs":{"url":"https://github.com/yeatszhang/redux-toolkit/issues"},"homepage":"https://github.com/yeatszhang/redux-toolkit#readme","_id":"redux-toolkit@1.1.1","_shasum":"0663bf65dfc0559d6e4cb13fb52005193a1c352a","_from":".","_npmVersion":"2.14.7","_nodeVersion":"4.2.1","_npmUser":{"name":"yeatszhang","email":"yichi.coder@foxmail.com"},"dist":{"shasum":"0663bf65dfc0559d6e4cb13fb52005193a1c352a","tarball":"https://registry.npmjs.org/redux-toolkit/-/redux-toolkit-1.1.1.tgz","integrity":"sha512-Titz7iZ4/hq0rPk1pVnYn8fQE/oFK+pYkhtgmJKOOchjr8X2FNcSy3TItjTUrTivNzm+rx70JShAGyP0kdT6pw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC7eRqnQdzOGyf7Sr5grdqbPG/W1UhVI5WxQ6dITG5XwQIhALn8BbRIZOlHuLU9EB9CcX1MCHs+EjakWZ3eWZwslwkV"}]},"maintainers":[{"name":"yeatszhang","email":"yichi.coder@foxmail.com"}],"directories":{}},"1.1.2":{"name":"redux-toolkit","version":"1.1.2","description":"supply useful utils for redux","main":"lib/index.js","scripts":{"build":"rm -rf lib && babel src --out-dir lib","test":"mocha"},"repository":{"type":"git","url":"git+https://github.com/yeatszhang/redux-toolkit.git"},"keywords":["redux","utils","helper"],"author":{"name":"yeatszhang"},"dependencies":{"debug":"^2.2.0","flux-standard-action":"^0.6.0","invariant":"^2.1.1","lodash":"^3.10.1"},"gitHead":"0a472a51d00cc47bcc271ccd07e6bf898d160e55","bugs":{"url":"https://github.com/yeatszhang/redux-toolkit/issues"},"homepage":"https://github.com/yeatszhang/redux-toolkit#readme","_id":"redux-toolkit@1.1.2","_shasum":"f7dc880fea13b4804284b4fe0072ef0e7a5552ff","_from":".","_npmVersion":"2.14.7","_nodeVersion":"4.2.1","_npmUser":{"name":"yeatszhang","email":"yichi.coder@foxmail.com"},"dist":{"shasum":"f7dc880fea13b4804284b4fe0072ef0e7a5552ff","tarball":"https://registry.npmjs.org/redux-toolkit/-/redux-toolkit-1.1.2.tgz","integrity":"sha512-ZDs6LqSvGLy5kcFfl3yHB/xzpPlXodryCex4ICJUJ2s1SiE/zUsbT/y4YU5IDJafNh4cmTr/J518nTJ+V4rIOQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDcJtMc05bKVOr47eIEr1bSNTWpOJG3WgKP4gql+TNdxgIgbCxhbbgLPq2zVmR6fDh5RTamYCjKDW3kRj5UoXxgwvQ="}]},"maintainers":[{"name":"yeatszhang","email":"yichi.coder@foxmail.com"}],"directories":{}}},"readme":"# redux-toolkit\n\n## introduction\n\n提供实用的工具函数，改善使用redux的开发体验，提供代码可读性。\n\n* `createReducer` a functional way to write reducer\n* `createAction`  a simple way to write action\n* `debugMiddleware` a useful debug middleware\n\n## installation\n\n`mnpm install redux-toolkit`\n\n## Usage\n\n`import { createAction, createReducer, debugMiddleware } from 'redux-toolkit'`\n\n### createReducer\n\n避免使用switch碰到的问题：\n\n* 不用担心各个`case`下的变量冲突问题\n* 可以解构`action` 和 `state`\n* 使用箭头函数\n* 当swtich case 过多时，object 的速度会比 switch 更快\n* 不再会被 `break` 和 `default` 恶心\n\n下面是一个简单的reducer例子\n\n```\nimport { ADD_TODO, DELETE_TODO, EDIT_TODO, COMPLETE_TODO, COMPLETE_ALL, CLEAR_COMPLETED } from '../constants/ActionTypes';\n\nconst initialState = [{\n  text: 'Use Redux',\n  completed: false,\n  id: 0\n}];\n\nexport default createReducer({\n  [ADD_TODO]: (state, { text }) => [{\n    id: state.reduce((maxId, todo) => Math.max(todo.id, maxId), -1) + 1,\n    completed: false,\n    text\n  }, ...state],\n\n  [DELETE_TODO]: (state, { id }) => state.filter(todo =>\n    todo.id !== action.id\n  ),\n\n  [EDIT_TODO]: (state, { id, text }) => state.map(todo =>\n    todo.id === id ?\n      Object.assign({}, todo, { text }) :\n      todo\n  ),\n\n  [COMPLETE_ALL]: state => {\n    const areAllMarked = state.every(todo => todo.completed);\n    return state.map(todo => Object.assign({}, todo, {\n      completed: !areAllMarked\n    }));\n  },\n\n  [CLEAR_COMPLETED]: state => state.filter(todo => todo.completed === false)\n}, initialState)\n```\n\n### createAction\n\n提供更简单的方法去创建actionCreator。下面是通过actionCreator和普通方法进行对比。\n\n**创建没有payload的action**\n\n```\ncreateAction('showAll');\n\nfunction() {\n  return {\n    type: 'showAll'\n  }\n}\n```\n\n**只有一个携带值**\n\n当只有一个需要传递给`reducer`的值时，接受一个key。\n\n```\ncreateAction('add', 'value');\n\nfunction(value) {\n  return {\n    type: 'add',\n    payload: {\n      value: value\n    }\n  };\n}\n```\n\n**传递多个值**\n\n接受一个keys数组，会将参数按顺序放置在`action`的`payload`属性中。\n\n```\ncreateAction('add', ['num1', 'num2']);\n\nfunction (num1, num2) {\n  return {\n    type: 'add',\n    payload: {\n      num1: num1,\n      num2: num2  \n    }\n  };\n}\n```\n\n**根据函数创建action**\n\n接受一个将参数处理为`payload`的函数\n\n```\ncreateAction('add', (num1, num2) => {\n  number1: num1,\n  number2: num2,\n  other: num1 * num2\n})\n\nfunction (num1, num2) {\n  var getAction = (num1, num2) => {\n    number1: num1,\n    number2: num2,\n    other: num1 * num2\n  };\n  return {\n    type: 'add',\n    payload: getAction(num1, num2)\n  };\n}\n```\n\n## debugMiddleware\n\n提供一个debug的middleware\n\n### features\n\n* if dispatched action don't match [FSA](https://github.com/acdlite/flux-standard-action) rules, will throw Error\n* print the info of actions\n* print the old state after action dispatched\n","maintainers":[{"email":"yichi.coder@gmail.com","name":"yeatz"}],"time":{"modified":"2022-06-26T10:30:54.445Z","created":"2015-10-14T08:30:09.553Z","1.0.2":"2015-10-14T08:30:09.553Z","1.0.3":"2015-10-14T08:35:28.913Z","1.0.4":"2015-10-14T08:47:07.461Z","1.1.0":"2015-10-21T03:03:21.542Z","1.1.1":"2015-10-21T03:08:11.182Z","1.1.2":"2015-10-21T03:50:29.233Z"},"keywords":["redux","utils","helper"],"author":{"name":"yeatszhang"},"readmeFilename":"README.md","homepage":"https://github.com/yeatszhang/redux-toolkit#readme","repository":{"type":"git","url":"git+https://github.com/yeatszhang/redux-toolkit.git"},"bugs":{"url":"https://github.com/yeatszhang/redux-toolkit/issues"}}