UNPKG

rvx

Version:

A signal based rendering library

71 lines (70 loc) 2.12 kB
/** * An object that is used to convert between reactive wrappers and their targets. */ export interface Barrier { /** * Get a reactive wrapper for the specified value. * * This should always return the same wrapper for the same value. * * @param value The target. * @returns The wrapper or the value itself if it was already wrapped. */ wrap<T>(value: T): T; /** * Get the target for the specified reactive wrapper. * * This should always return the same target for the same value. * * @param value The wrapper or a non-wrapped value. * @returns The target or the value itself if it was already unwrapped. */ unwrap<T>(value: T): T; } export interface WrapInstanceFn<T> { (instance: T): T; } /** * The default barrier using {@link wrap} and {@link unwrap}. */ export declare const BARRIER: Barrier; /** * Get a deep reactive wrapper for the specified value. * * This always returns the same wrapper for the same value. * * @param value The value to wrap. * @returns The wrapper or the value itself if it was already wrapped. */ export declare function wrap<T>(value: T): T; /** * Get the target for a reactive wrapper. * * This always returns the same target for the same value. * * @param value The value to unwrap. * @returns The target or the value itself if it was already unwrapped. */ export declare function unwrap<T>(value: T): T; /** * Allow instances of the specified target class to be wrapped. * * @param targetClass The target class. * @param wrap A function to wrap an instance. By default `createReactiveProxy` is used with `wrap` and `unwrap` for inner values. * * @example * ```tsx * class Example { * static { * // Using the default "createReactiveProxy": * wrapInstancesOf(this); * * // Or a custom wrapper: * wrapInstancesOf(this, instance => { * return createSomeWrapperFor(instance); * }); * } * } * ``` */ export declare function wrapInstancesOf<T extends object>(targetClass: new (...args: any) => T, wrap?: (instance: T) => T): void;