Skip to content

Commit

Permalink
Merge pull request #184 from m-ld/null-remotes
Browse files Browse the repository at this point in the history
Add `NullRemotes`
  • Loading branch information
gsvarovsky authored Jul 25, 2024
2 parents cfbf165 + bbaf5be commit 2a41cac
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"./ext/socket.io-server": "./ext/socket.io/server/index.js",
"./ext/socket.io/server": "./ext/socket.io/server/index.js",
"./ext/ably": "./ext/ably/index.js",
"./ext/null": "./ext/null/index.js",
"./ext/html": "./ext/html/index.js",
"./ext/wrtc": "./ext/wrtc/index.js",
"./ext/security": "./ext/security/index.js",
Expand Down
32 changes: 32 additions & 0 deletions src/null/NullRemotes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { BehaviorSubject, NEVER, type Observable } from "rxjs";

import { MeldRemotes, OperationMessage, MeldLocal } from "../engine";
import type { LiveValue } from '../engine/api-support';

class NotImplementedError extends Error {
constructor(methodName: string) {
super(
`${methodName} is not implemented for a NullRemote. The local clone should be genesis.`
);
}
}

export class NullRemotes implements MeldRemotes {
readonly operations: Observable<OperationMessage> = NEVER;
readonly updates: Observable<OperationMessage> = NEVER;
readonly live: LiveValue<boolean | null> = new BehaviorSubject(false);

setLocal(_clone: MeldLocal | null): void {}

newClock(): never {
throw new NotImplementedError("newClock");
}

revupFrom(): never {
throw new NotImplementedError("revupFrom");
}

snapshot(): never {
throw new NotImplementedError("snapshot");
}
}
1 change: 1 addition & 0 deletions src/null/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { NullRemotes } from './NullRemotes';

0 comments on commit 2a41cac

Please sign in to comment.