1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2025-07-01 04:12:14 +02:00

💥 rename signals to observables

This commit is contained in:
2023-11-24 20:41:04 +01:00
parent fc4037f3eb
commit 58b73dcbc7
44 changed files with 372 additions and 333 deletions

27
dist/dde-with-observables.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4
dist/dde.js vendored

File diff suppressed because one or more lines are too long

View File

@ -153,10 +153,10 @@ export const scope: {
preventDefault<T extends boolean>(prevent: T): T,
/**
* This represents reference to the current host element `scope.host()`.
* It can be also used to register Addon (function to be called when component is initized)
* It can be also used to register Addon(s) (functions to be called when component is initized)
* `scope.host(on.connected(console.log))`.
* */
host: ddeElementAddon<any>,
host: (...addons: ddeElementAddon<any>[])=> HTMLElement,
state: Scope[],
/** Adds new child scope. All attributes are inherited by default. */
@ -444,19 +444,19 @@ declare global{
interface ddeSVGUseElement extends SVGUseElement{ append: ddeAppend<ddeSVGUseElement>; }
interface ddeSVGViewElement extends SVGViewElement{ append: ddeAppend<ddeSVGViewElement>; }
}
export type Signal<V, A>= (set?: V)=> V & A;
type Action<V>= (this: { value: V }, ...a: any[])=> typeof S._ | void;
export type Observable<V, A>= (set?: V)=> V & A;
type Action<V>= (this: { value: V }, ...a: any[])=> typeof observable._ | void;
type SymbolOnclear= Symbol;
type SymbolSignal= Symbol;
type SymbolObservable= Symbol;
type Actions<V>= Record<string, Action<V>>;
interface S {
interface observable{
_: Symbol
/**
* Simple example:
* ```js
* const hello= S("Hello Signal");
* const hello= S("Hello Observable");
* ```
* simple todo signal:
* simple todo observable:
* ```js
* const todos= S([], {
* add(v){ this.value.push(S(v)); },
@ -464,46 +464,47 @@ interface S {
* [S.symbols.onclear](){ S.clear(...this.value); },
* });
* ```
* computed signal:
* computed observable:
* ```js
* const name= S("Jan");
* const surname= S("Andrle");
* const fullname= S(()=> name()+" "+surname());
* ```
* @param value Initial signal value. Or function computing value from other signals.
* @param actions Use to define actions on the signal. Such as add item to the array.
* There is also a reserved function `S.symbol.onclear` which is called when the signal is cleared
* @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`.
* */
<V, A extends Actions<V>>(value: V, actions?: A): Signal<V, A>;
<V, A extends Actions<V>>(value: V, actions?: A): Observable<V, A>;
/**
* Computations signal. This creates a signal which is computed from other signals.
* Computations observable. This creates a observable which is computed from other observables.
* */
<V>(computation: ()=> V): Signal<V, {}>
action<S extends Signal<any, Actions<any>>, A extends (S extends Signal<any, infer A> ? A : never), N extends keyof A>(
signal: S,
<V>(computation: ()=> V): Observable<V, {}>
action<S extends Observable<any, Actions<any>>, A extends (S extends Observable<any, infer A> ? A : never), N extends keyof A>(
observable: S,
name: N,
...params: A[N] extends (...args: infer P)=> any ? P : never
): void;
clear(...signals: Signal<any, any>[]): void;
on<T>(signal: Signal<T, any>, onchange: (a: T)=> void, options?: AddEventListenerOptions): void;
clear(...observables: Observable<any, any>[]): void;
on<T>(observable: Observable<T, any>, onchange: (a: T)=> void, options?: AddEventListenerOptions): void;
symbols: {
signal: SymbolSignal;
observable: SymbolObservable;
onclear: SymbolOnclear;
}
/**
* Reactive element, which is rendered based on the given signal.
* Reactive element, which is rendered based on the given observable.
* ```js
* S.el(signal, value=> value ? el("b", "True") : el("i", "False"));
* S.el(observable, value=> value ? el("b", "True") : el("i", "False"));
* S.el(listS, list=> list.map(li=> el("li", li)));
* ```
* */
el<S extends any>(signal: Signal<S, any>, el: (v: S)=> Element | Element[]): DocumentFragment;
el<S extends any>(observable: Observable<S, any>, el: (v: S)=> Element | Element[]): DocumentFragment;
attribute(name: string, initial?: string): Signal<string, {}>;
attribute(name: string, initial?: string): Observable<string, {}>;
}
export const S: S;
export const observable: observable;
export const O: observable;
declare global {
type ddeSignal<T, A= {}>= Signal<T, A>;
type ddeObservable<T, A= {}>= Observable<T, A>;
type ddeActions<V>= Actions<V>
}

4
dist/esm-with-observables.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4
dist/esm.d.ts vendored
View File

@ -153,10 +153,10 @@ export const scope: {
preventDefault<T extends boolean>(prevent: T): T,
/**
* This represents reference to the current host element — `scope.host()`.
* It can be also used to register Addon (function to be called when component is initized)
* It can be also used to register Addon(s) (functions to be called when component is initized)
* — `scope.host(on.connected(console.log))`.
* */
host: ddeElementAddon<any>,
host: (...addons: ddeElementAddon<any>[])=> HTMLElement,
state: Scope[],
/** Adds new child scope. All attributes are inherited by default. */

2
dist/esm.js vendored

File diff suppressed because one or more lines are too long