Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Commit 4ee1ca3

Browse files
committed
fix: expose emitter on replica
1 parent 4a47a44 commit 4ee1ca3

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/State.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { Tree } from "./Tree";
2020
import { TreeNode } from "./TreeNode";
2121
import mitt from "mitt";
2222

23-
type Events<Id, Metadata> = {
23+
export type Events<Id, Metadata> = {
2424
/**
2525
* Intermediary operations made when reordering events based on timestamps.
2626
*
@@ -34,7 +34,7 @@ type Events<Id, Metadata> = {
3434
};
3535
};
3636

37-
type Parent<Id, Metadata> = {
37+
export type Parent<Id, Metadata> = {
3838
id: Id;
3939
metadata?: Metadata;
4040
parent?: Parent<Id, Metadata>;

src/TreeReplica.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
// `State` is a lower-level interface to the Tree CRDT and is not tied to any
1111
// actor/peer.
1212

13+
import { Emitter } from "mitt";
1314
import { Clock } from "./Clock";
1415
import { OpMove } from "./OpMove";
15-
import { State } from "./State";
16+
import { Events, State } from "./State";
1617
import { Tree } from "./Tree";
1718
import { TreeNode } from "./TreeNode";
1819

@@ -39,11 +40,15 @@ export class TreeReplica<Id, Metadata> {
3940
latestTimeByReplica: Map<Id, Clock<Id>> = new Map();
4041
/** A tree structure that represents the current state of the tree */
4142
tree: Tree<Id, Metadata>;
43+
/** An event emitter for updates to the state of the tree */
44+
emitter: Emitter<Events<Id, Metadata>>;
4245

4346
constructor(authorId: Id, options: ReplicaOptions<Id, Metadata> = {}) {
4447
this.time = new Clock(authorId);
4548
this.state = new State(options);
49+
4650
this.tree = this.state.tree;
51+
this.emitter = this.state.emitter;
4752
}
4853

4954
/** Get a node by its id */

0 commit comments

Comments
 (0)