mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-26 10:21:53 +00:00
* major refactor to exclude multiple sources Co-authored-by: Matt Hill <matthewonthemoon@gmail.com>
19 lines
504 B
TypeScript
19 lines
504 B
TypeScript
import { map, Observable, shareReplay } from 'rxjs'
|
|
import { tap } from 'rxjs/operators'
|
|
import { Store } from './store'
|
|
import { DBCache, Update } from './types'
|
|
|
|
export class PatchDB<T> {
|
|
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$: Observable<Update<T>>,
|
|
private readonly initialCache: DBCache<T>,
|
|
) {}
|
|
}
|