Skip to content

Instantly share code, notes, and snippets.

@amoerie
Created June 26, 2017 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amoerie/2b7db64c4a2f0e88c0aaa483af8d15f7 to your computer and use it in GitHub Desktop.
Save amoerie/2b7db64c4a2f0e88c0aaa483af8d15f7 to your computer and use it in GitHub Desktop.
A nice, simple debug operator for RxJs 5.
import {Observable} from 'rxjs/Observable';
const isProduction: boolean = process && process.env && process.env.NODE_ENV === "production";
const debug = function <T>(this: Observable<T>, name: string) {
if (isProduction)
return this;
return this
.do({
next: (value: T) => {
console.group("Next : " + name);
console.dir(value);
console.groupEnd();
},
error: (error: Error) => {
console.group("Error : " + name);
console.dir(error);
console.groupEnd();
},
complete: () => console.log("Complete : " + name)
});
};
Observable.prototype.debug = debug;
declare module 'rxjs/Observable' {
interface Observable<T> {
debug: typeof debug;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment