chore: send the most recent cache upon subscription

This commit is contained in:
waterplea
2022-05-17 11:21:33 +03:00
parent f3bc3832a6
commit 3972b76d10

View File

@@ -1,4 +1,4 @@
import { merge, Observable, Subject, Subscription } from 'rxjs'
import { merge, Observable, ReplaySubject, Subject, Subscription } from 'rxjs'
import { Store } from './store'
import { DBCache, Http } from './types'
import { RPCError } from './source/ws-source'
@@ -8,7 +8,7 @@ export class PatchDB<T> {
public store: Store<T> = new Store(this.http, this.initialCache)
public connectionError$ = new Subject<Error>()
public rpcError$ = new Subject<RPCError>()
public cache$ = new Subject<DBCache<T>>()
public cache$ = new ReplaySubject<DBCache<T>>(1)
private updatesSub?: Subscription
private sourcesSub = this.sources$.subscribe(sources => {