Created
July 12, 2019 18:07
-
-
Save alexeden/45187c0c5678f2d878b44e5a00daf65f to your computer and use it in GitHub Desktop.
Tag RxJS Operator
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 { Observable, Subscriber } from 'rxjs'; | |
| const nextCss = `background-color: cyan; color: #000000; font-weight: bold;`; | |
| const errorCss = `background-color: #f64040; color: #ffffff; font-weight: bold;`; | |
| const completeCss = `background-color: rgb(24, 255, 148); color: #000000; font-weight: bold;`; | |
| export const tag = (tagText: string, stringify = false) => { | |
| return <T>(source: Observable<T>) => | |
| new Observable((observer: Subscriber<T>) => { | |
| let count = 0; | |
| return source.subscribe({ | |
| next(x) { | |
| console.log(`%c${tagText} #${++count} `, nextCss, stringify ? JSON.stringify(x, null, 2) : x); | |
| observer.next(x); | |
| }, | |
| error(err) { | |
| console.log(`%c${tagText} error after #${count} emissions `, errorCss, err); | |
| observer.error(err); | |
| }, | |
| complete() { | |
| console.log(`%c${tagText} completed after #${count} emissions `, completeCss); | |
| observer.complete(); | |
| }, | |
| }); | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment