UNPKG

enso

Version:

Maximalist state & form management library for React

58 lines (45 loc) 1.56 kB
"use strict"; exports.AtomInternalOpaque = void 0; var _index = require("../../../change/index.cjs"); var _index2 = require("../../../detached/index.cjs"); var _index3 = require("../base/index.cjs"); class AtomInternalOpaque extends _index3.AtomInternal { //#region Instance constructor(atom, value) { super(atom, value); this.#value = value; } //#endregion //#region Value #value; get value() { return this.#value === _index2.detachedValue ? undefined : this.#value; } set(value) { let changes = 0n; if (this.#value === _index2.detachedValue && value !== _index2.detachedValue) changes |= _index.change.atom.attach;else if (this.#value !== _index2.detachedValue && value === _index2.detachedValue) changes |= _index.change.atom.detach;else if (typeof this.#value !== typeof value || this.#value && typeof this.#value === "object" && Object.getPrototypeOf(this.#value) !== Object.getPrototypeOf(value)) changes |= _index.change.atom.type;else if (this.#value !== value) changes |= _index.change.atom.value; if (this.#value !== value) this.#value = value; return changes; } dirty(initial) { return initial !== this.#value; } detached() { return this.#value === _index2.detachedValue; } //#endregion //#region Tree $() { return undefined; } // @ts-expect-error lookup(path) { if (path.length === 0) return this.external; return undefined; } //#endregion //#region Events unwatch() {} //#endregion } exports.AtomInternalOpaque = AtomInternalOpaque;