UNPKG

@tucmc/hazel

Version:
65 lines (64 loc) 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReferableMapEntity = void 0; const FieldDelete_1 = require("./FieldDelete"); class ReferableMapEntity { synthesized; document; content; saved = {}; changes = {}; alive = true; constructor(content, document) { this.synthesized = true; this.content = content; this.document = document; } isEdited() { return (Object.keys(this.changes).length > 0 || this.isDeleted() || !this.document || this.synthesized); } update(field, value) { if (!(field in this.saved)) { this.saved[field] = this.content[field]; } this.content[field] = value; this.changes[field] = value; return this; } set(value) { this.content = value; this.changes = value; return this; } get(field) { return this.content[field]; } deleteField(field) { if (!(field in this.saved)) { this.saved[field] = this.content[field]; } this.content[field] = new FieldDelete_1.FieldDelete(); this.changes[field] = new FieldDelete_1.FieldDelete(); } delete() { this.saved = this.getOriginal(); this.changes = {}; this.alive = false; } isDeleted() { return !this.alive; } data() { return this.content; } getOriginal() { return { ...this.content, ...this.saved }; } setSynthesized(syn) { this.synthesized = syn; } } exports.ReferableMapEntity = ReferableMapEntity;