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

href/src see #5 ♻️ renaming

This commit is contained in:
Jan Andrle 2023-09-08 15:54:47 +02:00
parent eb8aa93f06
commit f632be61cf
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
2 changed files with 10 additions and 7 deletions

View File

@ -50,7 +50,7 @@ export function assign(element, ...attributes){
case "style": return forEachEntries(attr, setRemove.bind(null, element.style, "Property"));
case "dataset": return forEachEntries(attr, setDelete.bind(null, element.dataset));
case "ariaset": return forEachEntries(attr, (key, val)=> setRemoveAttr("aria-"+key, val));
case "classList": return classListDeclartive(element, attr);
case "classList": return classListDeclarative(element, attr);
default: return Reflect.set(element, key, attr);
}
}
@ -59,6 +59,8 @@ export function assign(element, ...attributes){
return setRemoveAttr(key, attr);
}
switch(key){
case "href" || "src":
return setRemoveAttr(key, attr);
case "xlink:href":
return setRemoveAttr(key, attr, "http://www.w3.org/1999/xlink");
case "textContent" || "innerText":
@ -69,7 +71,7 @@ export function assign(element, ...attributes){
});
return element;
}
export function classListDeclartive(element, toggle){
export function classListDeclarative(element, toggle){
if(typeof toggle !== "object") return element;
forEachEntries(toggle,
@ -101,6 +103,7 @@ function getPropDescriptor(p, key, level= 0){
return [ des, level, p ];
}
/** @template {Record<any, any>} T @param {T} obj @param {(param: [ keyof T, T[keyof T] ])=> void} cb */
function forEachEntries(obj, cb){ return Object.entries(obj).forEach(([ key, val ])=> cb(key, val)); }
function isUndef(value){ return typeof value==="undefined"; }

View File

@ -7,19 +7,19 @@ export function on(event, listener, options){
};
}
const connections_changes= connectionsChangesObserverConstructor();
const c_ch_o= connectionsChangesObserverConstructor();
on.connected= function(listener, options){
return function registerElement(element){
connections_changes.onConnected(element, listener);
c_ch_o.onConnected(element, listener);
if(options && options.signal)
options.signal.addEventListener("abort", ()=> connections_changes.offConnected(element, listener));
options.signal.addEventListener("abort", ()=> c_ch_o.offConnected(element, listener));
};
};
on.disconnected= function(listener, options){
return function registerElement(element){
connections_changes.onDisconnected(element, listener);
c_ch_o.onDisconnected(element, listener);
if(options && options.signal)
options.signal.addEventListener("abort", ()=> connections_changes.offDisconnected(element, listener));
options.signal.addEventListener("abort", ()=> c_ch_o.offDisconnected(element, listener));
};
};