diff --git a/client/lib/patch-db.ts b/client/lib/patch-db.ts index e5be7a1..5d8b894 100644 --- a/client/lib/patch-db.ts +++ b/client/lib/patch-db.ts @@ -1,5 +1,5 @@ import { EMPTY, map, merge, Observable, shareReplay, Subject } from 'rxjs' -import { catchError, switchMap } from 'rxjs/operators' +import { catchError, filter, switchMap, tap } from 'rxjs/operators' import { Store } from './store' import { DBCache, Http } from './types' import { Source } from './source/source' @@ -17,9 +17,10 @@ export class PatchDB { }), ), ), + tap(_ => this.connectionError$.next(null)), + filter(Boolean), map(res => { this.store.update(res) - return this.store.cache }), shareReplay(1), diff --git a/client/lib/source/poll-source.ts b/client/lib/source/poll-source.ts index 678bc4f..25c82c6 100644 --- a/client/lib/source/poll-source.ts +++ b/client/lib/source/poll-source.ts @@ -14,12 +14,20 @@ export class PollSource implements Source { private readonly http: Http, ) {} - watch$({ sequence$ }: Store): Observable> { + watch$({ sequence$ }: Store): Observable | null> { return sequence$.pipe( concatMap(seq => this.http.getRevisions(seq)), take(1), - // convert Revision[] it into Observable. Convert Dump into Observable> - concatMap(res => (Array.isArray(res) ? from(res) : of(res))), + concatMap(res => { + // If Revision[] + if (Array.isArray(res)) { + // Convert Revision[] it into Observable OR return null + return res.length ? from(res) : of(null) + // If Dump + } + // Convert Dump into Observable> + return of(res) + }), repeat({ delay: this.pollConfig.cooldown }), ) } diff --git a/client/lib/source/source.ts b/client/lib/source/source.ts index 4e69eb0..ce5197f 100644 --- a/client/lib/source/source.ts +++ b/client/lib/source/source.ts @@ -3,5 +3,5 @@ import { Store } from '../store' import { Update } from '../types' export interface Source { - watch$(store?: Store): Observable> + watch$(store?: Store): Observable | null> } diff --git a/client/package.json b/client/package.json index 8d86da0..51cbd57 100644 --- a/client/package.json +++ b/client/package.json @@ -15,7 +15,7 @@ "uuid": "8.3.2" }, "peerDependencies": { - "rxjs": ">=6.0.0" + "rxjs": ">=7.0.0" }, "devDependencies": { "@types/node": "16.4.13",