From 0f2f5cb34984947c49030dfc10c871dea1e89270 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Wed, 17 Aug 2022 15:15:58 -0600 Subject: [PATCH] remove sources entirely --- client/index.ts | 3 --- client/lib/patch-db.ts | 24 +++++++----------------- client/lib/source/mock-source.ts | 11 ----------- client/lib/source/source.ts | 7 ------- client/lib/source/ws-source.ts | 12 ------------ client/lib/store.ts | 11 ++--------- client/lib/types.ts | 5 ----- 7 files changed, 9 insertions(+), 64 deletions(-) delete mode 100644 client/lib/source/mock-source.ts delete mode 100644 client/lib/source/source.ts delete mode 100644 client/lib/source/ws-source.ts diff --git a/client/index.ts b/client/index.ts index ec8c227..f2de622 100644 --- a/client/index.ts +++ b/client/index.ts @@ -1,6 +1,3 @@ -export * from './lib/source/mock-source' -export * from './lib/source/ws-source' -export * from './lib/source/source' export * from './lib/json-patch-lib' export * from './lib/patch-db' export * from './lib/store' diff --git a/client/lib/patch-db.ts b/client/lib/patch-db.ts index bed63f9..3347a1f 100644 --- a/client/lib/patch-db.ts +++ b/client/lib/patch-db.ts @@ -1,28 +1,18 @@ -import { map, shareReplay, Subject, timer } from 'rxjs' -import { catchError, concatMap, tap } from 'rxjs/operators' +import { map, Observable, shareReplay } from 'rxjs' +import { tap } from 'rxjs/operators' import { Store } from './store' -import { DBCache, Http } from './types' -import { Source } from './source/source' +import { DBCache, Update } from './types' export class PatchDB { - public store: Store = new Store(this.http, this.initialCache) - public connectionError$ = new Subject() - public cache$ = this.source.watch$(this.store).pipe( - catchError((e, watch$) => { - this.connectionError$.next(e) - return timer(4000).pipe(concatMap(() => watch$)) - }), - tap(res => { - this.connectionError$.next(null) - this.store.update(res) - }), + public store: Store = new Store(this.initialCache) + public cache$ = this.source$.pipe( + tap(res => this.store.update(res)), map(_ => this.store.cache), shareReplay(1), ) constructor( - private readonly source: Source, - private readonly http: Http, + private readonly source$: Observable>, private readonly initialCache: DBCache, ) {} } diff --git a/client/lib/source/mock-source.ts b/client/lib/source/mock-source.ts deleted file mode 100644 index 7791046..0000000 --- a/client/lib/source/mock-source.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Observable } from 'rxjs' -import { Update } from '../types' -import { Source } from './source' - -export class MockSource implements Source { - constructor(private readonly seed: Observable>) {} - - watch$(): Observable> { - return this.seed - } -} diff --git a/client/lib/source/source.ts b/client/lib/source/source.ts deleted file mode 100644 index 4e69eb0..0000000 --- a/client/lib/source/source.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Observable } from 'rxjs' -import { Store } from '../store' -import { Update } from '../types' - -export interface Source { - watch$(store?: Store): Observable> -} diff --git a/client/lib/source/ws-source.ts b/client/lib/source/ws-source.ts deleted file mode 100644 index f73c76c..0000000 --- a/client/lib/source/ws-source.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Observable, timeout } from 'rxjs' -import { webSocket } from 'rxjs/webSocket' -import { Update } from '../types' -import { Source } from './source' - -export class WebsocketSource implements Source { - constructor(private readonly url: string) {} - - watch$(): Observable> { - return webSocket>(this.url).pipe(timeout({ first: 21000 })) - } -} diff --git a/client/lib/store.ts b/client/lib/store.ts index 98eafe2..de7d5e9 100644 --- a/client/lib/store.ts +++ b/client/lib/store.ts @@ -1,4 +1,4 @@ -import { DBCache, Dump, Http, Revision, Update } from './types' +import { DBCache, Dump, Revision, Update } from './types' import { BehaviorSubject, Observable, ReplaySubject } from 'rxjs' import { applyOperation, getValueByPointer, Operation } from './json-patch-lib' import BTree from 'sorted-btree' @@ -13,7 +13,7 @@ export class Store { private watchedNodes: { [path: string]: ReplaySubject } = {} private stash = new BTree() - constructor(private readonly http: Http, public cache: DBCache) {} + constructor(public cache: DBCache) {} watch$(): Observable watch$(p1: P1): Observable> @@ -127,14 +127,7 @@ export class Store { } private handleRevision(revision: Revision): void { - // stash the revision this.stash.set(revision.id, { revision, undo: [] }) - - // if revision is futuristic, fetch missing revisions - if (revision.id > this.cache.sequence + 1) { - this.http.getRevisions(this.cache.sequence) - } - this.processStashed(revision.id) } diff --git a/client/lib/types.ts b/client/lib/types.ts index 657692c..0a9aa2f 100644 --- a/client/lib/types.ts +++ b/client/lib/types.ts @@ -18,11 +18,6 @@ export enum PatchOp { REPLACE = 'replace', } -export interface Http { - getRevisions(since: number): Promise> - getDump(): Promise> -} - export interface Bootstrapper { init(): Promise> update(cache: DBCache): Promise