{"id":18285899,"url":"https://github.com/exodusmovement/redux-watch","last_synced_at":"2025-04-06T23:17:30.430Z","repository":{"id":45889010,"uuid":"47999011","full_name":"ExodusMovement/redux-watch","owner":"ExodusMovement","description":"Watch/observe/monitor Redux store state changes","archived":false,"fork":false,"pushed_at":"2023-05-12T23:05:23.000Z","size":18,"stargazers_count":310,"open_issues_count":1,"forks_count":27,"subscribers_count":27,"default_branch":"master","last_synced_at":"2024-10-29T22:51:35.813Z","etag":null,"topics":[],"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/ExodusMovement.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2015-12-14T20:19:46.000Z","updated_at":"2024-10-21T22:08:21.000Z","dependencies_parsed_at":"2024-01-07T21:03:06.757Z","dependency_job_id":"dbbd2757-b0e7-4b17-86ce-f2940b1964c4","html_url":"https://github.com/ExodusMovement/redux-watch","commit_stats":null,"previous_names":["jprichardson/redux-watch"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExodusMovement%2Fredux-watch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExodusMovement%2Fredux-watch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExodusMovement%2Fredux-watch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExodusMovement%2Fredux-watch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ExodusMovement","download_url":"https://codeload.github.com/ExodusMovement/redux-watch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247563938,"owners_count":20958971,"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":[],"created_at":"2024-11-05T13:18:07.711Z","updated_at":"2025-04-06T23:17:30.400Z","avatar_url":"https://github.com/ExodusMovement.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# redux-watch\n\n[![NPM Package](https://img.shields.io/npm/v/redux-watch.svg?style=flat-square)](https://www.npmjs.org/package/redux-watch)\n[![Build Status](https://img.shields.io/github/workflow/status/ExodusMovement/redux-watch/Node.js%20CI/master?style=flat-square)](https://github.com/ExodusMovement/redux-watch/actions/workflows/ci.yml?query=branch%3Amaster)\n\n[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n\nWatch/observe [Redux](http://redux.js.org/) store state changes.\n\n## Why?\n\nRedux provides you with a `subscribe()` method so that you can be notified when the state changes. However, it does not let you know what changed. `redux-watch` will let you know what changed.\n\n\n## Install\n\n```\nnpm i --save redux-watch\n```\n\n## Usage\n\n`watch(getState [, objectPath [, comparison]])` -\u003e `function`\n\n- `getState`: A `function` that is used to return the state. Also useful in conjunction with selectors.\n- `objectPath`: An **optional** `string` or `Array` that represents the path in an object. Uses [object-path](https://www.npmjs.com/package/object-path) ([mariocasciaro/object-path](https://github.com/mariocasciaro/object-path)) for value extraction.\n- `comparison`: An **optional** function to pass for comparison of the fields. Defaults to strict equal comparison (`===`).\n\n## Example\n\n##### basic example\n\n```js\n// ... other imports/requires\nimport watch from 'redux-watch'\n\n// assuming you have an admin reducer / state slice\nconsole.log(store.getState().admin.name) // 'JP'\n\n// store is THE redux store\nlet w = watch(store.getState, 'admin.name')\nstore.subscribe(w((newVal, oldVal, objectPath) =\u003e {\n  console.log('%s changed from %s to %s', objectPath, oldVal, newVal)\n  // admin.name changed from JP to JOE\n}))\n\n// somewhere else, admin reducer handles ADMIN_UPDATE\nstore.dispatch({ type: 'ADMIN_UPDATE', payload: { name: 'JOE' }})\n```\n\n##### example (w/ [reselect](https://www.npmjs.com/package/reselect) ([reactjs/reselect](https://github.com/reactjs/reselect)) selectors)\n\nWhen using with selectors, you often times won't need to pass the object path. Most times the selectors will handle this for you.\n\n```js\n// ... other imports requires\nimport watch from 'redux-watch'\n\n// assuming mySelector is a reselect selector defined somewhere\nlet w = watch(() =\u003e mySelector(store.getState()))\nstore.subscribe(w((newVal, oldVal) =\u003e {\n  console.log(newVal)\n  console.log(oldVal)\n}))\n```\n\n#### Note on Comparisons.\n\nBy default, `redux-watch` uses `===` (strict equal) operator to check for changes. This may not be want you want. Sometimes you may want to do a deep inspection. You should use either [deep-equal](https://www.npmjs.com/package/deep-equal) ([substack/node-deep-equal](https://github.com/substack/node-deep-equal)) or [is-equal](https://www.npmjs.com/package/is-equal) ([ljharb/is-equal](https://github.com/ljharb/is-equal)). `is-equal` is better since it supports ES6 types like Maps/Sets.\n\n##### is-equal example\n\n```js\nimport isEqual from 'is-equal'\nimport watch from 'redux-watch'\n\nlet w = watch(store.getState, 'admin', isEqual)\nstore.subscribe(w((newVal, oldVal, objectPath) =\u003e {\n  // response to changes\n}))\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexodusmovement%2Fredux-watch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexodusmovement%2Fredux-watch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexodusmovement%2Fredux-watch/lists"}