simontonsoftware / s-libs

A collection of libraries for any of javascript, rxjs, or angular.
MIT License
43 stars 5 forks source link

[rxjs-core] Add `pageIsVisibile$()` #104

Closed ersimont closed 1 year ago

ersimont commented 1 year ago

Extract it from keepWakeLock$()

export function pageIsVisible$(): Observable<boolean> {
  return fromEvent(document, 'visibilitychange').pipe(
    startWith(undefined),
    map(() => document.visibilityState === 'visible'),
    distinctUntilChanged(),
  );
}
ersimont commented 1 year ago

Will be in the next release