diff --git a/src/State.ts b/src/State.ts index e60e244..cbd399a 100644 --- a/src/State.ts +++ b/src/State.ts @@ -20,7 +20,7 @@ import { Tree } from "./Tree"; import { TreeNode } from "./TreeNode"; import mitt from "mitt"; -type Events = { +export type Events = { /** * Intermediary operations made when reordering events based on timestamps. * @@ -34,7 +34,7 @@ type Events = { }; }; -type Parent = { +export type Parent = { id: Id; metadata?: Metadata; parent?: Parent; diff --git a/src/TreeReplica.ts b/src/TreeReplica.ts index 1575138..aab8013 100644 --- a/src/TreeReplica.ts +++ b/src/TreeReplica.ts @@ -10,9 +10,10 @@ // `State` is a lower-level interface to the Tree CRDT and is not tied to any // actor/peer. +import { Emitter } from "mitt"; import { Clock } from "./Clock"; import { OpMove } from "./OpMove"; -import { State } from "./State"; +import { Events, State } from "./State"; import { Tree } from "./Tree"; import { TreeNode } from "./TreeNode"; @@ -39,11 +40,15 @@ export class TreeReplica { latestTimeByReplica: Map> = new Map(); /** A tree structure that represents the current state of the tree */ tree: Tree; + /** An event emitter for updates to the state of the tree */ + emitter: Emitter>; constructor(authorId: Id, options: ReplicaOptions = {}) { this.time = new Clock(authorId); this.state = new State(options); + this.tree = this.state.tree; + this.emitter = this.state.emitter; } /** Get a node by its id */