From 99d073b87ac66523a8cf80f9db34ce2733c9890a Mon Sep 17 00:00:00 2001 From: Jan Andrle Date: Thu, 12 Dec 2024 20:05:21 +0100 Subject: [PATCH] :zap: :bug: improves/fixes queue --- dist/dde-with-signals.js | 25 ++++++++++++------------- dist/dde.js | 29 ++++++++++++++--------------- dist/esm-with-signals.js | 25 ++++++++++++------------- dist/esm.js | 29 ++++++++++++++--------------- jsdom.js | 10 ++++++---- src/dom-common.js | 3 +-- src/dom.js | 2 +- 7 files changed, 60 insertions(+), 63 deletions(-) diff --git a/dist/dde-with-signals.js b/dist/dde-with-signals.js index 039fcf8..01ede4f 100644 --- a/dist/dde-with-signals.js +++ b/dist/dde-with-signals.js @@ -52,8 +52,7 @@ var d = { H: globalThis.HTMLElement, S: globalThis.SVGElement, M: globalThis.MutationObserver, - qa: (t) => t, - qw: () => Promise.resolve() + q: (t) => t || Promise.resolve() }; function pt(t, e, n) { if (Reflect.set(t, e, n), !!A(n)) { @@ -67,7 +66,7 @@ var O = "__dde_lifecyclesToEvents", _ = "dde:connected", S = "dde:disconnected", // src/dom.js function Mt(t) { - return d.qa(t); + return d.q(t); } var y = [{ get scope() { @@ -467,7 +466,7 @@ E.on = function t(e, n, r = {}) { let { signal: o } = r; if (!(o && o.aborted)) { if (Array.isArray(e)) return e.forEach((c) => t(c, n, r)); - K(e, n), o && o.addEventListener("abort", () => R(e, n)); + Q(e, n), o && o.addEventListener("abort", () => R(e, n)); } }; E.symbols = { @@ -508,7 +507,7 @@ E.el = function(t, e) { k.remove(); m.remove(), n.isConnected && yt(c.host()); }; - return K(t, a), ut(t, a, n, e), a(t()), o; + return Q(t, a), ut(t, a, n, e), a(t()), o; }; function yt(t) { !t || !t[D] || (requestIdleCallback || setTimeout)(function() { @@ -522,7 +521,7 @@ var At = { }; function Ot(t) { return function(e, n) { - let r = (...c) => c.length ? e.setAttribute(n, ...c) : V(r), o = ft(r, e.getAttribute(n), At); + let r = (...c) => c.length ? e.setAttribute(n, ...c) : K(r), o = ft(r, e.getAttribute(n), At); return t[n] = o, o; }; } @@ -549,7 +548,7 @@ var st = { return R(n, o); r(e, c); }; - return K(n, o), ut(n, o, t, e), n(); + return Q(n, o), ut(n, o, t, e), n(); } }; function ut(t, e, ...n) { @@ -567,14 +566,14 @@ function ut(t, e, ...n) { }); } function it(t, e, n) { - let r = t ? () => V(r) : (...o) => o.length ? at(r, ...o) : V(r); + let r = t ? () => K(r) : (...o) => o.length ? at(r, ...o) : K(r); return ft(r, e, n, t); } var St = Object.assign(/* @__PURE__ */ Object.create(null), { stopPropagation() { this.skip = !0; } -}), Q = class extends Error { +}), V = class extends Error { constructor() { super(); let [e, ...n] = this.stack.split(` @@ -595,7 +594,7 @@ function ft(t, e, n, r = !1) { onclear: o, host: u, listeners: /* @__PURE__ */ new Set(), - defined: new Q().stack, + defined: new V().stack, readonly: r }, enumerable: !1, @@ -606,7 +605,7 @@ function ft(t, e, n, r = !1) { function Ct() { return z[z.length - 1]; } -function V(t) { +function K(t) { if (!t[p]) return; let { value: e, listeners: n } = t[p], r = Ct(); return r && n.add(r), g.has(r) && g.get(r).add(t), e; @@ -617,7 +616,7 @@ function at(t, e, n) { if (!(!n && r.value === e)) return r.value = e, r.listeners.forEach((o) => o(e)), e; } -function K(t, e) { +function Q(t, e) { if (t[p]) return t[p].listeners.add(e); } @@ -641,7 +640,6 @@ globalThis.dde= { S: E, assign: q, assignAttribute: nt, - asyncQueueAdd: Mt, chainableAppend: lt, classListDeclarative: ht, createElement: M, @@ -656,6 +654,7 @@ globalThis.dde= { lifecyclesToEvents: xt, observedAttributes: wt, on: w, + queue: Mt, registerReactivity: H, scope: x, signal: E, diff --git a/dist/dde.js b/dist/dde.js index b9ef61d..b659278 100644 --- a/dist/dde.js +++ b/dist/dde.js @@ -40,17 +40,16 @@ function G(t) { // src/dom-common.js var f = { - setDeleteAttr: Q, + setDeleteAttr: V, ssr: "", D: globalThis.document, F: globalThis.DocumentFragment, H: globalThis.HTMLElement, S: globalThis.SVGElement, M: globalThis.MutationObserver, - qa: (t) => t, - qw: () => Promise.resolve() + q: (t) => t || Promise.resolve() }; -function Q(t, e, n) { +function V(t, e, n) { if (Reflect.set(t, e, n), !!x(n)) { if (Reflect.deleteProperty(t, e), t instanceof f.H && t.getAttribute(e) === "undefined") return t.removeAttribute(e); @@ -62,7 +61,7 @@ var w = "__dde_lifecyclesToEvents", v = "dde:connected", m = "dde:disconnected", // src/dom.js function dt(t) { - return f.qa(t); + return f.q(t); } var g = [{ get scope() { @@ -98,7 +97,7 @@ var g = [{ function q(...t) { return this.appendOriginal(...t), this; } -function V(t) { +function J(t) { return t.append === q || (t.appendOriginal = t.append, t.append = q), t; } var T; @@ -131,7 +130,7 @@ function P(t, e, ...n) { case !c: c = R.call(this, f.D.createElement(t), e); } - return V(c), a || (a = c), n.forEach((d) => d(a)), o && D.pop(), o = 2, c; + return J(c), a || (a = c), n.forEach((d) => d(a)), o && D.pop(), o = 2, c; } P.mark = function(t, e = !1) { t = Object.entries(t).map(([o, c]) => o + `="${c}"`).join(" "); @@ -156,7 +155,7 @@ function ht(t, e = t) { for (let p of d) { let b = (p.slot || "") + n; try { - K(p, "remove", "slot"); + Q(p, "remove", "slot"); } catch { } let h = o[b]; @@ -205,7 +204,7 @@ function U(t, e, n) { case "ariaset": return M(o, n, (d, p) => r("aria-" + d, p)); case "classList": - return J.call(c, t, n); + return K.call(c, t, n); } return X(t, e) ? $(t, e, n) : r(e, n); } @@ -214,7 +213,7 @@ function H(t, e) { let r = (t instanceof f.S ? tt : Y).bind(null, t, "Attribute"), o = S(e); return { setRemoveAttr: r, s: o }; } -function J(t, e) { +function K(t, e) { let n = S(this); return M( n, @@ -222,7 +221,7 @@ function J(t, e) { (r, o) => t.classList.toggle(r, o === -1 ? void 0 : !!o) ), t; } -function K(t, e, n, r) { +function Q(t, e, n, r) { return t instanceof f.H ? t[e + "Attribute"](n, r) : t[e + "AttributeNS"](null, n, r); } function X(t, e) { @@ -431,9 +430,8 @@ _.attributeChanged = function(t, e) { globalThis.dde= { assign: R, assignAttribute: U, - asyncQueueAdd: dt, - chainableAppend: V, - classListDeclarative: J, + chainableAppend: J, + classListDeclarative: K, createElement: P, createElementNS: pt, customElementRender: mt, @@ -441,10 +439,11 @@ globalThis.dde= { dispatchEvent: Ot, el: P, elNS: pt, - elementAttribute: K, + elementAttribute: Q, lifecyclesToEvents: nt, observedAttributes: rt, on: _, + queue: dt, registerReactivity: Z, scope: D, simulateSlots: ht diff --git a/dist/esm-with-signals.js b/dist/esm-with-signals.js index b14e915..91a000d 100644 --- a/dist/esm-with-signals.js +++ b/dist/esm-with-signals.js @@ -50,8 +50,7 @@ var d = { H: globalThis.HTMLElement, S: globalThis.SVGElement, M: globalThis.MutationObserver, - qa: (t) => t, - qw: () => Promise.resolve() + q: (t) => t || Promise.resolve() }; function pt(t, e, n) { if (Reflect.set(t, e, n), !!A(n)) { @@ -65,7 +64,7 @@ var O = "__dde_lifecyclesToEvents", _ = "dde:connected", S = "dde:disconnected", // src/dom.js function Mt(t) { - return d.qa(t); + return d.q(t); } var y = [{ get scope() { @@ -465,7 +464,7 @@ E.on = function t(e, n, r = {}) { let { signal: o } = r; if (!(o && o.aborted)) { if (Array.isArray(e)) return e.forEach((c) => t(c, n, r)); - K(e, n), o && o.addEventListener("abort", () => R(e, n)); + Q(e, n), o && o.addEventListener("abort", () => R(e, n)); } }; E.symbols = { @@ -506,7 +505,7 @@ E.el = function(t, e) { k.remove(); m.remove(), n.isConnected && yt(c.host()); }; - return K(t, a), ut(t, a, n, e), a(t()), o; + return Q(t, a), ut(t, a, n, e), a(t()), o; }; function yt(t) { !t || !t[D] || (requestIdleCallback || setTimeout)(function() { @@ -520,7 +519,7 @@ var At = { }; function Ot(t) { return function(e, n) { - let r = (...c) => c.length ? e.setAttribute(n, ...c) : V(r), o = ft(r, e.getAttribute(n), At); + let r = (...c) => c.length ? e.setAttribute(n, ...c) : K(r), o = ft(r, e.getAttribute(n), At); return t[n] = o, o; }; } @@ -547,7 +546,7 @@ var st = { return R(n, o); r(e, c); }; - return K(n, o), ut(n, o, t, e), n(); + return Q(n, o), ut(n, o, t, e), n(); } }; function ut(t, e, ...n) { @@ -565,14 +564,14 @@ function ut(t, e, ...n) { }); } function it(t, e, n) { - let r = t ? () => V(r) : (...o) => o.length ? at(r, ...o) : V(r); + let r = t ? () => K(r) : (...o) => o.length ? at(r, ...o) : K(r); return ft(r, e, n, t); } var St = Object.assign(/* @__PURE__ */ Object.create(null), { stopPropagation() { this.skip = !0; } -}), Q = class extends Error { +}), V = class extends Error { constructor() { super(); let [e, ...n] = this.stack.split(` @@ -593,7 +592,7 @@ function ft(t, e, n, r = !1) { onclear: o, host: u, listeners: /* @__PURE__ */ new Set(), - defined: new Q().stack, + defined: new V().stack, readonly: r }, enumerable: !1, @@ -604,7 +603,7 @@ function ft(t, e, n, r = !1) { function Ct() { return z[z.length - 1]; } -function V(t) { +function K(t) { if (!t[p]) return; let { value: e, listeners: n } = t[p], r = Ct(); return r && n.add(r), g.has(r) && g.get(r).add(t), e; @@ -615,7 +614,7 @@ function at(t, e, n) { if (!(!n && r.value === e)) return r.value = e, r.listeners.forEach((o) => o(e)), e; } -function K(t, e) { +function Q(t, e) { if (t[p]) return t[p].listeners.add(e); } @@ -638,7 +637,6 @@ export { E as S, q as assign, nt as assignAttribute, - Mt as asyncQueueAdd, lt as chainableAppend, ht as classListDeclarative, M as createElement, @@ -653,6 +651,7 @@ export { xt as lifecyclesToEvents, wt as observedAttributes, w as on, + Mt as queue, H as registerReactivity, x as scope, E as signal, diff --git a/dist/esm.js b/dist/esm.js index dd954e2..9f9641e 100644 --- a/dist/esm.js +++ b/dist/esm.js @@ -38,17 +38,16 @@ function G(t) { // src/dom-common.js var f = { - setDeleteAttr: Q, + setDeleteAttr: V, ssr: "", D: globalThis.document, F: globalThis.DocumentFragment, H: globalThis.HTMLElement, S: globalThis.SVGElement, M: globalThis.MutationObserver, - qa: (t) => t, - qw: () => Promise.resolve() + q: (t) => t || Promise.resolve() }; -function Q(t, e, n) { +function V(t, e, n) { if (Reflect.set(t, e, n), !!x(n)) { if (Reflect.deleteProperty(t, e), t instanceof f.H && t.getAttribute(e) === "undefined") return t.removeAttribute(e); @@ -60,7 +59,7 @@ var w = "__dde_lifecyclesToEvents", v = "dde:connected", m = "dde:disconnected", // src/dom.js function dt(t) { - return f.qa(t); + return f.q(t); } var g = [{ get scope() { @@ -96,7 +95,7 @@ var g = [{ function q(...t) { return this.appendOriginal(...t), this; } -function V(t) { +function J(t) { return t.append === q || (t.appendOriginal = t.append, t.append = q), t; } var T; @@ -129,7 +128,7 @@ function P(t, e, ...n) { case !c: c = R.call(this, f.D.createElement(t), e); } - return V(c), a || (a = c), n.forEach((d) => d(a)), o && D.pop(), o = 2, c; + return J(c), a || (a = c), n.forEach((d) => d(a)), o && D.pop(), o = 2, c; } P.mark = function(t, e = !1) { t = Object.entries(t).map(([o, c]) => o + `="${c}"`).join(" "); @@ -154,7 +153,7 @@ function ht(t, e = t) { for (let p of d) { let b = (p.slot || "") + n; try { - K(p, "remove", "slot"); + Q(p, "remove", "slot"); } catch { } let h = o[b]; @@ -203,7 +202,7 @@ function U(t, e, n) { case "ariaset": return M(o, n, (d, p) => r("aria-" + d, p)); case "classList": - return J.call(c, t, n); + return K.call(c, t, n); } return X(t, e) ? $(t, e, n) : r(e, n); } @@ -212,7 +211,7 @@ function H(t, e) { let r = (t instanceof f.S ? tt : Y).bind(null, t, "Attribute"), o = S(e); return { setRemoveAttr: r, s: o }; } -function J(t, e) { +function K(t, e) { let n = S(this); return M( n, @@ -220,7 +219,7 @@ function J(t, e) { (r, o) => t.classList.toggle(r, o === -1 ? void 0 : !!o) ), t; } -function K(t, e, n, r) { +function Q(t, e, n, r) { return t instanceof f.H ? t[e + "Attribute"](n, r) : t[e + "AttributeNS"](null, n, r); } function X(t, e) { @@ -428,9 +427,8 @@ _.attributeChanged = function(t, e) { export { R as assign, U as assignAttribute, - dt as asyncQueueAdd, - V as chainableAppend, - J as classListDeclarative, + J as chainableAppend, + K as classListDeclarative, P as createElement, pt as createElementNS, mt as customElementRender, @@ -438,10 +436,11 @@ export { Ot as dispatchEvent, P as el, pt as elNS, - K as elementAttribute, + Q as elementAttribute, nt as lifecyclesToEvents, rt as observedAttributes, _ as on, + dt as queue, Z as registerReactivity, D as scope, ht as simulateSlots diff --git a/jsdom.js b/jsdom.js index ceebc2e..00d5a2d 100644 --- a/jsdom.js +++ b/jsdom.js @@ -2,10 +2,12 @@ import { enviroment as env } from './src/dom-common.js'; env.ssr= " ssr"; -const wa_store= new Set(); -env.qa= function(promise){ wa_store.add(promise); return promise; }; -env.qw= function(){ return Promise.allSettled(Array.from(wa_store)).then(()=> wa_store.clear()); }; -export const asyncQueue= env.ww; +const q_store= new Set(); +env.q= function(promise){ + if(promise) return ( q_store.add(promise), promise ); + return Promise.allSettled(Array.from(q_store)).then(()=> q_store.clear()); +}; +export const queue= env.q; const { setDeleteAttr }= env; /** @param {HTMLElement} obj */ diff --git a/src/dom-common.js b/src/dom-common.js index 713581e..01eb83f 100644 --- a/src/dom-common.js +++ b/src/dom-common.js @@ -6,8 +6,7 @@ export const enviroment= { H: globalThis.HTMLElement, S: globalThis.SVGElement, M: globalThis.MutationObserver, - qa: (p)=> p, - qw: ()=> Promise.resolve(), + q: p=> p || Promise.resolve(), }; import { isUndef } from './helpers.js'; function setDeleteAttr(obj, prop, val){ diff --git a/src/dom.js b/src/dom.js index 7c6370b..4ad5b39 100644 --- a/src/dom.js +++ b/src/dom.js @@ -1,7 +1,7 @@ import { signals } from "./signals-common.js"; import { enviroment as env } from './dom-common.js'; -export function asyncQueueAdd(promise){ return env.qa(promise); } +export function queue(promise){ return env.q(promise); } /** @type {{ scope: object, prevent: boolean, host: function }[]} */ const scopes= [ { get scope(){ return env.D.body; },