Watch/observe Redux store state changes.
Redux 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.
npm i --save redux-watch
watch(getState [, objectPath [, comparison]]) ->
functionthat is used to return the state. Also useful in conjunction with selectors.
objectPath: An optional
Arraythat represents the path in an object. Uses object-path (mariocasciaro/object-path) for value extraction.
comparison: An optional function to pass for comparison of the fields. Defaults to strict equal comparison (
// ... other imports/requires// assuming you have an admin reducer / state sliceconsole // 'JP'// store is THE redux storelet w =store// somewhere else, admin reducer handles ADMIN_UPDATEstore
reselect (reactjs/reselect) selectors)example (w/
When using with selectors, you often times won't need to pass the object path. Most times the selectors will handle this for you.
// ... other imports requires// assuming mySelector is a reselect selector defined somewherelet w =store
Note on Comparisons.
=== (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 (substack/node-deep-equal) or is-equal (ljharb/is-equal).
is-equal is better since it supports ES6 types like Maps/Sets.
deep equal example
let w =store
Copyright (c) JP Richardson