{"id":18369059,"url":"https://github.com/dog-days/redux-mutation","last_synced_at":"2025-04-06T17:31:56.984Z","repository":{"id":57351079,"uuid":"153060077","full_name":"dog-days/redux-mutation","owner":"dog-days","description":"变异版 Redux ","archived":false,"fork":false,"pushed_at":"2024-09-29T08:16:32.000Z","size":653,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-21T23:34:58.745Z","etag":null,"topics":["dva","middleware","redux","redux-center","redux-saga"],"latest_commit_sha":null,"homepage":"https://redux-mutation.gitbook.io/zh-cn/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dog-days.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-15T05:56:58.000Z","updated_at":"2023-03-27T08:09:38.000Z","dependencies_parsed_at":"2022-09-18T23:40:46.579Z","dependency_job_id":null,"html_url":"https://github.com/dog-days/redux-mutation","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dog-days%2Fredux-mutation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dog-days%2Fredux-mutation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dog-days%2Fredux-mutation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dog-days%2Fredux-mutation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dog-days","download_url":"https://codeload.github.com/dog-days/redux-mutation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247522444,"owners_count":20952552,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dva","middleware","redux","redux-center","redux-saga"],"created_at":"2024-11-05T23:28:18.977Z","updated_at":"2025-04-06T17:31:55.529Z","avatar_url":"https://github.com/dog-days.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Redux-Mutation\n\n[![build status](https://travis-ci.org/dog-days/redux-mutation.svg?branch=master)](https://travis-ci.org/dog-days/redux-mutation) [![codecov](https://codecov.io/gh/dog-days/redux-mutation/branch/master/graph/badge.svg)](https://codecov.io/gh/dog-days/redux-mutation) [![npm package](https://badge.fury.io/js/redux-mutation.svg)](https://www.npmjs.org/package/redux-mutation) [![NPM downloads](http://img.shields.io/npm/dm/redux-mutation.svg)](https://npmjs.org/package/redux-mutation) ![](https://img.shields.io/badge/minzipped%20size-4.5kb-brightgreen.svg)\n\n\u003e 如果你只是用了 Redux，然后想过度到 redux-mutation，你完全可以使用 redux-mutation 替换 redux。迁移特别简单，请看[迁移到 redux-mutation](./docs/other/migrating.md)文章。\n\n`redux-mutaion`是变异版的`redux`，基于 [redux](https://redux.js.org/)，**保留 `redux` 所有原用法的基础上**，定义了新用法（dva model 用方法）。`redux-mutation` 同时支持 `async` 和 `generator` 用法，这个得益于 `redux-center`。\n\n`redux-mutation` 是基于[redux-center](https://github.com/dog-days/redux-center)，有一个`center`概念，这个可以移步 `redux-center`。（如果你用过 dva ，你可以理解 centers 为 effects）。\n\n`redux-mutation` umd 包 gip 后只有 4.5KB（包括 redux-center 和 redux），所以不用担心会太大。\n\n`redux-mutation` 默认用法相当于 `dva` model 的抽离，本人也会向 `dva` 的 model 的用法进行兼容（当然 redux-saga 用法兼容不了）。\n\n## 由来\n\n之所以单独抽离阿里 [dva](https://github.com/dvajs/dva) model 的原因如下：\n\n- dva 官方并没有单独抽离 model 的用法，而是和其他框架逻辑耦合在一起。\n- dva model 不兼容原生 redux 原生写法的，用法需全部迁移\n\n\n\n## 浏览器兼容性\n\n兼容 IE11、edge、谷歌、火狐、safar 等浏览器，其中 IE 需要而外支持`promise`。\n\n### Npm Promise\n\n首先安装 promise\n\n```sh\nnpm i promise\n```\n\n然后添加下面代码\n\n```js\nif (typeof Promise === 'undefined') {\n  // Rejection tracking prevents a common issue where React gets into an\n  // inconsistent state due to an error, but it gets swallowed by a Promise,\n  // and the user has no idea what causes React's erratic future behavior.\n  require('promise/lib/rejection-tracking').enable();\n  window.Promise = require('promise/lib/es6-extensions.js');\n}\n```\n\n### Umd Promise\n\n```html\n\u003cscript src=\"https://www.promisejs.org/polyfills/promise-6.1.0.min.js\"\u003e\u003c/script\u003e\n```\n\n## 入门使用\n\n### 安装\n\n需要而外安装`redux \u003e= 3.1.0`，测试是基于 `redux@4.0.1`，最低兼容到 `redux@3.1.0` 版本，这个跟 `applyMiddleware` 有关。\n\n```sh\nnpm i redux redux-mutation\n```\n\n### 使用例子\n\n```js\nimport { createStore } from 'redux-mutation';\n\nconst mutations = [\n  {\n    // 别名 state，兼容 dva\n    initialState: 0,\n    namespace: 'counter',\n    reducers: {\n      increment(state, action) {\n        return state + 1;\n      },\n      decrement(state, action) {\n        return state - 1;\n      },\n    },\n    // 别名 effects，兼容 dva\n    centers: {\n      async increment_async(action, { put, call, select }) {\n        await put({ type: 'increment' }, 'counter');\n      },\n    },\n  },\n];\nconst store = createStore(mutations);\nstore.subscribe(function() {\n  console.log('rendered', 'You can render dom here.');\n});\nstore.dispatch({ type: 'tester/increment_async' });\n```\n\n## 文档\n\n- [API 文档](./docs/api/README.md)\n\n## 在浏览器中使用 umd 方式\n\n### cdn 方式\n\n- https://unpkg.com/redux-mutation/dist/redux-mutation.js\n- https://unpkg.com/redux-mutation/dist/redux-mutation.min.js\n\n`const { createStore } = window.ReduxMutation`相当于 es6 import:\n\n```js\nimport { createStore } from 'redux-mutation';\n```\n\n### 构建方式\n\n```sh\ngit clone https://github.com/dog-days/redux-mutation\ncd redux-mutation\nnpm install\n#npm test（安装完成后，postinstall 会触发）\n#npm run build （生成例子可用代码，安装完成后，postinstall 会触发）\n```\n\n然后在根目录下的 `./dist` 文件夹获取相关的 js 文件。\n\n## 基于源文件运行例子\n\n请看[这里](https://github.com/dog-days/redux-mutation/tree/master/examples)。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdog-days%2Fredux-mutation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdog-days%2Fredux-mutation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdog-days%2Fredux-mutation/lists"}