Last active
April 12, 2019 10:18
-
-
Save smoke/6e1b48e9f279193febd489569bceedda to your computer and use it in GitHub Desktop.
It allows you to easily dump things from a RxJS Observable
This file contains hidden or 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
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