Created
February 14, 2021 19:02
-
-
Save sashaaro/ad138ad6eafde27021b7a38731db9dbc to your computer and use it in GitHub Desktop.
log 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 { OperatorFunction } from 'rxjs'; | |
import { tap } from 'rxjs/operators'; | |
export function log<T>(prefix: string = null): OperatorFunction<T, T> { | |
return tap( | |
(data: T) => logIt(prefix, data), | |
err => logIt(prefix + '[ERROR]', err), | |
() => { | |
window.console.group(prefix + '[COMPLETE]') | |
window.console.groupEnd() | |
}, | |
); | |
} | |
function logIt(prefix?: string, data?: any): void { | |
if (prefix) { | |
window.console.group(prefix); | |
window.console.log(data); | |
window.console.groupEnd(); | |
} else { | |
window.console.log(data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment