feat(callstatelib): add a callstate publishable lib

This commit is contained in:
thomas
2022-12-07 16:03:05 +01:00
parent 278e513538
commit 1ec45ce141
19 changed files with 1477 additions and 0 deletions

View File

@@ -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
)
);
};