1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-22 07:49:38 +01:00

Add ddeSignal type to global scope + TODOs updated

This commit is contained in:
Jan Andrle 2023-09-07 18:21:51 +02:00
parent 6fae2fc4e6
commit 9b77d65279
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
5 changed files with 7 additions and 6 deletions

1
index.d.ts vendored
View File

@ -2,7 +2,6 @@ import { Signal } from "./src/signals";
//TODO? //TODO?
declare global { declare global {
type ddeFires<T extends string[]>= ( (...a: any[])=> any ) & { events: T }; type ddeFires<T extends string[]>= ( (...a: any[])=> any ) & { events: T };
type ddeSignal<T, A>= Signal<T, A>;
} }
type ElementTagNameMap= HTMLElementTagNameMap & SVGElementTagNameMap & { type ElementTagNameMap= HTMLElementTagNameMap & SVGElementTagNameMap & {
'#text': Text '#text': Text

View File

@ -1,6 +1,6 @@
{ {
"name": "deka-dom-el", "name": "deka-dom-el",
"version": "0.1.2", "version": "0.1.3",
"description": "A low-code library that simplifies the creation of native DOM elements/components using small wrappers and tweaks.", "description": "A low-code library that simplifies the creation of native DOM elements/components using small wrappers and tweaks.",
"author": "Jan Andrle <andrle.jan@centrum.cz>", "author": "Jan Andrle <andrle.jan@centrum.cz>",
"license": "MIT", "license": "MIT",

View File

@ -12,7 +12,7 @@ export function S(value, actions){
const out= create(); const out= create();
watch(()=> out(value())); watch(()=> out(value()));
return out; return out;
//TODO is auto remove if used for args, if external listener needs also S.clear //TODO for docs: is auto remove if used for args, if external listener needs also S.clear
} }
S.action= function(signal, name, ...a){ S.action= function(signal, name, ...a){
const s= signal[mark], { actions }= s; const s= signal[mark], { actions }= s;
@ -28,7 +28,7 @@ S.on= function on(signals, listener, options= {}){
if(Array.isArray(signals)) return signals.forEach(s=> on(s, listener, options)); if(Array.isArray(signals)) return signals.forEach(s=> on(s, listener, options));
addSignalListener(signals, listener); addSignalListener(signals, listener);
if(as) as.addEventListener("abort", ()=> removeSignalListener(signals, listener)); if(as) as.addEventListener("abort", ()=> removeSignalListener(signals, listener));
//TODO cleanup when signal removed (also TODO) //TODO cleanup when signal removed
}; };
S.symbols= { S.symbols= {
signal: mark, signal: mark,

4
src/signals.d.ts vendored
View File

@ -43,3 +43,7 @@ interface S {
} }
} }
export const S: S; export const S: S;
declare global {
type ddeSignal<T, A>= Signal<T, A>;
type ddeActions<V>= Actions<V>
}

View File

@ -14,9 +14,7 @@ const className= style.host(todosComponent).css`
/** @param {{ todos: string[] }} */ /** @param {{ todos: string[] }} */
export function todosComponent({ todos= [ "A" ] }= {}){ export function todosComponent({ todos= [ "A" ] }= {}){
const todosS= S([], { const todosS= S([], {
/** @param {string} v */
add(v){ this.value.push(S(v)); }, add(v){ this.value.push(S(v)); },
/** @param {number} i */
remove(i){ this.value.splice(i, 1); }, remove(i){ this.value.splice(i, 1); },
[S.symbols.onclear](){ S.clear(...this.value); }, [S.symbols.onclear](){ S.clear(...this.value); },
}); });