Skip to content

Commit

Permalink
feat(json-crdt): 馃幐 improve extension presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed May 3, 2024
1 parent 3ef93cd commit d13cc65
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/json-crdt/extensions/ExtensionNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {printTree} from 'tree-dump/lib/printTree';
import type {ITimestampStruct} from '../../json-crdt-patch/clock';
import {toDisplayString, type ITimestampStruct} from '../../json-crdt-patch/clock';
import type {ExtensionJsonNode, JsonNode} from '..';
import type {Printable} from 'tree-dump/lib/types';

Expand Down Expand Up @@ -29,7 +28,7 @@ export abstract class ExtensionNode<N extends JsonNode> implements ExtensionJson

// ---------------------------------------------------------------- Printable

public toString(tab?: string): string {
return this.name() + printTree(tab, [(tab) => this.data.toString(tab)]);
public toString(tab?: string, parentId?: ITimestampStruct): string {
return this.name() + (parentId ? ' ' + toDisplayString(parentId) : '') + ', ' + this.data.toString(tab);
}
}
9 changes: 5 additions & 4 deletions src/json-crdt/nodes/vec/VecNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {compare, ITimestampStruct, toDisplayString} from '../../../json-crdt-pat
import type {Model} from '../../model';
import type {JsonNode, JsonNodeView} from '..';
import type {Printable} from 'tree-dump/lib/types';
import type {ExtensionNode} from '../../extensions/ExtensionNode';

/**
* Represents a `vec` JSON CRDT node, which is a LWW array.
Expand Down Expand Up @@ -67,14 +68,14 @@ export class VecNode<Value extends JsonNode[] = JsonNode[]> implements JsonNode<
/**
* @ignore
*/
private __extNode: JsonNode | undefined;
private __extNode: ExtensionNode<JsonNode> | undefined;

/**
* @ignore
* @returns Returns the extension data node if this is an extension node,
* otherwise `undefined`. The node is cached after the first access.
*/
public ext(): JsonNode | undefined {
public ext(): ExtensionNode<JsonNode> | undefined {
if (this.__extNode) return this.__extNode;
const extensionId = this.getExtId();
const isExtension = extensionId >= 0;
Expand Down Expand Up @@ -112,7 +113,7 @@ export class VecNode<Value extends JsonNode[] = JsonNode[]> implements JsonNode<
/**
* @ignore
*/
public child(): JsonNode | undefined {
public child(): ExtensionNode<JsonNode> | undefined {
return this.ext();
}

Expand Down Expand Up @@ -182,7 +183,7 @@ export class VecNode<Value extends JsonNode[] = JsonNode[]> implements JsonNode<
const header =
this.name() + ' ' + toDisplayString(this.id) + (extNode ? ` { extension = ${this.getExtId()} }` : '');
if (extNode) {
return this.child()!.toString(tab);
return this.child()!.toString(tab, this.id);
}
const index = this.doc.index;
return (
Expand Down

0 comments on commit d13cc65

Please sign in to comment.