/// import { ReadonlySignal, Signal } from "@preact-signals/unified-signals"; import { Accessor } from "./utils"; declare const enum UncachedField { Accessor = "_a", Setter = "_s" } /** * ReactiveRef class extends Signal class and allows to use it in JSX. * Usually you don't need to use it directly, use `$` function instead. */ declare class ReactiveRef extends Signal { constructor(accessor: Accessor); get value(): T; peek(): T; valueOf(): T; toString(): string; /** @internal */ [UncachedField.Accessor](): T; } /** * WritableReactiveRef class extends ReactiveRef class and allows to use it in JSX. * Usually you don't need to use it directly, use `$w` function instead. */ declare class WritableReactiveRef extends ReactiveRef { set value(value: T); constructor(get: () => T, set: (value: T) => void); /** @internal */ [UncachedField.Setter](value: T): void; } interface WritableReactiveRef extends JSX.Element { } interface ReactiveRef extends JSX.Element { } declare function ReactiveRef(this: ReactiveRef, accessor: Accessor): void; declare namespace ReactiveRef { var prototype: ReactiveRef; } export type WritableRefOptions = { get(): T; set(value: T): void; }; declare function WritableReactiveRef(this: WritableReactiveRef, get: () => T, set: (value: T) => void): void; declare namespace WritableReactiveRef { var prototype: WritableReactiveRef; } /** * ReactiveRef is just accessor function in object wrapper, that allows to use it in JSX * and use `instanceof` to check if it is ReactiveRef. Main difference with Signal is that you shouldn't care about using hooks for it creation. * @example * ```tsx * const sig = signal(1); * *
{$(() => sig.value * 10)}
* ``` * * Using with component wrapped in `withSignalProps` * ```tsx * const C = withSignalProps((props: { a: number }) => { * return
{props.a}
; * }); * * const sig = signal(1); * * sig.value)} /> * ``` */ export declare const $: (accessor: Accessor) => ReactiveRef; /** * @description `WritableReactiveRef` is accessor and setter function in object wrapper, that allows to use it in JSX. * @example * ```tsx * const sig = signal({ * a: [1,2,3] * }); * * const ref = $w({ * get: () => sig.value["a"][0], * set: (value) => sig.value = { ...sig.value, a: [value, ...sig.value["a"].slice(1)] } * }); * *
ref.value++}>{ref}
* ``` * * `WritableReactiveRef` is also handy with deep reactivity tracking system * ```tsx * const sig = deepSignal({ * a: [1,2,3] * }); * * // more efficient because it doesn't recreate object on each change * const ref = $w({ * get: () => sig.value["a"][0], * set: (value) => sig.value["a"][0] = value * }); * ``` * * `WritableReactiveRef` can be used as prop with component wrapped in `withSignalProps` * ```tsx * const C = withSignalProps((props: { a: number }) => { * return
{props.a}
; * }); * * const sig = signal(1); * const ref = $w({ * get: () => sig.value, * set(value) { * sig.value = value; * }, * }) * * * ``` */ export declare const $w: (options: WritableRefOptions) => WritableReactiveRef; export declare const signalOf$: ($value: ReactiveRef) => ReadonlySignal; export { /** * @deprecated use `ReactiveRef` */ ReactiveRef as Uncached, /** * @deprecated use `WritableReactiveRef` */ WritableReactiveRef as WritableUncached, ReactiveRef, WritableReactiveRef, };