Skip to content

Core concepts

Terminology and session model for @jayoncode/browser-lifecycle.

Previous: Overview · Next: Tutorial

Problem → approach

Scattered browser listenersWith Browser Lifecycle
document.addEventListener("visibilitychange", …) in every featureOne session, typed page:visible / page:hidden events
Duplicate online/offline handlers across modulesNormalized connectivity:* events + snapshot
No single place to read “current tab state”getSnapshot() — readonly consolidated state
Leaked listeners on SPA route changesdispose() tears down modules and subscriptions

Session

ts
const lifecycle = createBrowserLifecycle({ autoStart: true });

One instance per browser tab. Share it via app context — do not create one per component.

API map

ConceptResponsibilityAPI
SessionLifecycle boundarycreateBrowserLifecycle()
EventNormalized browser signallifecycle.on("page:hidden", …)
SnapshotCurrent module statelifecycle.getSnapshot()
ModuleVisibility, focus, idle, etc.Configuration + typed events
PluginCross-cutting extensionPlugin registration API

Session phases

PhaseMeaning
createdConstructed, not listening
runningActive listeners
stoppedPaused
disposedTorn down — do not reuse

Next steps

GoalGuide
Integration walkthroughTutorial
Page visibilityVisibility
Event subscriptionEvents

State explorer →

JOC is a JayOnCode monorepo of @jayoncode/* packages. Docs sync from source via TypeDoc and sync scripts.