remove sources entirely

This commit is contained in:
Matt Hill
2022-08-17 15:15:58 -06:00
parent a8eaf2ca41
commit 0f2f5cb349
7 changed files with 9 additions and 64 deletions

View File

@@ -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<T> {
public store: Store<T> = new Store(this.http, this.initialCache)
public connectionError$ = new Subject<any>()
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<T> = 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<T>,
private readonly http: Http<T>,
private readonly source$: Observable<Update<T>>,
private readonly initialCache: DBCache<T>,
) {}
}