Last active
October 11, 2018 13:18
-
-
Save braco/28dc2006e9ce04a004d2d9c4f5b9a4b6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import 'rxjs'; | |
import { Observable } from 'rxjs'; | |
Observable.prototype.debug = function(_message) { | |
const message = `EpicDebug: ${_message}`; | |
return this.do( | |
function(next) { | |
if (__DEV__) { | |
console.log(message, next); | |
} | |
}, | |
function(err) { | |
if (__DEV__) { | |
console.error('ERROR >>> ', message, err); | |
} | |
}, | |
function() { | |
if (__DEV__) { | |
console.log('Completed.', message); | |
} | |
} | |
); | |
}; | |
const debugEpic = debugName => epic => (...args) => | |
epic(...args) | |
.catch((error, source) => { | |
console.info(`${debugName}: caught an error.`, error, source); | |
setTimeout(() => { | |
throw error; | |
}, 0); | |
return source; | |
}) | |
.finally(() => | |
console.info(`${debugName}: epic exited.`, args) | |
); | |
export const wrapEpics = (epicObj, debugName = 'root') => { | |
if (typeof epicObj === 'function') { | |
return debugEpic(debugName)(epicObj); | |
} | |
return combineEpics( | |
...Object | |
.entries(epicObj) | |
.map(([name, epics]) => wrapEpics(epics, `${debugName}/${name}`)) | |
.map(debugEpic(debugName)) | |
); | |
}; |
This file contains hidden or 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
import { wrapEpics } from './epicHelpers'; | |
import * as reducer1Epics from './reducer1/epics'; | |
import * as reducer2Epics from './reducer2/epics'; | |
export default wrapEpics({ | |
reducer1Epics, | |
reducer2Epics, | |
}); |
This file contains hidden or 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
export const exampleEpic = epic$ => ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment