Skip to content

Commit

Permalink
feat(hdom): update setAttrib()
Browse files Browse the repository at this point in the history
- add IDeref support for individual attrib values (i.e. via `deref()` wrappers)
- update attribute removal/deletion logic
  • Loading branch information
postspectacular committed Feb 25, 2023
1 parent a6c0b36 commit 61aa627
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/hdom/src/dom.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { implementsFunction } from "@thi.ng/checks/implements-function";
import { isArray as isa } from "@thi.ng/checks/is-array";
import { isNotStringAndIterable as isi } from "@thi.ng/checks/is-not-string-iterable";
import { isString as iss } from "@thi.ng/checks/is-string";
Expand Down Expand Up @@ -217,6 +218,7 @@ export const setAttribs = (el: Element, attribs: any) => {
* @param attribs - object of all attribs
*/
export const setAttrib = (el: Element, id: string, val: any, attribs?: any) => {
implementsFunction(val, "deref") && (val = val.deref());
if (id.startsWith("__")) return;
const isListener = id[0] === "o" && id[1] === "n";
if (!isListener && typeof val === "function") {
Expand Down Expand Up @@ -263,7 +265,9 @@ export const setAttrib = (el: Element, id: string, val: any, attribs?: any) => {
: el.setAttribute(id, val === true ? "" : val);
}
} else {
(<any>el)[id] != null ? ((<any>el)[id] = null) : el.removeAttribute(id);
el.hasAttribute(id)
? el.removeAttribute("title")
: (<any>el)[id] && ((<any>el)[id] = null);
}
return el;
};
Expand Down

0 comments on commit 61aa627

Please sign in to comment.