mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-13 14:23:02 -05:00
feat(callstatelib): add a callstate publishable lib
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
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
|
||||
)
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user