reactronic
Version:
Reactronic - Transactional Reactive State Management
45 lines (44 loc) • 1.55 kB
JavaScript
import { Log } from "../util/Dbg.js";
import { Meta } from "./Meta.js";
export { Meta } from "./Meta.js";
export class ContentFootprint {
get isComputed() { return false; }
constructor(content, lastEditorChangesetId) { this.content = content; this.lastEditorChangesetId = lastEditorChangesetId; }
}
export class ObjectVersion {
constructor(changeset, former, data) {
this.changeset = changeset;
this.former = { objectVersion: former || this };
this.data = data;
this.changes = new Set();
this.conflicts = new Map();
if (Log.isOn)
Object.freeze(this);
}
get revision() {
var _a, _b;
return (_b = (_a = this.data[Meta.Revision]) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : 0;
}
get disposed() { return this.revision < 0; }
set disposed(value) {
const rev = this.revision;
if (rev < 0 !== value)
this.data[Meta.Revision].content = ~rev;
}
}
export class ObjectHandle {
constructor(data, proxy, handler, applied, hint) {
this.id = ++ObjectHandle.generator;
this.data = data;
this.proxy = proxy || new Proxy(this, handler);
this.applied = applied;
this.editing = undefined;
this.editors = 0;
this.hint = hint;
}
static getHint(obj, full) {
const h = Meta.get(obj, Meta.Handle);
return h !== undefined ? (full ? `${h.hint}#${h.id}` : h.hint) : undefined;
}
}
ObjectHandle.generator = 19;