@alegendstale/holly-components
Version:
Reusable UI components created using lit
37 lines (36 loc) • 1.15 kB
JavaScript
class t {
constructor({ name: e, initialValue: i, detect: s }) {
this.name = e, this.initialValue = i ?? !0, this.detect = s, t.all[e] = this, Object.defineProperty(t, e, {
get() {
return this.all[e].value;
},
configurable: !0,
enumerable: !0
});
}
#t;
#e;
/**
* Get whether the bug is present or not, or a promise that will resolve to this value when detection is complete.
*/
get valuePending() {
return this.#t !== void 0 ? this.#t : this.#e !== void 0 ? this.#e : (this.#e = this.detect(), this.#e instanceof Promise ? this.#e.then((e) => this.#t = e) : this.#t = this.#e, this.#e);
}
/**
* Synchronously get either whether the bug is present (if already detected or detection is sync)
* or kick off detection and return the initial value if detection is async
*/
get value() {
if (this.#t !== void 0)
return this.#t;
let e = this.valuePending;
return e instanceof Promise ? this.initialValue : e;
}
static all = {};
static detectAll() {
return Promise.all(Object.values(t.all).map((e) => e.valuePending));
}
}
export {
t as default
};