redux-watch
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -0,3 +1,7 @@ | ||
2015-12-14 / 1.1.0 | ||
------------------ | ||
- pass `objectPath` to watch callback (access in `subscribe()`) | ||
2015-12-14 / 1.0.0 | ||
------------------ | ||
- initial release |
@@ -14,3 +14,3 @@ var getValue = require('object-path').get | ||
if (compare(baseVal, newVal)) return | ||
fn(newVal, baseVal) | ||
fn(newVal, baseVal, objectPath) | ||
baseVal = newVal | ||
@@ -17,0 +17,0 @@ } |
{ | ||
"name": "redux-watch", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Watch Redux state for changes.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -43,13 +43,17 @@ redux-watch | ||
```js | ||
// ... other imports requires | ||
// ... | ||
// ... other imports/requires | ||
import watch from 'redux-watch' | ||
// assuming you have an admin reducer / state slice | ||
console.log(store.getState().admin.name) // 'JP' | ||
// store is THE redux store | ||
// assuming you have an admin reducer | ||
let w = watch(store.getState, 'admin.name') | ||
store.subscribe(w(function(newVal, oldVal) { | ||
console.log(newval) | ||
console.log(oldVal) | ||
store.subscribe(w((newVal, oldVal, objectPath) => { | ||
console.log('%s changed from %s to %s', objectPath, oldVal, newVal) | ||
// admin.name changed from JP to JOE | ||
})) | ||
// somewhere else, admin reducer handles ADMIN_UPDATE | ||
store.dispatch({ type: 'ADMIN_UPDATE', payload: { name: 'JOE' }}) | ||
``` | ||
@@ -64,3 +68,2 @@ | ||
// ... other imports requires | ||
// ... | ||
import watch from 'redux-watch' | ||
@@ -70,3 +73,3 @@ | ||
let w = watch(() => mySelector(store.getState())) | ||
store.subscribe(w(function(newVal, oldVal) { | ||
store.subscribe(w((newVal, oldVal) => { | ||
console.log(newval) | ||
@@ -73,0 +76,0 @@ console.log(oldVal) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3573
84