@web-atoms/core
Version:
127 lines • 5.53 kB
TypeScript
import type { App } from "../App";
import { IValueConverter } from "./IValueConverter";
import { CancelToken } from "./types";
export interface IAtomComponent {
element: any;
viewModel: any;
localViewModel: any;
data: any;
app: App;
runAfterInit(f: () => void): void;
setLocalValue(e: any, name: string, value: any): void;
bindEvent(e: any, name: string, handler: any): any;
bind(e: any, name: string, path: any, twoWays: boolean, converter: any, source?: any): any;
}
/**
* Bindings needs to be cloned...
*/
export type bindingFunction<T extends IAtomComponent = IAtomComponent> = (control: T, e?: any) => any;
export type asyncBindingFunction<TR, T extends IAtomComponent = IAtomComponent> = (control: T, e: any, cancelToken: CancelToken) => Promise<TR>;
export type bindingFunctionCommand<T extends IAtomComponent = IAtomComponent> = (control: T, e?: any) => (p: any) => void;
export interface IData<T> extends IAtomComponent {
data: T;
}
export interface IVM<T> extends IAtomComponent {
viewModel: T;
}
export interface ILVM<T> extends IAtomComponent {
localViewModel: T;
}
export interface IBinder<T extends IAtomComponent> {
presenter(name?: string): Bind;
event(handler: (control: T, e?: CustomEvent) => void): any;
/**
* Bind the expression one time
* @param path Lambda Expression for binding
* @param now Default value to set immediately
*/
oneTime(path: bindingFunction<T>, now?: any): Bind;
/**
* Bind the expression one way
* @param path Lambda Expression for binding
* @param now Default value to set immediately
*/
oneWay(path: bindingFunction<T>, now?: any): Bind;
/**
* Setup two way binding with given expression
* @param path Lambda Expression for binding
* @param events events on auto refresh
*/
twoWays(path: bindingFunction<T>, events?: string[]): Bind;
}
export declare const bindSymbol: unique symbol;
export default class Bind {
readonly setupFunction: ((name: string, b: Bind, c: IAtomComponent, e: any, self?: any) => void);
readonly name?: string;
readonly eventList?: string[];
static forControl<C extends IAtomComponent>(): IBinder<C>;
static forData<D>(): IBinder<IData<D>>;
static forViewModel<D>(): IBinder<IVM<D>>;
static forLocalViewModel<D>(): IBinder<ILVM<D>>;
static presenter(name?: string | ((c: any) => any)): any;
static event<T extends IAtomComponent = IAtomComponent>(sourcePath: (control: T, e?: CustomEvent) => void): any;
/**
* Bind the expression one time
* @param sourcePath Lambda Expression for binding
* @param now Default value to set immediately
*/
static oneTime<T extends IAtomComponent = IAtomComponent>(sourcePath: bindingFunction<T>, now?: any): any;
/**
* Bind the expression one time
* @param sourcePath Lambda Expression for binding
* @param now Default value to set immediately
*/
static oneTimeAsync<TR, T extends IAtomComponent = IAtomComponent>(sourcePath: asyncBindingFunction<TR, T>, now?: any): Promise<TR>;
/**
* Bind the expression one way with source, you cannot reference
* `this` inside this context, it will not watch `this`
* @param source source to watch
* @param path Lambda Expression for binding
* @param now Default value to set immediately
*/
static source<T>(source: T, path: (x: {
control: IAtomComponent;
source: T;
}) => any, now?: any): any;
static oneWayAsync<TR, T extends IAtomComponent = IAtomComponent>(sourcePath: asyncBindingFunction<TR, T>, { watchDelayInMS, default: defaultValue }?: {
watchDelayInMS?: number;
default?: any;
}): Promise<TR>;
/**
* Bind the expression one way
* @param sourcePath Lambda Expression for binding
* @param now Default value to set immediately
*/
static oneWay<T extends IAtomComponent = IAtomComponent>(sourcePath: bindingFunction<T>, now?: any): any;
/**
* Setup two way binding with given expression
* @param sourcePath Lambda Expression for binding
* @param events events on auto refresh
* @param converter IValueConverter for value conversion
*/
static twoWays<T extends IAtomComponent = IAtomComponent>(sourcePath: bindingFunction<T>, events?: string[], converter?: IValueConverter): any;
/**
* Bind the expression one way with source, you cannot reference
* `this` inside this context, it will not watch `this`
* @param source source to watch
* @param path Lambda Expression for binding
* @param now Default value to set immediately
*/
static sourceTwoWays<T>(source: T, path: (x: {
control: IAtomComponent;
source: T;
}) => any, events?: string[]): any;
/**
* Use this for HTML only, this will fire two way binding
* as soon as the input/textarea box is updated
* @param sourcePath binding lambda expression
* @param converter Optional value converter
*/
static twoWaysImmediate<T extends IAtomComponent = IAtomComponent>(sourcePath: bindingFunction<T>, converter?: IValueConverter): any;
readonly sourcePath: bindingFunction;
readonly pathList: string[][];
readonly thisPathList: string[][];
readonly combined: string[][];
constructor(setupFunction: ((name: string, b: Bind, c: IAtomComponent, e: any, self?: any) => void), sourcePath: bindingFunction, name?: string, eventList?: string[]);
}
//# sourceMappingURL=Bind.d.ts.map