type CleanupFn = () => void; type MountFn = (() => CleanupFn | undefined | void) | (() => Promise); /** * Runs `fn` once after the component's DOM is attached and ready * (fires on the internal `DOMReadyEvent`). * * Accepts both sync and async functions. * * **Sync behaviour:** * `fn` runs after the component's DOM is ready. If `fn` returns a function, * that function is registered as a cleanup and called when the component unmounts. * * **Async behaviour — client:** * `fn` is called after `DOMReadyEvent` fires (same timing as sync). * State updates inside `fn` trigger reactive re-renders normally. * Cleanup return values are not supported for async functions (a `Promise` * is returned, not a `CleanupFn`). * * **Async behaviour — SSR:** * `DOMReadyEvent` is a no-op on the server's fake host, so async functions * would otherwise never run. Instead, when `isSSR()` is `true`, async functions * are pushed onto `host._asyncMountQueue`. The renderer drains this queue * (`await Promise.all`) **before** calling the template function, so by the * time the HTML is serialized the state is already populated. * Sync functions are silently ignored on the server (same as before — * `DOMReadyEvent.__subscribe` is a no-op on the fake host). * * Must be called in the component outer function (guarded by `safetyCheck`). * * @example * // Sync — return a cleanup function to run on unmount: * onMount(() => { * console.log("component mounted"); * return () => console.log("component unmounted"); * }); * * // Async — no cleanup return value supported: * onMount(async () => { * const data = await fetch("/api/init").then(r => r.json()); * myAtom.set(data); * }); */ export declare const onMount: (fn: MountFn) => void; /** * Runs `fn` after each paint of the current component and all its children, * during both the initial mount and every subsequent update cycle. * * If `fn` returns a function, that function is registered as a cleanup and * called before the next paint or when the component unmounts. * * Must be called in the component outer function (guarded by `safetyCheck`). * * @example * onPaint(() => { * console.log("painted"); * return () => console.log("paint cleanup"); * }); */ export declare const onPaint: (fn: () => CleanupFn | undefined) => void; /** * Runs `fn` once, after the current component **and all its children** have * mounted, before the next paint. * * Uses `globalScheduler.onceIdle` — `fn` fires when the scheduler becomes idle, * guaranteeing that the entire component subtree is fully mounted. * * If `fn` returns a function, that function is registered as a cleanup and * called when the component unmounts. * * Must be called in the component outer function (guarded by `safetyCheck`). * * @example * onAllMount(() => { * console.log("current component and all children are mounted"); * }); */ export declare const onAllMount: (fn: () => CleanupFn | undefined) => void; /** * Registers `fn` to run when the component is unmounted (removed from the DOM). * * Equivalent to returning a cleanup function from `onMount`, but can be called * independently at any point in the component outer function. * * Must be called in the component outer function (guarded by `safetyCheck`). * * @example * onCleanup(() => { * console.log("component unmounted — cleaning up"); * subscription.unsubscribe(); * }); */ export declare const onCleanup: (fn: () => void) => void; export {}; //# sourceMappingURL=lifecycle.d.ts.map