vasille-jsx
Version:
The same framework which is designed to build bulletproof frontends (JSX components)
40 lines (39 loc) • 1.78 kB
TypeScript
import { IValue, Reactive, KindOfIValue, Expression, SetModel, MapModel, ArrayModel } from "vasille";
export declare function expr<T, Args extends unknown[]>(ctx: Reactive | undefined, func: (...args: Args) => T, values: KindOfIValue<Args>): Expression<T, Args>;
/**
* It transforms a non-reactive value to a reactive one.
* 1. `let a = 0` to `const a = ref(0)`
*/
export declare function ref<T>(v: T): IValue<T>;
/**
* create a `Set` model
* 1. translate `new Set(#)` to `set(ctx, #)`
*/
export declare function setModel(ctx: Reactive | undefined, data?: unknown[]): SetModel<unknown>;
/**
* create a `Map` model
* 1. `new Map(#)` to `mapModel(ctx, #)`
*/
export declare function mapModel(ctx: Reactive | undefined, data?: [unknown, unknown][]): MapModel<unknown, unknown>;
/**
* create an `Array` model
* 1. `[...]` to `arrayModel(ctx, [...])`
*/
export declare function arrayModel(ctx: Reactive | undefined, data?: unknown[] | number): ArrayModel<unknown>;
/**
* Use when a value must be IValue but can be undefined
* 1. `let a = obj.$key` to `const a = ensure(obj.$key)`
*/
export declare function ensure<T extends object>(obj: T | null | undefined, key: keyof T): IValue<undefined> | T[keyof T];
/**
* Used for destruction with computed values
* 1. `{[a]: a1} = {x: 2}` to `{[a]: a1 = match("a1")} = {x: 2}`
* 1. `{[a]: a1 = 3} = {x: 2}` to `{[a]: a1 = match("a1", 3)} = {x: 2}`
*/
export declare function match(name: string | number | symbol, data?: unknown, createRef?: typeof ref): any;
/**
* Set a value of a field (alternative to proxies)
* 1. `obj.$key = 23` to `set(obj, "$key", 23)`
* 2. `arr[0] = 23` to `set(arr, 0, 23)`
*/
export declare function set(o: object, key: string | symbol | number, value: unknown, createRef?: typeof ref): unknown;