All files / json-crdt/extensions ExtNode.ts

62.5% Statements 5/8
0% Branches 0/2
20% Functions 1/5
62.5% Lines 5/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39156x       156x       1861x 1861x                                         1861x                
import {printTs, type ITimestampStruct} from '../../json-crdt-patch/clock';
import type {JsonNode} from '..';
import type {Printable} from 'tree-dump/lib/types';
 
export abstract class ExtNode<N extends JsonNode, View = unknown> implements JsonNode<View>, Printable {
  public abstract readonly extId: number;
  public readonly id: ITimestampStruct;
 
  constructor(public readonly data: N) {
    this.id = data.id;
  }
 
  // -------------------------------------------------------- ExtensionJsonNode
 
  /**
   * @todo Maybe hardcode this as `ext` to be inline with other classes. And retrieve extension names differently.
   */
  public abstract name(): string;
  public abstract view(): View;
 
  public children(callback: (node: JsonNode) => void): void {}
 
  public child?(): N {
    return this.data;
  }
 
  public container(): JsonNode | undefined {
    return this.data.container();
  }
 
  public api: undefined | unknown = undefined;
 
  // ---------------------------------------------------------------- Printable
 
  public toString(tab?: string, parentId?: ITimestampStruct): string {
    return this.name() + (parentId ? ' ' + printTs(parentId) : '') + ' ' + this.data.toString(tab);
  }
}