mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-12 05:43:03 -05:00
21 lines
559 B
TypeScript
21 lines
559 B
TypeScript
import { combineLatest, map, mapTo, Observable, startWith, timer } from 'rxjs';
|
|
|
|
/**
|
|
* Delay the first emition of data$ value. Instead, it emits "true" until duration is elapsed
|
|
*/
|
|
export const nonFlickerLoader = (
|
|
data$: Observable<boolean>,
|
|
duration = 300
|
|
): Observable<boolean> => {
|
|
const isTrueWhileDuration$ = timer(duration).pipe(
|
|
mapTo(false),
|
|
startWith(true)
|
|
);
|
|
|
|
return combineLatest([data$, isTrueWhileDuration$]).pipe(
|
|
map(([data, isTrueWhileDuration]) =>
|
|
isTrueWhileDuration ? isTrueWhileDuration : data
|
|
)
|
|
);
|
|
};
|