Page visibility
Allows tracking window focus and blur with Events and Stores.
INFO
Uses Page Visibility API under the hood
Usage
All you need to do is to create an integration by calling trackPageVisibility
with an integration options:
setup
: after this Event all listeners will be installed, and the integration will be ready to use; it is required because it is better to use explicit initialization Event in the application.teardown?
: after this Event all listeners will be removed, and the integration will be ready to be destroyed.
ts
import { trackPageVisibility } from '@withease/web-api';
const { visible, hidden, $visible, $hidden } = trackPageVisibility({
setup: appStarted,
});
Returns an object with:
visible
: Event fired when the content of a tab has become visiblehidden
: Event fired when the content of a tab has been hidden$visible
: Store withtrue
if document is visible andfalse
if it is hidden$hidden
: Store withfalse
if document is visible andtrue
if it is hidden
TIP
It supports @@trigger
protocol. Since it allows firing only one Event trackPageVisibility
triggers visible
as a fired
in case of @@trigger
protocol.
ts
import { trackPageVisibility } from '@withease/web-api';
somethingExpectsTrigger(trackPageVisibility);
Live demo
Let us show you a live demo of how it works. The following demo displays history of hidden
and visible
Events. Switch to other tab and return there see how it works.