export type Observable= (set?: V)=> V & A; type Action= (this: { value: V, stopPropagation(): void }, ...a: any[])=> typeof observable._ | void; //type SymbolObservable= Symbol; type SymbolOnclear= symbol; type Actions= Record>; interface observable{ _: Symbol /** * Simple example: * ```js * const hello= S("Hello Observable"); * ``` * …simple todo observable: * ```js * const todos= S([], { * add(v){ this.value.push(S(v)); }, * remove(i){ this.value.splice(i, 1); }, * [S.symbols.onclear](){ S.clear(...this.value); }, * }); * ``` * …computed observable: * ```js * const name= S("Jan"); * const surname= S("Andrle"); * const fullname= S(()=> name()+" "+surname()); * ``` * @param value Initial observable value. Or function computing value from other observables. * @param actions Use to define actions on the observable. Such as add item to the array. * There is also a reserved function `S.symbol.onclear` which is called when the observable is cleared * by `S.clear`. * */ >(value: V, actions?: A): Observable; /** * Computations observable. This creates a observable which is computed from other observables. * */ (computation: ()=> V): Observable action>, A extends (S extends Observable ? A : never), N extends keyof A>( observable: S, name: N, ...params: A[N] extends (...args: infer P)=> any ? P : never ): void; clear(...observables: Observable[]): void; on(observable: Observable, onchange: (a: T)=> void, options?: AddEventListenerOptions): void; symbols: { //observable: SymbolObservable; onclear: SymbolOnclear; } /** * Reactive element, which is rendered based on the given observable. * ```js * S.el(observable, value=> value ? el("b", "True") : el("i", "False")); * S.el(listS, list=> list.map(li=> el("li", li))); * ``` * */ el(observable: Observable, el: (v: S)=> Element | Element[] | DocumentFragment): DocumentFragment; attribute(name: string, initial?: string): Observable; } export const observable: observable; export const O: observable; declare global { type ddeObservable= Observable; type ddeAction= Action type ddeActions= Actions }