SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

autoRefresh

Why JS: reloading a list on an interval, and pausing while the tab is hidden, needs a timer and the Page Visibility API.

tsx
import { autoRefresh } from "@sdxc/ui/app";

Usage

Runs a RefreshSchedule while the host <time> is in the document, counted from the host's own datetime. It pauses while the page is hidden, catches up with one reload when shown, sets data-paused meanwhile, and rewrites the host's datetime and text after each reload.

Signature

typescript
autoRefresh(options: AutoRefreshTimer.Options): MixinDescriptor<HTMLTimeElement>

Parameters

ParameterTypeRequiredDescription
optionsAutoRefreshTimer.OptionsYes

Examples

tsx
<time dateTime={iso} mix={[autoRefresh({ every: 30_000, reload: () => handle.frames.top.reload() })]}>{text}</time>

The events, constants and types its module publishes, each imported from @sdxc/ui/app too.

Interface

AutoRefreshTimer.Options

Configuration for autoRefresh, read when the host is inserted.

MemberTypeRequiredDescription
everynumberYesMilliseconds between reloads; 0 or less leaves the host as rendered.
reload() => Promise<unknown>YesReloads the frame or page the list lives in.
localestringNoLocale the refreshed time is written in. Defaults to the runtime's.
@sdxc/ui

Can’t find it? Contact us