Created
March 20, 2017 07:51
-
-
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.
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
// 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