UNPKG

@westacks/vortex

Version:

Server-based routing for SPAs

66 lines (65 loc) 1.64 kB
function y(n, t) { const e = Object.keys, r = typeof n; return n && t && r === "object" && r === typeof t ? e(n).length === e(t).length && e(n).every((i) => y(n[i], t[i])) : n === t; } function b(n, t) { return typeof n != "object" || n === null || n instanceof File || n instanceof Blob ? n : Array.isArray(n) ? n.map((e) => b(e, t)) : Object.entries(n).reduce( (e, [r, o]) => (e[r] = typeof o != "object" || o === null ? o : new Proxy(b(o, t), t), e), {} ); } function p(n) { return typeof n != "object" || n === null || n instanceof File || n instanceof Blob ? n : Array.isArray(n) ? n.map(p) : Object.keys(n).reduce((t, e) => (t[e] = p(n[e]), t), {}); } let f = null; function k(n = void 0, t = (e, r) => e === r) { let e = n; const r = /* @__PURE__ */ new Set(); function o(s) { r.delete(s); } function i() { return f && !r.has(f) && (r.add(f), f.link(o)), e; } function u(s, j = !1) { const l = s instanceof Function ? s(e) : s; if (!(!j && t(e, l))) { e = l; for (const g of [...r]) g.notify(); } } return { get: i, set: u, subscribe: (s) => w(() => s(i())) }; } function w(n) { let t; const e = /* @__PURE__ */ new Set(), r = { notify: o, link: i }; function o() { u(), f = r; try { t = n(); } catch (c) { console.error(c); } f = null; } function i(c) { e.add(c); } async function u() { for (const s of e) s(r); e.clear(); const c = await t; c instanceof Function && c(), t = void 0; } return o(), u; } const A = k(void 0, y); export { p as a, b, y as i, A as p, k as s };