@jayoncode/browser-lifecycle-svelte
v0.1.1
Published
Svelte adapter for @jayoncode/browser-lifecycle — context helpers and reactive snapshots.
Downloads
27
Maintainers
Readme
Browser Lifecycle Svelte
Svelte adapter for @jayoncode/browser-lifecycle.
Thin wrappers only — no browser observation logic. Context helpers + readable snapshot store. Owned sessions dispose automatically via createBrowserLifecycleContext()'s onDestroy(); createOwnedBrowserLifecycle() requires calling .destroy() yourself; adopted sessions are never disposed. Start is guarded with typeof document !== "undefined" (SSR-safe).
Install
npm install @jayoncode/browser-lifecycle @jayoncode/browser-lifecycle-svelteUsage
<script>
import { createBrowserLifecycleContext } from "@jayoncode/browser-lifecycle-svelte";
const { snapshot, lifecycle } = createBrowserLifecycleContext();
</script>
<p>{$snapshot.visibility}</p>Or adopt an existing session: createBrowserLifecycleContext({ lifecycle }).
Options — { config?, lifecycle? }
createBrowserLifecycleContext() and createOwnedBrowserLifecycle() both accept config (forwarded to createBrowserLifecycle()) or lifecycle (an existing session to adopt). Adopted sessions are never started or disposed by the adapter.
Owned sessions are always created with autoStart: false internally, and the adapter guards its own start() call with typeof document !== "undefined" since component scripts also run during SvelteKit SSR.
See the full adapter guide for the complete API surface, dispose-rule differences between createBrowserLifecycleContext() and createOwnedBrowserLifecycle(), and more examples.
Docs
Core docs: Browser Lifecycle · Interactive demos: Playground
License
MIT © JayOnCode
