import { ObservableMaybe, ObservableReadonly } from 'woby'; /** * @template TInput The type of the object or array being destructured. * @typedef {Object | Array} DestructuredResult * @property {ObservableReadonly} [K] - Each property/element is wrapped in an ObservableReadonly. */ type DestructuredResult = { [K in keyof TInput]: ObservableReadonly; }; /** * `useDestruct` is a custom hook that allows you to destructure properties from an object or elements from an array. * Regardless of whether the source `o` is a plain value or an `Observable`, all destructured properties/elements * will be returned as `ObservableReadonly` instances. This ensures that changes to the original source (if it's an Observable) * or changes to the destructured properties themselves (if they were originally Observables) will trigger updates. * * If no keys are provided, it will destructure all enumerable properties of an object or all elements of an array (avoid large array). * * @template TInput The type of the input object or array, which can be a plain value or an `Observable`. * @param {Observable | TInput} o The object or array to destructure, or an `Observable` containing it. * @param {...(keyof TInput)[]} keys Optional. The specific keys (for objects) or indices (for arrays) to destructure. * If not provided, all properties/elements will be destructured. * @returns {DestructuredResult} An object or array containing the destructured properties or elements, * each wrapped in an `ObservableReadonly`. * * @example * // Destructuring from a plain object * const { name, age } = useDestruct({ name: 'Alice', age: 30 }, 'name', 'age'); * // name is ObservableReadonly, age is ObservableReadonly * // Access values: name(), age() * * @example * // Destructuring from an Observable object * const user = $<{ name: string, age: number }>({ name: 'Bob', age: 25 }); * const { name: nameObs, age: ageObs } = useDestruct(user, 'name', 'age'); * // nameObs is ObservableReadonly, ageObs is ObservableReadonly * // Access values: nameObs(), ageObs() * * @example * // Destructuring all properties from an Observable object * const settings = $<{ theme: string, notifications: boolean }>({ theme: 'dark', notifications: true }); * const { theme, notifications } = useDestruct(settings); * // theme is ObservableReadonly, notifications is ObservableReadonly * * @example * // Destructuring from a plain array * const [first, second] = useDestruct(['apple', 'banana', 'cherry'], 0, 1); * // first is ObservableReadonly, second is ObservableReadonly * * @example * // Destructuring from an Observable array * const items = $(['item1', 'item2']); * const [item1Obs, item2Obs] = useDestruct(items, 0, 1); * // item1Obs is ObservableReadonly, item2Obs is ObservableReadonly * * @example * // Handling properties that are already Observables within an Observable object * const complexState = $<{ counter: Observable, status: string }>({ counter: $(0), status: 'active' }); * const { counter, status } = useDestruct(complexState); * // counter is ObservableReadonly> (the original observable is wrapped in a new ObservableReadonly) * // status is ObservableReadonly */ export declare const useDestruct: (o: ObservableMaybe | TInput, ...keys: (keyof TInput)[]) => DestructuredResult; export {}; //# sourceMappingURL=useDestruct.d.ts.map