Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Forked from jhades/01-debug-rxjs.ts
Created April 30, 2019 19:53
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 stevewithington/4b760dac156e2aa21e59bed54c560f14 to your computer and use it in GitHub Desktop.
Save stevewithington/4b760dac156e2aa21e59bed54c560f14 to your computer and use it in GitHub Desktop.
onSelectUser(participantId:string) {
this.participantsService.findParticipantById(parseInt(participantId))
.debug("Loading participant from backend")
.subscribe(
participant => {
...
},
console.error
);
}
findParticipantById(participantId: number): Observable<Participant> {
return this.http.get(`/api/participants/${participantId}`)
.do( res => console.log('HTTP response:', res))
.map(res => res.json().payload)
.do(console.log);
}
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/mergeMap';
import {Observable} from "rxjs";
const debuggerOn = true;
Observable.prototype.debug = function (message: string) {
return this.do(
function (next) {
if (debuggerOn) {
console.log(message, next);
}
},
function (err) {
if (debuggerOn) {
console.error('ERROR >>> ',message , err);
}
},
function () {
if (debuggerOn) {
console.log('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