Skip to content

Instantly share code, notes, and snippets.

@studioTeaTwo
Last active February 5, 2020 12:34
Show Gist options
  • Save studioTeaTwo/ed1562a9513d4c0b59a6d9532f743458 to your computer and use it in GitHub Desktop.
Save studioTeaTwo/ed1562a9513d4c0b59a6d9532f743458 to your computer and use it in GitHub Desktop.
const Observable$ = of(1).pipe(
tap(console.log),
delayWhenLoading(isLoading = true)
);
Observable$.subscribe();
const delayWhenLoading = <T>(isLoading: boolean, delayTime: number = defaultDelayTime): OperatorFunction<T, T> => {
return pipe(
delayWhen(() => {
if (isLoading) {
return timer(delayTime);
}
return timer(0);
}),
tap(() => console.log('emit'))
);
};
const Observable$ = of(1)
.tap(console.log);
delayWhenLoading(source$, isLoading = true).subscribe();
const delayWhenLoading = <T>(source$: Observable<T>, isLoading: boolean): Observable<T> => {
return source$
.delayWhen(() => {
if (isLoading) {
return timer(delayTime);
}
return timer(0);
})
.tap(() => console.log('emit'));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment