add connection monitoring

This commit is contained in:
Matt Hill
2021-07-01 16:18:26 -06:00
committed by Aiden McClelland
parent 4fedd74b26
commit eb4a24e797
5 changed files with 32 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
import { merge, Observable, of } from 'rxjs'
import { Observable } from 'rxjs'
import { concatMap, finalize, map, tap } from 'rxjs/operators'
import { Source } from './source/source'
import { Store } from './store'
@@ -7,6 +7,7 @@ export { Operation } from 'fast-json-patch'
export class PatchDB<T extends object> {
store: Store<T>
connectionStatus$ = this.source.connectionStatus$
constructor (
private readonly source: Source<T>,
@@ -21,7 +22,7 @@ export class PatchDB<T extends object> {
const sequence$ = this.store.watchAll$().pipe(map(cache => cache.sequence))
// nested concatMaps, as it is written, ensure sync is not run for update2 until handleSyncResult is complete for update1.
// flat concatMaps would allow many syncs to run while handleSyncResult was hanging. We can consider such an idea if performance requires it.
return merge(this.source.watch$(sequence$)).pipe(
return this.source.watch$(sequence$).pipe(
tap(update => console.log('PATCHDB - source updated:', update)),
concatMap(update => this.store.update$(update)),
finalize(() => {