mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-30 12:01:57 +00:00
chore: fix comments
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { EMPTY, merge, Observable, ReplaySubject, Subject } from 'rxjs'
|
import { EMPTY, map, merge, Observable, shareReplay, Subject } from 'rxjs'
|
||||||
import { catchError, switchMap } from 'rxjs/operators'
|
import { catchError, switchMap } from 'rxjs/operators'
|
||||||
import { Store } from './store'
|
import { Store } from './store'
|
||||||
import { DBCache, Http } from './types'
|
import { DBCache, Http } from './types'
|
||||||
@@ -7,17 +7,7 @@ import { Source } from './source/source'
|
|||||||
export class PatchDB<T> {
|
export class PatchDB<T> {
|
||||||
public store: Store<T> = new Store(this.http, this.initialCache)
|
public store: Store<T> = new Store(this.http, this.initialCache)
|
||||||
public connectionError$ = new Subject<any>()
|
public connectionError$ = new Subject<any>()
|
||||||
public cache$ = new ReplaySubject<DBCache<T>>(1)
|
public cache$ = this.sources$.pipe(
|
||||||
|
|
||||||
constructor(
|
|
||||||
private readonly sources$: Observable<Source<T>[]>,
|
|
||||||
private readonly http: Http<T>,
|
|
||||||
private readonly initialCache: DBCache<T>,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
ngOnInit() {
|
|
||||||
this.sources$
|
|
||||||
.pipe(
|
|
||||||
switchMap(sources =>
|
switchMap(sources =>
|
||||||
merge(...sources.map(s => s.watch$(this.store))).pipe(
|
merge(...sources.map(s => s.watch$(this.store))).pipe(
|
||||||
catchError(e => {
|
catchError(e => {
|
||||||
@@ -27,10 +17,17 @@ export class PatchDB<T> {
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
map(res => {
|
||||||
.subscribe(res => {
|
|
||||||
this.store.update(res)
|
this.store.update(res)
|
||||||
this.cache$.next(this.store.cache)
|
|
||||||
})
|
return this.store.cache
|
||||||
}
|
}),
|
||||||
|
shareReplay(1),
|
||||||
|
)
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private readonly sources$: Observable<Source<T>[]>,
|
||||||
|
private readonly http: Http<T>,
|
||||||
|
private readonly initialCache: DBCache<T>,
|
||||||
|
) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { from, Observable, of, repeatWhen, timer } from 'rxjs'
|
import { from, Observable, of, repeat } from 'rxjs'
|
||||||
import { concatMap, map, take } from 'rxjs/operators'
|
import { concatMap, take } from 'rxjs/operators'
|
||||||
import { Store } from '../store'
|
import { Store } from '../store'
|
||||||
import { Http, Update } from '../types'
|
import { Http, Update } from '../types'
|
||||||
import { Source } from './source'
|
import { Source } from './source'
|
||||||
@@ -20,7 +20,7 @@ export class PollSource<T> implements Source<T> {
|
|||||||
take(1),
|
take(1),
|
||||||
// convert Revision[] it into Observable<Revision>. Convert Dump<T> into Observable<Dump<T>>
|
// convert Revision[] it into Observable<Revision>. Convert Dump<T> into Observable<Dump<T>>
|
||||||
concatMap(res => (Array.isArray(res) ? from(res) : of(res))),
|
concatMap(res => (Array.isArray(res) ? from(res) : of(res))),
|
||||||
repeatWhen(() => timer(this.pollConfig.cooldown)),
|
repeat({ delay: this.pollConfig.cooldown }),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user