Skip to content

Instantly share code, notes, and snippets.

@AndreaPaciolla
Created March 20, 2017 07:51
Show Gist options
  • Save AndreaPaciolla/34dba0918edc6348cbfe0c1b52356f07 to your computer and use it in GitHub Desktop.
Save AndreaPaciolla/34dba0918edc6348cbfe0c1b52356f07 to your computer and use it in GitHub Desktop.
A simple utility function to help debugging rxJS observables. This function extends rxjs/Observable namespace and allow to use a function as debug.
// main.ts
const debuggerOn = true;
Observable.prototype.debug = function(message: string) {
return this.do(
nextValue => {
if(debuggerOn) console.log(message, nextValue);
},
error => {
if(debuggerOn) {
console.error(message, err);
}
},
() => {
if(debuggerOn) {
console.log("Observable completed - ");
}
}
);
}
declare module 'rxjs/Observable' {
interface Observable<T> {
debug: (...any) => Observable<T>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment