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

Commit

Permalink
fix: expose emitter on replica
Browse files Browse the repository at this point in the history
  • Loading branch information
matchai committed Aug 11, 2021
1 parent 4a47a44 commit 4ee1ca3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Tree } from "./Tree";
import { TreeNode } from "./TreeNode";
import mitt from "mitt";

type Events<Id, Metadata> = {
export type Events<Id, Metadata> = {
/**
* Intermediary operations made when reordering events based on timestamps.
*
Expand All @@ -34,7 +34,7 @@ type Events<Id, Metadata> = {
};
};

type Parent<Id, Metadata> = {
export type Parent<Id, Metadata> = {
id: Id;
metadata?: Metadata;
parent?: Parent<Id, Metadata>;
Expand Down
7 changes: 6 additions & 1 deletion src/TreeReplica.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

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

constructor(authorId: Id, options: ReplicaOptions<Id, Metadata> = {}) {
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 */
Expand Down

0 comments on commit 4ee1ca3

Please sign in to comment.