Created
April 22, 2019 18:26
-
-
Save taras/fa31aa77c2ed3c49167f8018af945306 to your computer and use it in GitHub Desktop.
This file contains 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 } from "rxjs"; | |
import { valueOf } from 'microstates' | |
import { diff } from 'deep-object-diff' | |
export const logDiff = (name: string) => <T>(source: Observable<T>) => | |
new Observable<T>(observer => { | |
let last: any; | |
return source.subscribe({ | |
next(x) { | |
console.log(name, diff(valueOf(last), valueOf(x))); | |
last = x; | |
observer.next(x); | |
}, | |
error(err) { observer.error(err); }, | |
complete() { observer.complete(); } | |
}) | |
}) |
This file contains 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 } from "rxjs"; | |
import * as captureStackTrace from 'capture-stack-trace'; | |
import { get } from 'stack-trace'; | |
// @ts-ignore | |
if (!Error.captureStackTrace) { | |
// @ts-ignore | |
Error.captureStackTrace = captureStackTrace; | |
} | |
export const logStackTrace = (name: string, belowFn?: () => void) => console.log(name, get(belowFn)) | |
export const logStackTraceOp = (belowFn?: () => void) => <T>(source: Observable<T>) => | |
new Observable<T>(observer => { | |
return source.subscribe({ | |
next(x) { | |
logStackTrace('STACK TRACE', belowFn); | |
observer.next(x); | |
}, | |
error(err) { observer.error(err); }, | |
complete() { observer.complete(); } | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment