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

🔨 mainly types + 💥 ddePublicElementTagNameMap

This commit is contained in:
2023-11-08 18:53:22 +01:00
parent 14fe70e8f6
commit 5c038f0427
12 changed files with 195 additions and 54 deletions

View File

@ -67,7 +67,9 @@ import { scope } from "./dom.js";
const key_attributes= "__dde_attributes";
S.attribute= function(name, initial= undefined){
const out= S(initial);
let host;
scope.host(element=> {
host= element;
if(element instanceof HTMLElement){
if(element.hasAttribute(name)) out(element.getAttribute(name));
} else {
@ -83,16 +85,26 @@ S.attribute= function(name, initial= undefined){
* Investigate `__dde_attributes` key of the element.*/
const [ name, value ]= detail;
const curr= element[key_attributes][name];
if(curr) curr(value);
if(curr) return curr(value);
})(element);
on.disconnected(function(){
/*! This removes all signals mapped to attributes (`S.attribute`).
* Investigate `__dde_attributes` key of the element.*/
S.clear(...Object.values(element[key_attributes]));
host= null;
})(element);
return element;
});
return out;
return new Proxy(out, {
apply(target, _, args){
if(!args.length) return target();
if(!host) return;
const value= args[0];
if(host instanceof HTMLElement)
return host.setAttribute(name, value);
return host.setAttributeNS(null, name, value);
}
});
};
S.clear= function(...signals){
for(const signal of signals){