rvx
Version:
A signal based rendering library
79 lines • 2.76 kB
TypeScript
/**
* A context for implicitly passing values along the call stack.
*
* If you need a global default value, use {@link DefaultContext} instead.
*/
export declare class Context<T> {
#private;
/**
* @param defaultValue The default value. This is used if the {@link current} value is `null` or `undefined`.
*/
constructor(defaultValue: T);
constructor(...defaultValue: T extends undefined ? [] : [T]);
/**
* Get or set the default value.
*
* This is used if the {@link current} value is `null` or `undefined`.
*/
default: T;
/**
* Get the current value for this context.
*/
get current(): T;
/**
* Run a function while providing the specified value for this context.
*
* See {@link Provide `<Provide>`} when using JSX.
*
* @param value The value to provide.
* @param fn The function to run.
* @param args The function arguments.
* @returns The function's return value.
*/
provide<F extends (...args: any) => any>(value: T | null | undefined, fn: F, ...args: Parameters<F>): ReturnType<F>;
/**
* Shorthand for creating a context-value pair for this context.
*/
with(value: T | null | undefined): ContextState<T>;
/**
* Run a function in a new context window (ignoring all current contexts) while providing the specified states.
*
* @param states The states to provide.
* @param fn The function to run.
* @param args The function arguments.
* @returns The function's return value.
*/
static isolate<F extends (...args: any) => any>(states: ContextState<unknown>[], fn: F, ...args: Parameters<F>): ReturnType<F>;
/**
* Run a function while providing the specified states.
*
* See {@link Provide `<Provide>`} when using JSX.
*
* @param states The states to provide. When providing multiple values for the same context, the last one is used.
* @param fn The function to run.
* @param args The function arguments.
* @returns The function's return value.
*/
static provide<F extends (...args: any) => any>(states: ContextState<unknown>[], fn: F, ...args: Parameters<F>): ReturnType<F>;
/**
* Capture all current context states.
*/
static capture(): ContextState<unknown>[];
/**
* Bind a function to the current context.
*
* @param fn The function to bind.
* @returns The bound function.
*/
static bind<T extends (...args: any) => any>(fn: T): T;
}
/**
* A context-value pair.
*
* Fields are considered internal and not subject to semantic versioning.
*/
export interface ContextState<T> {
c: Context<T>;
v: T | null | undefined;
}
//# sourceMappingURL=context.d.ts.map