-
-
Save soundyogi/9f786fdc419937bc3edf75540a0e03c3 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