{"id":47783770,"url":"https://github.com/xixilive/redux-weapp","last_synced_at":"2026-04-03T14:03:07.895Z","repository":{"id":46907611,"uuid":"77838874","full_name":"xixilive/redux-weapp","owner":"xixilive","description":"1KB(gzip) Redux-based微信小程序状态管理, 极简地分离数据与表现。","archived":false,"fork":false,"pushed_at":"2023-01-05T09:43:12.000Z","size":939,"stargazers_count":97,"open_issues_count":13,"forks_count":18,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-24T13:47:49.951Z","etag":null,"topics":["redux","redux-weapp","weapp","wechat","weixin"],"latest_commit_sha":null,"homepage":"","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/xixilive.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-02T14:25:29.000Z","updated_at":"2024-04-23T07:48:09.000Z","dependencies_parsed_at":"2023-02-03T23:31:17.441Z","dependency_job_id":null,"html_url":"https://github.com/xixilive/redux-weapp","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/xixilive/redux-weapp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xixilive%2Fredux-weapp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xixilive%2Fredux-weapp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xixilive%2Fredux-weapp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xixilive%2Fredux-weapp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xixilive","download_url":"https://codeload.github.com/xixilive/redux-weapp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xixilive%2Fredux-weapp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31355719,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T08:03:20.796Z","status":"ssl_error","status_checked_at":"2026-04-03T08:00:37.834Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["redux","redux-weapp","weapp","wechat","weixin"],"created_at":"2026-04-03T14:02:11.424Z","updated_at":"2026-04-03T14:03:07.888Z","avatar_url":"https://github.com/xixilive.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# redux-weapp\n\n![Travis](https://img.shields.io/travis/xixilive/redux-weapp/master.svg)\n![npm bundle size (minified + gzip)](https://img.shields.io/bundlephobia/minzip/redux-weapp.svg)\n![npm](https://img.shields.io/npm/dt/redux-weapp.svg)\n![NpmVersion](https://img.shields.io/npm/v/redux-weapp.svg)\n[![Known Vulnerabilities](https://snyk.io/test/github/xixilive/redux-weapp/badge.svg?targetFile=package.json)](https://snyk.io/test/github/xixilive/redux-weapp?targetFile=package.json)\n![NpmLicense](https://img.shields.io/npm/l/redux-weapp.svg)\n\nRedux-based State Management for Wechat applet(微信小程序, weapp), to connect Redux store with your weapp's App or Page lifecycles. \n\n## Install\n\n```\n# via Github\nnpm install xixilive/redux-weapp --save-dev\n\n# via npm\nnpm install redux-weapp --save-dev\n\n# via yarn\nyarn add -D redux-weapp\n```\n\n## Build\n\n```sh\ngit clone https://github.com/xixilive/redux-weapp.git \\\n  \u0026\u0026 cd redux-weapp \\\n  \u0026\u0026 yarn \\\n  \u0026\u0026 yarn build\n```\n\n## Usage\n\nBefore trying these demo code snippets, you should/must be experienced in weapp modulize development. \n[微信小程序模块化开发实践](https://www.jianshu.com/p/8fe7b756a211)\n\n```js\n// Redux store\nimport {createStore} from 'redux'\n//create your Redux store\nconst store = createStore(...)\n```\n\n## connect to weapp App\n\n```js\nimport connect from 'redux-weapp'\nconst config = connect.App(\n  store,\n  //to map next state into your app\n  (state) =\u003e {\n    // must return an object, which will be passed to onStateChange function\n    return {}\n  },\n  // to bind dispatch with your action,\n  // and this binding will be injected into your app object.\n  (dispatch) =\u003e {\n    // return an object, which can be invoked within app context(this scope).\n    return {}\n  }\n)({\n  onLaunch(options){},\n  //...,\n  onStateChange(nextState, prevState, initFlag){\n    this.setData({...this.data, ...nextState})\n  }\n})\n\n// construct your app\nApp(config)\n```\n\n### connect to weapp Page\n\nAssume we have a [store shape](https://redux.js.org/basics/store) as following:\n\n```json\n{\n  \"todos\": [\n    {\n      \"title\": \"String\",\n      \"complete\": \"Boolean\"\n    }\n  ]\n}\n```\n\nand we have defined an action creator([FSA](https://github.com/redux-utilities/flux-standard-action)) as:\n\n```js\nconst fetchTodosAction = (status) =\u003e ({type: 'FETCH_TODOS', filter: {status}})\n```\n\nOk, let's connect store to todo-list page.\n\n```js\n// \nimport connect from 'redux-weapp'\n\nconst config = connect.Page(\n  store,\n  //to map next-state into your page\n  (state) =\u003e ({todos: state.todos}),\n\n  // to bind dispatch with your action creators,\n  // and this binding will be injected into your page object\n  (dispatch) =\u003e ({\n    fetchTodos(status = 'inprogress'){\n      // dispatch an action\n      dispatch(fetchTodosAction(status))\n    }\n  })\n)({\n  onLoad(options){\n    this.fetchTodos('inprogress')\n  },\n  \n  onStateChange(nextState, prevState, initFlag){\n    const {todos} = nextState\n    this.setData({todos}) // to update UI\n  },\n\n  // view interactions\n  onTapCompleteTab(){\n    this.fetchTodos('complete')\n  },\n\n  onTapInProgressTab(){\n    this.fetchTodos('inprogress')\n  }\n})\n\n// construct your page\nPage(config)\n```\n\n## connect API\n\n### connect.App\n\n```ts\n//define app connect function\nfactory = connect.App(\n  store:ReduxStore, \n  mapStateToProps:Function(state:Object), \n  mapDispatchToProps:Function(dispatch:Function)\n):Function\n\n//build a store-binding app config object\nconfig = factory({\n  onLaunch(options:Object){},\n  onStateChange(nextState:Object, prevState:Object, initFlag:Any),\n  //...\n}):Object\n\n//launch app with store-binding config\nApp(config)\n```\n\n### connect.Page\n\n```ts\n//define page connect function\nfactory = connect.Page(\n  store:ReduxStore, \n  mapStateToProps:Function(state:Object), \n  mapDispatchToProps:Function(dispatch:Function)\n):Function\n\n//build a store-binding page config object\nconfig = factory({\n  onLoad(options:Object){},\n  onStateChange(nextState:Object, prevState:Object, initFlag:Any)\n  //...\n}):Object\n\n//start page instance with store-binding config\nPage(config)\n```\n\n### the `onStateChange` function\n\n```ts\n// would be called after each concerned state changed\nonStateChange(nextState:Object, prevState:Object, initFlag:Any):void\n```\n\n- `initFlag`: new feature from `redux-weapp@0.2.x`, see Changes section for details.\n\n## Changes from v0.2.x\n\n### `connect.App` API\n\n- removed `appLaunchOptions` argument from `mapState` function.\n\n```ts\n// v0.1.x\nconnect.App({\n  store:ReduxStore,\n  mapState:Function(state:Object, appLaunchOptions:Object):Object,\n  mapDispatch:Function(dispatch:Function):Object,\n})\n\n// v0.2.x\nconnect.App({\n  store:ReduxStore,\n  mapState:Function(state:Object):Object,\n  mapDispatch:Function(dispatch:Function):Object,\n})\n```\n\n### `connect.Page` API\n\n- removed `pageLoadOptions` argument from `mapState` function.\n\n```ts\n// v0.1.x\nconnect.Page({\n  store:ReduxStore,\n  mapState:Function(state:Object, pageLoadOptions:Object):Object,\n  mapDispatch:Function(dispatch:Function):Object,\n})\n\n// v0.2.x\nconnect.Page({\n  store:ReduxStore,\n  mapState:Function(state:Object):Object,\n  mapDispatch:Function(dispatch:Function):Object,\n})\n```\n\n### `onStateChange` callback\n\n- add `initFlag` as the 3rd argument, which could be a string value `INIT_SYNC` just on the very first dispatch, `undefined` otherwise.\n\n```ts\n// v0.1.x\nonStateChange(nextState:Object, prevState:Object)\n\n// v0.2.x\nonStateChange(nextState:Object, prevState:Object, initFlag:Any)\n```\n\n## Lifecycles\n\n### for weapp App\n\n- `onLaunch`\n\nsetup an subscribe listener when `onLaunch` function called, and the initial store state will be broadcasted.\n\n- `onShow`\n\nAn inactive listener will be set to `active` when `onShow` function has called, and the listener will be called with last state.\n\n- `onHide`\n\nAn active listener will be set to `inactive` when `onHide` function has called.\n\n### for weapp Page\n\n- `onLoad`\n\nsetup an subscribe listener when `onLoad` function called, and the initial store state will be broadcasted.\n\n- `onShow`\n\nAn inactive listener will be set to `active` when `onShow` function has called, and the listener will be called with last state.\n\n- `onHide`\n\nAn active listener will be set to `inactive` when `onHide` function has called.\n\n- `onUnload`\n\nThe listener will be remove when `onUnload` function has called.\n\n----\n\nGood luck!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxixilive%2Fredux-weapp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxixilive%2Fredux-weapp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxixilive%2Fredux-weapp/lists"}