json-joy
Version:
Collection of libraries for building collaborative editing apps.
61 lines (60 loc) • 1.7 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConNode = void 0;
const clock_1 = require("../../../json-crdt-patch/clock");
/**
* Represents the `con` type of the JSON CRDT specification.
*
* Constant type represents an immutable JSON value. It can be any JSON/CBOR
* value including deeply nested objects and arrays, Uint8Array binary data, or
* it can store a logical timestamp. The constant value cannot be edited.
*
* @category CRDT Node
*/
class ConNode {
/**
* @param id ID of the CRDT node.
* @param val Raw value of the constant. It can be any JSON/CBOR value, or
* a logical timestamp {@link Timestamp}.
*/
constructor(id, val) {
this.id = id;
this.val = val;
/**
* @ignore
*/
this.api = undefined;
}
// ----------------------------------------------------------------- JsonNode
/**
* @ignore
*/
children() { }
/**
* @ignore
*/
child() {
return undefined;
}
/**
* @ignore
*/
container() {
return undefined;
}
view() {
return this.val;
}
name() {
return 'con';
}
// ---------------------------------------------------------------- Printable
toString(tab) {
const val = this.val;
const valFormatted = val instanceof Uint8Array
? `Uint8Array { ${('' + val).replaceAll(',', ', ')} }`
: `{ ${val instanceof clock_1.Timestamp ? (0, clock_1.printTs)(val) : JSON.stringify(val)} }`;
return `${this.name()} ${(0, clock_1.printTs)(this.id)} ${valFormatted}`;
}
}
exports.ConNode = ConNode;
;