UNPKG

@frui.ts/helpers

Version:
165 lines (164 loc) 4.44 kB
var P = Object.defineProperty; var m = (t, e, s) => e in t ? P(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s; var i = (t, e, s) => (m(t, typeof e != "symbol" ? e + "" : e, s), s); import { action as a, ObservableMap as _, makeObservable as h, computed as j, observable as g, isObservable as B, makeAutoObservable as M, set as D, isObservableArray as S, isObservableSet as k, isObservableMap as A } from "mobx"; function N(t, e, s) { const n = s.value; if (typeof n != "function") throw new Error(`@bound decorator can only be applied to methods, not ${typeof n}`); let r = !1; return { configurable: !0, get() { if (r || this === t.prototype || Object.prototype.hasOwnProperty.call(this, e)) return n; const o = n.bind(this); return r = !0, Object.defineProperty(this, e, { value: o, configurable: !0, writable: !0 }), r = !1, o; } }; } var T = Object.defineProperty, $ = Object.getOwnPropertyDescriptor, v = (t, e, s, n) => { for (var r = n > 1 ? void 0 : n ? $(e, s) : e, o = t.length - 1, u; o >= 0; o--) (u = t[o]) && (r = (n ? u(e, s, r) : u(r)) || r); return n && r && T(e, s, r), r; }; class C { constructor() { i(this, "busyCounter", new _()); h(this); } get isBusy() { return this.busyCounter.size > 0; } checkBusy(e) { return this.busyCounter.has(e); } getBusyTicket(e = Symbol()) { const s = this.busyCounter.get(e); s ? this.busyCounter.set(e, s + 1) : this.busyCounter.set(e, 1); let n = !1; return a(() => { if (!n) { const r = this.busyCounter.get(e); !r || r === 1 ? this.busyCounter.delete(e) : this.busyCounter.set(e, r - 1), n = !0; } }); } watch(e) { const s = this.getBusyTicket(); return e.then(s, s), e; } } v([ j ], C.prototype, "isBusy", 1); v([ a.bound ], C.prototype, "getBusyTicket", 1); function V(t, e, s) { const n = typeof t != "object", r = n ? t : Symbol(), o = (u, z, p) => { const O = p.value; p.value = function(...d) { var y; const c = (y = this.busyWatcher) == null ? void 0 : y.getBusyTicket(r), l = O.apply(this, d); return c && (E(l) ? l.then(c, (w) => { console.error(w), c(); }) : c()), l; }; }; if (n) return o; if (!e || !s) throw new Error("Wrong decorator use. PropertyKey and Descriptor must be provided"); return o(t, e, s); } function E(t) { return typeof (t == null ? void 0 : t.then) == "function"; } function q(t, e, s, n) { let r = t; return e && (r = r ? r + " " + e : e), s && (r = r ? r + " " + s : s), n && (r = r ? r + " " + n : n), r; } function x(t, e, s) { const n = s ?? ((o) => o), r = /* @__PURE__ */ new Map(); return t.forEach((o) => r.set(e(o), n(o))), r; } function G(t, e) { return t.bind(e); } function H(t, e) { const s = /* @__PURE__ */ new Map(); for (const n of t) { const r = e(n), o = s.get(r); o ? o.push(n) : s.set(r, [n]); } return s; } var W = Object.defineProperty, F = Object.getOwnPropertyDescriptor, b = (t, e, s, n) => { for (var r = n > 1 ? void 0 : n ? F(e, s) : e, o = t.length - 1, u; o >= 0; o--) (u = t[o]) && (r = (n ? u(e, s, r) : u(r)) || r); return n && r && W(e, s, r), r; }; class f { constructor() { i(this, "promise"); i(this, "status", "new"); i(this, "resolveCallback"); i(this, "rejectCallback"); h(this), this.promise = new Promise((e, s) => { this.resolveCallback = e, this.rejectCallback = s; }); } resolve(e) { this.resolveCallback(e), this.status = "resolved"; } reject(e) { this.rejectCallback(e), this.status = "rejected"; } } b([ g ], f.prototype, "status", 2); b([ a.bound ], f.prototype, "resolve", 1); b([ a.bound ], f.prototype, "reject", 1); const I = (t) => t; function J(t, e, s) { B(t) ? D(t, e, s) : (t[e] = s, M(t)); } function Q(t) { return Array.isArray(t) || S(t); } function R(t) { return !!t && (t instanceof Set || k(t)); } function U(t) { return !!t && (t instanceof Map || A(t)); } function X(t) { return !!t; } export { C as BusyWatcher, f as ManualPromise, G as bind, N as bound, q as combineClassNames, x as createMap, J as ensureObservableProperty, H as groupBy, Q as isArrayLike, U as isMap, R as isSet, I as nameof, X as onlyDefined, V as watchBusy }; //# sourceMappingURL=index.es.js.map