Skip to content

Instantly share code, notes, and snippets.

@smoke
Last active April 12, 2019 10:18
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 smoke/6e1b48e9f279193febd489569bceedda to your computer and use it in GitHub Desktop.
Save smoke/6e1b48e9f279193febd489569bceedda to your computer and use it in GitHub Desktop.
It allows you to easily dump things from a RxJS Observable
import {tap} from 'rxjs/operators';
export function rxjsDebug<T>(context: string) {
return tap<T>(
v => {
console.log(`next(${context})`, v);
},
e => {
console.log(`error(${context})`, e);
},
() => {
console.log(`complete(${context})`);
}
);
}
/* Example usage
const subject = new Subject();
const subscription = subject.pipe(rxjsDebug('subject')).subscribe();
const subject.next('Hi'); // will log `'next(subject)' 'Hi`
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment