-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(json-crdt): 馃幐 add abstract ExtNode class
- Loading branch information
Showing
3 changed files
with
39 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {printTree} from 'tree-dump/lib/printTree'; | ||
import type {ITimestampStruct} from '../../json-crdt-patch/clock'; | ||
import type {ExtensionJsonNode, JsonNode} from '..'; | ||
import type {Printable} from 'tree-dump/lib/types'; | ||
|
||
export abstract class ExtNode<N extends JsonNode> implements ExtensionJsonNode, Printable { | ||
public readonly id: ITimestampStruct; | ||
|
||
constructor(public readonly data: N) { | ||
this.id = data.id; | ||
} | ||
|
||
// -------------------------------------------------------- ExtensionJsonNode | ||
|
||
public abstract name(): string; | ||
public abstract view(): unknown; | ||
|
||
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): string { | ||
return this.name() + printTree(tab, [(tab) => this.data.toString(tab)]); | ||
} | ||
} |