UNPKG

@adyen/adyen-platform-experience-web

Version:

![Platform Experience header](https://github.com/Adyen/adyen-platform-experience-web/assets/7926613/18094965-9e01-450e-8dc9-ea84e6b22c2b)

57 lines (56 loc) 1.86 kB
import { createWatchListCurrentStateRecord as W, createWatchListSubscriptionEventCallbacks as b } from "./helpers.js"; import { UNSUBSCRIBE_TOKEN as d } from "./constants.js"; import { getMappedValue as R } from "../../../utils/collection/main.js"; import { sameValue as _ } from "../../../utils/value/compare.js"; import { struct as v } from "../../../utils/struct/main.js"; import { enumerable as c, getter as S } from "../../../utils/struct/property.js"; import { isFunction as w } from "../../../utils/value/is.js"; import { noop as C } from "../../../utils/common.js"; const y = (u) => u === d, V = (u) => { let e; const g = W(u), a = b(), o = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new WeakMap(), m = () => Object.freeze({ ...g }), i = () => o.size === 0, l = (t) => { if (i()) return; if (y(t)) { const s = []; return o.forEach((r, n) => { s.push(n); const h = f.get(n); for (; r--; ) h == null || h(); }), s.forEach((r) => r(t)), !0; } const p = e; e = m(); for (const s of Object.keys(e)) if (!_(e[s], p[s])) return o.forEach((r, n) => n(e)), !0; return !1; }, E = (t) => { if (!w(t)) return C; const p = R(t, f, () => { let r = () => { const n = o.get(t) || 0; n === 1 ? (r = void 0, o.delete(t), f.delete(t), i() && (e = void 0, a.idle())) : n > 1 && o.set(t, n - 1); }; return () => { r == null || r(); }; }), s = i(); return o.set( t, (o.get(t) || 0) + 1 ), s && (e = m(), a.resume()), t(e), p; }; return v({ idle: S(i), on: c(a), cancelSubscriptions: c(() => l(d)), requestNotification: c(() => l()), snapshot: S(() => e ?? m()), subscribe: c(E) }); }; export { V as createWatchlist, V as default, y as isWatchlistUnsubscribeToken };