mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-26 10:21:53 +00:00
start
This commit is contained in:
committed by
Aiden McClelland
parent
43e3c77c14
commit
434c6f7037
@@ -1,4 +1,4 @@
|
||||
import { merge, Observable } from 'rxjs'
|
||||
import { merge, Observable, of } from 'rxjs'
|
||||
import { concatMap, finalize, tap } from 'rxjs/operators'
|
||||
import { Source } from './source/source'
|
||||
import { Store } from './store'
|
||||
@@ -6,21 +6,21 @@ import { DBCache } from './types'
|
||||
|
||||
export { Operation } from 'fast-json-patch'
|
||||
|
||||
export class PatchDB<T extends object> {
|
||||
export class PatchDB<T> {
|
||||
store: Store<T>
|
||||
|
||||
constructor (
|
||||
private readonly sources: Source<T>[],
|
||||
readonly cache: DBCache<T>,
|
||||
private readonly initialCache: DBCache<T>,
|
||||
) {
|
||||
this.store = new Store(cache)
|
||||
this.store = new Store(this.initialCache)
|
||||
}
|
||||
|
||||
sync$ (): Observable<DBCache<T>> {
|
||||
return merge(...this.sources.map(s => s.watch$(this.store)))
|
||||
.pipe(
|
||||
tap(update => this.store.update(update)),
|
||||
concatMap(() => this.store.watchCache$()),
|
||||
concatMap(() => of(this.store.cache)),
|
||||
finalize(() => {
|
||||
this.store.reset()
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user