mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-26 10:21:53 +00:00
remove connection status from lib
This commit is contained in:
committed by
Aiden McClelland
parent
80698e8228
commit
824a103e5c
@@ -1,32 +1,27 @@
|
||||
import { Observable } from 'rxjs'
|
||||
import { concatMap, finalize, map, tap } from 'rxjs/operators'
|
||||
import { merge, Observable } from 'rxjs'
|
||||
import { concatMap, finalize, tap } from 'rxjs/operators'
|
||||
import { Source } from './source/source'
|
||||
import { Store } from './store'
|
||||
import { DBCache } from './types'
|
||||
|
||||
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>,
|
||||
private readonly sources: Source<T>[],
|
||||
readonly cache: DBCache<T>,
|
||||
) {
|
||||
this.store = new Store(cache)
|
||||
}
|
||||
|
||||
sync$ (): Observable<DBCache<T>> {
|
||||
console.log('PATCHDB - sync$()')
|
||||
|
||||
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 this.source.watch$(sequence$).pipe(
|
||||
tap(update => console.log('PATCHDB - source updated:', update)),
|
||||
concatMap(update => this.store.update$(update)),
|
||||
return merge(...this.sources.map(s => s.watch$(this.store)))
|
||||
.pipe(
|
||||
tap(update => this.store.update(update)),
|
||||
concatMap(() => this.store.watchCache$()),
|
||||
finalize(() => {
|
||||
console.log('PATCHDB - FINALIZING sync$()')
|
||||
this.store.reset()
|
||||
}),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user