Skip to content

Instantly share code, notes, and snippets.

@LironHazan
Created October 12, 2020 18:59
Show Gist options
  • Save LironHazan/47cc7ce993f7e17992b5c925a0259c10 to your computer and use it in GitHub Desktop.
Save LironHazan/47cc7ce993f7e17992b5c925a0259c10 to your computer and use it in GitHub Desktop.
Yoni Argivi's snippet for rxjs post
public getHttpDistinctResponse(httpRequest$: Observable<any>): Observable<any> {
let cachedResponseStr = null;
return httpRequest$.pipe(
filter((response) => {
const currentResponseStr = JSON.stringify(response);
const areEquals = cachedResponseStr === currentResponseStr;
if (!areEquals) {
cachedResponseStr = currentResponseStr;
}
return !areEquals;
})
);
}
export function pollingOnResolved(httpRequest$: Observable<any>, delayMs = 0): Observable<any> {
const polling$ = new BehaviorSubject({});
const rePolling$ =
of('').pipe(
delay(delayMs),
tap(() => polling$.next({})),
skip(1)
);
// BOOM
const request = ignoreEqualResponses ? this.getHttpDistinctResponse(httpRequest$) : httpRequest$;
const httpPolling$ = concat(request, rePolling$);
return polling$.pipe(switchMap(() => httpPolling$));
}
@LironHazan
Copy link
Author

Let's agree to disagree.. I'm tired of this thread as it's pointless, that's ok to disagree, you think that my understanding is wrong I think that your understanding is wrong that's fine as long as we're chatting politely, IMO the software community should feel like a "safe" place..

Have a nice weekend and may the code be with you.

@mhamri
Copy link

mhamri commented Jun 17, 2021

disagree on something that is testable, and easy to confirm is ignorance, anyway...
You said the best; you have a good weekend too. ✌️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment