Skip to content

Instantly share code, notes, and snippets.

@braco
Last active October 11, 2018 13:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save braco/28dc2006e9ce04a004d2d9c4f5b9a4b6 to your computer and use it in GitHub Desktop.
Save braco/28dc2006e9ce04a004d2d9c4f5b9a4b6 to your computer and use it in GitHub Desktop.
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))
);
};
import { wrapEpics } from './epicHelpers';
import * as reducer1Epics from './reducer1/epics';
import * as reducer2Epics from './reducer2/epics';
export default wrapEpics({
reducer1Epics,
reducer2Epics,
});
export const exampleEpic = epic$ => ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment