import { Focus } from '../types'; import { AsyncState, AsyncMode } from './types'; /** * Derive an async state from other async states using a synchronous computation. * The computation function uses `async.wait()` to extract data from async states, * which throws promises when states are pending. * * Key behaviors: * - If `computeFn` throws a promise (via `async.wait`), sets focus to pending and re-runs after promise settles * - If `computeFn` throws an error, sets focus to error state * - If `computeFn` returns a value, sets focus to success state * - If `computeFn` returns a promise (not throws), throws an error - must be synchronous * - Uses a single wrapper promise to avoid cascading re-renders * * @param focus - Focus to update with derived async state * @param computeFn - Synchronous computation function that uses `async.wait()` to read async states * @returns Dispose function to stop the derivation * * @example * // Basic usage - derive from multiple async states * async.derive(focus('c'), () => { * const a = async.wait(state.a); * const b = async.wait(state.b); * return a + b; * }); * * @example * // Conditional dependencies * async.derive(focus('result'), () => { * const type = async.wait(state.type); * if (type === 'user') { * return async.wait(state.userData); * } else { * return async.wait(state.guestData); * } * }); * * @example * // For parallel waiting, use async.all * async.derive(focus('combined'), () => { * const [a, b, c] = async.all([state.a, state.b, state.c]); * return { a, b, c }; * }); * * @example * // With stale mode - preserves data during loading/error * async.derive(focus('result'), () => { * return async.wait(state.userData); * }); */ export declare function derive(focus: Focus>, computeFn: () => T): VoidFunction; //# sourceMappingURL=derive.d.ts.map