enso
Version:
Maximalist state & form management library for React
102 lines (78 loc) • 1.99 kB
JavaScript
;
"use client";
exports.StateProxyImpl = exports.StateProxy = exports.StateOptionalImpl = exports.StateImpl = exports.State = void 0;
var _implementation = require("../atom/implementation.cjs");
//#region State
class StateImpl extends _implementation.AtomImpl {
//#region Static
static prop = "state";
static create(value, parent) {
return new StateImpl(value, parent);
}
static proxy(state, intoMapper, fromMapper) {
return new StateProxyImpl(state, intoMapper, fromMapper);
}
static optional(target) {
return new StateOptionalImpl(target);
}
//#endregion
//#region Instance
constructor(value, parent) {
super(value, parent);
}
//#endregion
//#region Meta
useMeta(_props) {
return {};
}
//#endregion
//#region Cache
clearCache() {
_implementation.AtomImpl.prototype.clearCache.call(this);
}
//#endregion
}
//#endregion
//#region StateProxy
exports.StateImpl = exports.State = StateImpl;
class StateProxyImpl extends StateImpl {
#internal;
constructor(source, into, from) {
const value = into(source.value, undefined);
super(value, {
source
});
this.#internal = new _implementation.AtomProxyInternal(this, source, into, from);
}
deconstruct() {
this.#internal.deconstruct();
}
connect(source) {
this.#internal.connect(source);
}
}
//#endregion
//#region StateOptional
exports.StateProxyImpl = exports.StateProxy = StateProxyImpl;
class StateOptionalImpl extends StateImpl {
#internal;
constructor(target) {
super(_implementation.AtomOptionalInternal.value("state", target));
this.#internal = new _implementation.AtomOptionalInternal(this, target);
}
//#region Value
get value() {
return this.#internal.value;
}
//#endregion
//#region Tree
at(key) {
return this.#internal.at(key);
}
get try() {
return this.#internal.try;
}
//#endregion
}
//#endregion
exports.StateOptionalImpl = StateOptionalImpl;