Skip to content

Core concepts ​

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

Previous: Overview · Next: Tutorial

Observe → Understand → React ​

text
Browser APIs
    ↓
Normalized Session   ← Observe (core)
    ↓
Session Intelligence ← Understand (opt-in factories)
    ↓
Developer APIs       ← React (Wait, Conditions, Resilience)

One session. One snapshot. One event stream.
Everything else is derived. Core observation stays lightweight — intelligence and DX allocate only when you call their factories.

PillarMeaning
ObserveVisibility, focus, connectivity, idle, page lifecycle, cross-tab
UnderstandActivity, presence, timeline, session metrics & reports
ReactWait, conditions, resilience, plugins

Glossary ​

TermMeaning
SessionInstance from createBrowserLifecycle() — one per tab
VisibilityPage Visibility API → page:visible / page:hidden
IdleNo user activity past a threshold → idle / active events
SnapshotReadonly consolidated state from getSnapshot()
DisposeTeardown listeners, timers, plugins — session becomes unusable (sync)
SSR-safeMissing browser APIs detected; modules no-op until client start
Session IntelligenceOpt-in current derived state (activity, page-local presence)
Session InsightsOpt-in metrics and reports — not an analytics SDK

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 connection:* 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 stategetSnapshot()
Full feedAll eventslifecycle.subscribe(…)
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

Dispose on unmount

Leaked listeners on SPA navigations are the most common footgun. Always dispose() in the same scope that created the session.

Next steps ​

GoalGuide
Integration walkthroughTutorial
Page visibilityVisibility
Window focusFocus
Idle detectionIdle
Online/offlineConnectivity
Multi-tab coordinationCross-tab
Event subscriptionEvents
Extension pointsPlugins
Opt-in intelligenceIntelligence & DX

State explorer →

An ecosystem of independent, headless TypeScript libraries engineered for modern web development. Every package includes interactive playgrounds and documentation that evolves alongside the code.