-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: add logging wrapper around redux-watch
- Loading branch information
1 parent
07e8855
commit 6fddc8f
Showing
3 changed files
with
53 additions
and
21 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
server/zanata-frontend/src/frontend/app/editor/actions/phrases-action-types.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
server/zanata-frontend/src/frontend/app/editor/watchers/watch.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* Enhances redux-watch to add logging. | ||
* | ||
* Add the watcher name for the logger to use: | ||
* | ||
* original: watch(selector) // plain redux-watch | ||
* enhanced: watch('myWatcher')(selector) | ||
*/ | ||
|
||
import reduxWatch from 'redux-watch' | ||
|
||
const withLog = name => f => { | ||
if (process.env && (process.env.NODE_ENV === 'development')) { | ||
return (state, prevState) => { | ||
/* eslint-disable no-console */ | ||
console.group('%c watcher: %s', 'font-weight: bold; color: #CC6600', name) | ||
console.log('%c was', 'font-weight: bold; color: #9E9E9E', prevState) | ||
console.log('%c now', 'font-weight: bold; color: #03A9F4', state) | ||
console.groupEnd() | ||
/* eslint-enable no-console */ | ||
return f(state, prevState) | ||
} | ||
} else { | ||
return f | ||
} | ||
} | ||
|
||
const watch = (name) => (...watchArgs) => (callback) => | ||
reduxWatch(...watchArgs)(withLog(name)(callback)) | ||
|
||
export default watch |