1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-21 23:39:37 +01:00

🐛 check for null when checking type of object (assign)

This commit is contained in:
Jan Andrle 2023-09-19 12:39:56 +02:00
parent 78fdb45ea7
commit ddfa3a2929
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
5 changed files with 73 additions and 73 deletions

View File

@ -52,7 +52,7 @@
let r = N(this), o; let r = N(this), o;
switch (r.isTextContent(t) && (t = { textContent: t }), !0) { switch (r.isTextContent(t) && (t = { textContent: t }), !0) {
case typeof e == "function": { case typeof e == "function": {
o = e(t || void 0, (i) => i ? (n.unshift(i), void 0) : o); o = e(t || void 0, (s) => s ? (n.unshift(s), void 0) : o);
break; break;
} }
case e === "#text": case e === "#text":
@ -75,39 +75,39 @@
if (!t.length) if (!t.length)
return e; return e;
let r = e instanceof SVGElement, o = (r ? I : T).bind(null, e, "Attribute"); let r = e instanceof SVGElement, o = (r ? I : T).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([i, s]) { return Object.entries(Object.assign({}, ...t)).forEach(function a([s, i]) {
s = n.processReactiveAttribute(e, i, s, a); i = n.processReactiveAttribute(e, s, i, a);
let [h] = i; let [h] = s;
if (h === "=") if (h === "=")
return o(i.slice(1), s); return o(s.slice(1), i);
if (h === ".") if (h === ".")
return M(e, i.slice(1), s); return M(e, s.slice(1), i);
if (typeof s == "object") if (typeof i == "object" && i !== null)
switch (i) { switch (s) {
case "style": case "style":
return O(s, T.bind(null, e.style, "Property")); return O(i, T.bind(null, e.style, "Property"));
case "dataset": case "dataset":
return O(s, M.bind(null, e.dataset)); return O(i, M.bind(null, e.dataset));
case "ariaset": case "ariaset":
return O(s, (E, v) => o("aria-" + E, v)); return O(i, (E, v) => o("aria-" + E, v));
case "classList": case "classList":
return J(e, s); return J(e, i);
default: default:
return Reflect.set(e, i, s); return Reflect.set(e, s, i);
} }
if (/(aria|data)([A-Z])/.test(i)) if (/(aria|data)([A-Z])/.test(s))
return i = i.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(i, s); return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(s, i);
switch (i) { switch (s) {
case "href": case "href":
return o(i, s); return o(s, i);
case "xlink:href": case "xlink:href":
return o(i, s, "http://www.w3.org/1999/xlink"); return o(s, i, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
if (!r) if (!r)
break; break;
return e.appendChild(document.createTextNode(s)); return e.appendChild(document.createTextNode(i));
} }
return W(e, i) ? q(e, i, s) : o(i, s); return W(e, s) ? q(e, s, i) : o(s, i);
}), e; }), e;
} }
function J(e, t) { function J(e, t) {
@ -126,8 +126,8 @@
let r = e.nodeName + "," + t; let r = e.nodeName + "," + t;
if (x.has(r)) if (x.has(r))
return x.get(r); return x.get(r);
let [o, a, i] = H(e, t), s = !m(o.set); let [o, a, s] = H(e, t), i = !m(o.set);
return (!s || a) && x.set(i === HTMLElement.prototype ? n : r, s), s; return (!i || a) && x.set(s === HTMLElement.prototype ? n : r, i), i;
} }
function H(e, t, n = 0) { function H(e, t, n = 0) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
@ -175,10 +175,10 @@
for (let f of c) for (let f of c)
if (f.type === "childList") { if (f.type === "childList") {
if (E(f.addedNodes, !0)) { if (E(f.addedNodes, !0)) {
i(); s();
continue; continue;
} }
v(f.removedNodes, !0) && i(); v(f.removedNodes, !0) && s();
} }
}); });
return { return {
@ -202,7 +202,7 @@
} }
}; };
function r(c, f) { function r(c, f) {
f.connected.length || f.disconnected.length || (e.delete(c), i()); f.connected.length || f.disconnected.length || (e.delete(c), s());
} }
function o(c) { function o(c) {
if (e.has(c)) if (e.has(c))
@ -213,16 +213,16 @@
function a() { function a() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
} }
function i() { function s() {
!t || e.size || (t = !1, n.disconnect()); !t || e.size || (t = !1, n.disconnect());
} }
function s() { function i() {
return new Promise(function(c) { return new Promise(function(c) {
(requestIdleCallback || requestAnimationFrame)(c); (requestIdleCallback || requestAnimationFrame)(c);
}); });
} }
async function h(c) { async function h(c) {
e.size > 30 && await s(); e.size > 30 && await i();
let f = []; let f = [];
if (!(c instanceof Node)) if (!(c instanceof Node))
return f; return f;
@ -314,15 +314,15 @@
g.el = function(e, t) { g.el = function(e, t) {
let n = document.createComment("<#reactive>"), r = document.createComment("</#reactive>"), o = document.createDocumentFragment(); let n = document.createComment("<#reactive>"), r = document.createComment("</#reactive>"), o = document.createDocumentFragment();
o.append(n, r); o.append(n, r);
let a = (i) => { let a = (s) => {
if (!n.parentNode || !r.parentNode) if (!n.parentNode || !r.parentNode)
return $(e, a); return $(e, a);
let s = t(i); let i = t(s);
Array.isArray(s) || (s = [s]); Array.isArray(i) || (i = [i]);
let h = n; let h = n;
for (; (h = n.nextSibling) !== r; ) for (; (h = n.nextSibling) !== r; )
h.remove(); h.remove();
n.after(...s); n.after(...i);
}; };
return P(e, a), a(e()), o; return P(e, a), a(e()), o;
}; };

2
dist/dde.js vendored
View File

@ -78,7 +78,7 @@
return c(s.slice(1), f); return c(s.slice(1), f);
if (h === ".") if (h === ".")
return y(e, s.slice(1), f); return y(e, s.slice(1), f);
if (typeof f == "object") if (typeof f == "object" && f !== null)
switch (s) { switch (s) {
case "style": case "style":
return m(f, N.bind(null, e.style, "Property")); return m(f, N.bind(null, e.style, "Property"));

View File

@ -50,7 +50,7 @@ function ie(e, t, ...n) {
let r = N(this), o; let r = N(this), o;
switch (r.isTextContent(t) && (t = { textContent: t }), !0) { switch (r.isTextContent(t) && (t = { textContent: t }), !0) {
case typeof e == "function": { case typeof e == "function": {
o = e(t || void 0, (i) => i ? (n.unshift(i), void 0) : o); o = e(t || void 0, (s) => s ? (n.unshift(s), void 0) : o);
break; break;
} }
case e === "#text": case e === "#text":
@ -73,39 +73,39 @@ function y(e, ...t) {
if (!t.length) if (!t.length)
return e; return e;
let r = e instanceof SVGElement, o = (r ? I : T).bind(null, e, "Attribute"); let r = e instanceof SVGElement, o = (r ? I : T).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([i, s]) { return Object.entries(Object.assign({}, ...t)).forEach(function a([s, i]) {
s = n.processReactiveAttribute(e, i, s, a); i = n.processReactiveAttribute(e, s, i, a);
let [h] = i; let [h] = s;
if (h === "=") if (h === "=")
return o(i.slice(1), s); return o(s.slice(1), i);
if (h === ".") if (h === ".")
return M(e, i.slice(1), s); return M(e, s.slice(1), i);
if (typeof s == "object") if (typeof i == "object" && i !== null)
switch (i) { switch (s) {
case "style": case "style":
return O(s, T.bind(null, e.style, "Property")); return O(i, T.bind(null, e.style, "Property"));
case "dataset": case "dataset":
return O(s, M.bind(null, e.dataset)); return O(i, M.bind(null, e.dataset));
case "ariaset": case "ariaset":
return O(s, (E, v) => o("aria-" + E, v)); return O(i, (E, v) => o("aria-" + E, v));
case "classList": case "classList":
return J(e, s); return J(e, i);
default: default:
return Reflect.set(e, i, s); return Reflect.set(e, s, i);
} }
if (/(aria|data)([A-Z])/.test(i)) if (/(aria|data)([A-Z])/.test(s))
return i = i.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(i, s); return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(s, i);
switch (i) { switch (s) {
case "href": case "href":
return o(i, s); return o(s, i);
case "xlink:href": case "xlink:href":
return o(i, s, "http://www.w3.org/1999/xlink"); return o(s, i, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
if (!r) if (!r)
break; break;
return e.appendChild(document.createTextNode(s)); return e.appendChild(document.createTextNode(i));
} }
return W(e, i) ? q(e, i, s) : o(i, s); return W(e, s) ? q(e, s, i) : o(s, i);
}), e; }), e;
} }
function J(e, t) { function J(e, t) {
@ -124,8 +124,8 @@ function W(e, t) {
let r = e.nodeName + "," + t; let r = e.nodeName + "," + t;
if (x.has(r)) if (x.has(r))
return x.get(r); return x.get(r);
let [o, a, i] = H(e, t), s = !m(o.set); let [o, a, s] = H(e, t), i = !m(o.set);
return (!s || a) && x.set(i === HTMLElement.prototype ? n : r, s), s; return (!i || a) && x.set(s === HTMLElement.prototype ? n : r, i), i;
} }
function H(e, t, n = 0) { function H(e, t, n = 0) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
@ -173,10 +173,10 @@ function Z() {
for (let f of c) for (let f of c)
if (f.type === "childList") { if (f.type === "childList") {
if (E(f.addedNodes, !0)) { if (E(f.addedNodes, !0)) {
i(); s();
continue; continue;
} }
v(f.removedNodes, !0) && i(); v(f.removedNodes, !0) && s();
} }
}); });
return { return {
@ -200,7 +200,7 @@ function Z() {
} }
}; };
function r(c, f) { function r(c, f) {
f.connected.length || f.disconnected.length || (e.delete(c), i()); f.connected.length || f.disconnected.length || (e.delete(c), s());
} }
function o(c) { function o(c) {
if (e.has(c)) if (e.has(c))
@ -211,16 +211,16 @@ function Z() {
function a() { function a() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
} }
function i() { function s() {
!t || e.size || (t = !1, n.disconnect()); !t || e.size || (t = !1, n.disconnect());
} }
function s() { function i() {
return new Promise(function(c) { return new Promise(function(c) {
(requestIdleCallback || requestAnimationFrame)(c); (requestIdleCallback || requestAnimationFrame)(c);
}); });
} }
async function h(c) { async function h(c) {
e.size > 30 && await s(); e.size > 30 && await i();
let f = []; let f = [];
if (!(c instanceof Node)) if (!(c instanceof Node))
return f; return f;
@ -312,15 +312,15 @@ g.clear = function(...e) {
g.el = function(e, t) { g.el = function(e, t) {
let n = document.createComment("<#reactive>"), r = document.createComment("</#reactive>"), o = document.createDocumentFragment(); let n = document.createComment("<#reactive>"), r = document.createComment("</#reactive>"), o = document.createDocumentFragment();
o.append(n, r); o.append(n, r);
let a = (i) => { let a = (s) => {
if (!n.parentNode || !r.parentNode) if (!n.parentNode || !r.parentNode)
return $(e, a); return $(e, a);
let s = t(i); let i = t(s);
Array.isArray(s) || (s = [s]); Array.isArray(i) || (i = [i]);
let h = n; let h = n;
for (; (h = n.nextSibling) !== r; ) for (; (h = n.nextSibling) !== r; )
h.remove(); h.remove();
n.after(...s); n.after(...i);
}; };
return P(e, a), a(e()), o; return P(e, a), a(e()), o;
}; };

2
dist/esm.js vendored
View File

@ -76,7 +76,7 @@ function b(e, ...t) {
return c(s.slice(1), f); return c(s.slice(1), f);
if (h === ".") if (h === ".")
return y(e, s.slice(1), f); return y(e, s.slice(1), f);
if (typeof f == "object") if (typeof f == "object" && f !== null)
switch (s) { switch (s) {
case "style": case "style":
return m(f, N.bind(null, e.style, "Property")); return m(f, N.bind(null, e.style, "Property"));

View File

@ -43,19 +43,19 @@ export function assign(element, ...attributes){
const is_svg= element instanceof SVGElement; const is_svg= element instanceof SVGElement;
const setRemoveAttr= (is_svg ? setRemoveNS : setRemove).bind(null, element, "Attribute"); const setRemoveAttr= (is_svg ? setRemoveNS : setRemove).bind(null, element, "Attribute");
/* jshint maxcomplexity:16 */ /* jshint maxcomplexity:17 */
Object.entries(Object.assign({}, ...attributes)).forEach(function assignNth([ key, attr ]){ Object.entries(Object.assign({}, ...attributes)).forEach(function assignNth([ key, attr ]){
attr= s.processReactiveAttribute(element, key, attr, assignNth); attr= s.processReactiveAttribute(element, key, attr, assignNth);
const [ k ]= key; const [ k ]= key;
if("="===k) return setRemoveAttr(key.slice(1), attr); if("="===k) return setRemoveAttr(key.slice(1), attr);
if("."===k) return setDelete(element, key.slice(1), attr); if("."===k) return setDelete(element, key.slice(1), attr);
if(typeof attr === "object"){ if(typeof attr === "object" && attr!==null){
switch(key){ switch(key){
case "style": return forEachEntries(attr, setRemove.bind(null, element.style, "Property")); case "style": return forEachEntries(attr, setRemove.bind(null, element.style, "Property"));
case "dataset": return forEachEntries(attr, setDelete.bind(null, element.dataset)); case "dataset": return forEachEntries(attr, setDelete.bind(null, element.dataset));
case "ariaset": return forEachEntries(attr, (key, val)=> setRemoveAttr("aria-"+key, val)); case "ariaset": return forEachEntries(attr, (key, val)=> setRemoveAttr("aria-"+key, val));
case "classList": return classListDeclarative(element, attr); case "classList": return classListDeclarative(element, attr);
default: return Reflect.set(element, key, attr); default: return Reflect.set(element, key, attr);
} }
} }
if(/(aria|data)([A-Z])/.test(key)){ if(/(aria|data)([A-Z])/.test(key)){