UNPKG

@stainless-code/persist

Version:

Hydration-aware persistence for any reactive store — zero-dep persistSource core; codecs, backends, cross-tab transport, source + framework hydration adapters ship as opt-in recipes

43 lines (42 loc) • 1.56 kB
import { t as HydrationSignal } from "../hydration-DclSpq51.mjs"; //#region src/adapters/frameworks/alpine.d.ts type AlpineLike = Pick<typeof import("alpinejs"), "reactive" | "magic">; /** Alpine-reactive bag returned by {@link useHydrated}. */ interface HydratedBag { hydrated: boolean; /** Unsubscribe from the hydration signal. No-op when there is no signal. */ destroy(): void; } /** * Mount a `HydrationSignal` into Alpine reactivity — reactive `{ hydrated }` * for `x-show` / `x-text`. Call after `Alpine.plugin(persist)`. Null signal → * `{ hydrated: true }`. Tear down with `bag.destroy()` from `Alpine.data`. * Template `$hydrated(signal)` caches per element and cleans up on remove. * * @example * ```ts * import persist, { useHydrated } from "@stainless-code/persist/frameworks/alpine"; * Alpine.plugin(persist); * Alpine.data("prefs", () => { * const hydration = useHydrated(prefsHydration); * return { * get hydrated() { return hydration.hydrated; }, * destroy() { hydration.destroy(); }, * }; * }); * ``` */ declare function useHydrated(signal: HydrationSignal | null | undefined): HydratedBag; /** * Alpine plugin — stores the runtime for `Alpine.reactive` and registers * `$hydrated` (`(signal) => useHydrated(signal)`). * * @example * ```ts * import persist from "@stainless-code/persist/frameworks/alpine"; * Alpine.plugin(persist); * ``` */ declare function persist(Alpine: AlpineLike): void; //#endregion export { AlpineLike, HydratedBag, persist as default, persist, useHydrated };