{"id":22865369,"url":"https://github.com/toplan/redux-on","last_synced_at":"2026-05-19T10:05:15.813Z","repository":{"id":85627708,"uuid":"89583007","full_name":"toplan/redux-on","owner":"toplan","description":"Store enhancer for redux which support accurately subscribe","archived":false,"fork":false,"pushed_at":"2017-05-02T14:49:11.000Z","size":7,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-11T08:37:02.674Z","etag":null,"topics":["enhancer","redux","redux-on","subscribe"],"latest_commit_sha":null,"homepage":null,"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/toplan.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-27T09:55:45.000Z","updated_at":"2023-03-10T10:01:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"6e213ec8-30cd-452f-a3b4-4bd148593348","html_url":"https://github.com/toplan/redux-on","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/toplan/redux-on","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toplan%2Fredux-on","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toplan%2Fredux-on/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toplan%2Fredux-on/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toplan%2Fredux-on/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toplan","download_url":"https://codeload.github.com/toplan/redux-on/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toplan%2Fredux-on/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272612151,"owners_count":24964388,"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","status":"online","status_checked_at":"2025-08-29T02:00:10.610Z","response_time":87,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["enhancer","redux","redux-on","subscribe"],"created_at":"2024-12-13T11:36:48.708Z","updated_at":"2026-05-19T10:05:15.781Z","avatar_url":"https://github.com/toplan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"redux-on\n==============\n\n[![build status](https://img.shields.io/travis/toplan/redux-on/master.svg?style=flat-square)](https://travis-ci.org/toplan/redux-on)\n[![npm version](https://img.shields.io/npm/v/redux-on.svg?style=flat-square)](https://www.npmjs.com/package/redux-on)\n[![npm downloads](https://img.shields.io/npm/dm/redux-on.svg?style=flat-square)](https://www.npmjs.com/package/redux-on)\n\nStore enhancer for [redux](https://github.com/reactjs/redux) which support accurately subscribe.\n\n## Install\n\n```js\nnpm i --save redux-on\n```\n\n## Usage\n\n```js\nimport { createStore, applyMiddleware, compose } from 'redux'\nimport accuratelySubscribe from 'redux-on'\n\nconst enhancer = compose(\n  applyMiddleware(...middleware),\n  accuratelySubscribe()\n)\nconst store = createStore(reducer, initialState, enhancer)\n\n// example\nconst off = store.on((prevState, state) =\u003e {\n  return prevState.user !== state.user\n}, (prevState, state) =\u003e {\n  alert(`Hi, ${state.user.name}, welcome!`)\n})\n```\n\n## Api\n\n#### on([type], [predicate], handler, [once])\n\nAdds a change handler. It will be called any time an action with specified type dispatched\nor successful predication.\n\n###### Arguments\n1. `type` (String): The type of action.\n2. `predicate` (Function): The logic of predication. It will be called with two parameters: `prevState`, `state`. Need to returns a boolean value.\n3. `handler` (Function): The change handler. It will be called with two parameters: `prevState`, `state`.\n4. `once` (Boolean): Whether to handle change only once. Default `false`.\n\n###### Returns\n(Function): A function that drop the change handler.\n\n###### Examples\n```js\n// listen customer change by action type.\nconst off = store.on('CUSTOMER', (prevState, state) =\u003e {\n  alert(`Hi, ${state.customer.name}! welcome to the bar.`)\n})\n// listen customer change by predication.\nconst off1 = store.on(\n  (prevState, state) =\u003e prevState.customer !== state.customer,\n  (prevState, state) =\u003e alert(`Hi, ${state.customer.name}! welcome to the bar.`)\n)\n// listen customer change by action type and predication.\nconst off2 = store.on(\n  'CUSTOMER',\n  (prevState, state) =\u003e state.customer.age \u003c 18,\n  (prevState, state) =\u003e alert(`Hey, boy! Can't drink!`)\n)\n// cancel listen\noff()\n```\n\n#### once([type], [predicate], handler)\n\nAdds a change handler. It will be called only once an action with specified type dispatched\nor successful predication.\n\n###### Arguments\n1. `type` (String): The type of action.\n2. `predicate` (Function): The logic of predication. It will be called with two parameters: `prevState`, `state`. Need to returns a boolean value.\n3. `handler` (Function): The change handler. It will be called with two parameters: `prevState`, `state`.\n\n###### Returns\n(Function): A function that drop the change handler.\n\n###### Examples\n```js\nstore.once('CUSTOMER', (prevState, state) =\u003e {\n  alert(`Hey, you are the first customer, free drinking tonight!`)\n})\n// or\nstore.once(\n  (prevState, state) =\u003e !prevState.customer \u0026\u0026 state.customer,\n  (prevState, state) =\u003e alert(`Hey, you are the first customer, free drinking tonight!`)\n)\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoplan%2Fredux-on","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoplan%2Fredux-on","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoplan%2Fredux-on/lists"}