Application lifecycle state for TypeScript, React and React Native.
Documentation · Try the lifecycle lab · Changelog
Give your application one shared view of whether it is in the foreground and whether interaction is available. Pulse reports immutable snapshots and deduplicated foreground/background transitions, with an estimate of how long the app was away. The browser and React Native adapters share the same API.
No runtime dependencies. ESM. React is optional.
pnpm add @priemskiyyy/pulseSee status for the verification limits.
import { Pulse } from "@priemskiyyy/pulse";
import { browser } from "@priemskiyyy/pulse/browser";
export const pulse = new Pulse({ adapter: browser() });
pulse.on("foreground", (event) => {
console.log("Returned after", event.observedAway, "ms");
});
pulse.start();import { Pulse } from "@priemskiyyy/pulse";
import { reactNative } from "@priemskiyyy/pulse/react-native";
import { AppState, Platform } from "react-native";
export const pulse = new Pulse({
adapter: reactNative({ appState: AppState, platform: Platform.OS }),
});
pulse.start();Create and start the instance at application bootstrap. In React, publish it
with <PulseProvider pulse={pulse}> and read it with useLifecycle() from
@priemskiyyy/pulse-react, or pass it directly. Subscriptions are passive;
call pulse.dispose() only when the application explicitly tears down the host.
For one listener in one component, use them directly. Pulse is for the moment several services each attach their own listener and each decide differently what "active" means, what to do at startup, and what counts as a return:
- Two fields, not a boolean. A visible window without focus, an iOS
inactiveinterruption and the Android notification drawer change interaction, never phase. - Unknown is a value. Discovering the first state is not a transition, and nothing is inferred across an unknown gap, so startup never looks like a return.
- Deduplicated, ordered edges.
pagehide,visibilitychange,resume,pageshowandfocusaround one restore are one foreground event, and events queued from a callback wait their turn instead of being skipped. - One owner. Constructing observes nothing, hooks and services subscribe passively, and only the application starts and disposes.
Not a background task runner, a scheduler, a guaranteed exit hook, a session or presence tracker, an analytics engagement timer, or a security signal. A foreground event is not permission to run, a background event does not mean JavaScript keeps running, and observedAway is an estimate, never a timeout you can trust for authorization.
| Package | What it is |
|---|---|
@priemskiyyy/pulse |
The runtime, the browser and React Native adapters, and the test helpers |
@priemskiyyy/pulse-react |
A provider and hooks, with server rendering |
@priemskiyyy/pulse-solid |
A provider and primitives |
@priemskiyyy/pulse-vue |
A provider and composables |
@priemskiyyy/pulse-svelte |
A provider and utilities |
Every package is ESM only, side-effect free and typed. The core has no dependencies.
- The package readme: installation, the API and the entry points.
- Documentation: states and transitions, the adapters, React, testing and verification.
pnpm dev:docsserves it locally. - Live lifecycle lab: inspect this browser's signals alongside Pulse's state and transitions.
- The browser lab and the Expo lab: Pulse next to the raw host signals, for exercising a real browser or device.
0.1.0 is the first stable release.
The automated checks cover the runtime, adapter mappings, React integration,
package installation, browser labs and native bundles. Physical iOS and Android
devices, real browser tab/focus changes, freeze/discard and back/forward-cache
restoration still need platform verification. See the
verification matrix for the
evidence and the remaining exercises.
pnpm install --frozen-lockfile
pnpm check
pnpm check:releaseSee CONTRIBUTING.md, SUPPORT.md and RELEASING.md.