Visit time

Visit time

callbag

most

RxJS

xstream

This examples renders a stopwatch counting the time a user spends on a page while being online.

Aperture

Two sources observed:

Every time the page becomes visible and online, the stopwatch resumes. If the page becomes either offline or hidden, the stopwatch pauses.

Handler

The Refract handler handles pause, resume and tick effects to track the total time spent on the page and set it in state. It handles Date.now() impure calls.

Result

The end result is a stopwatch counting the number of milliseconds spent on the page when visible and online. To play with it you can:

  • switch between tabs, and you'll notice the counter hasn't moved while the example tab was hidden

  • toggle your navigator online status (can be done via devtools)

Last updated