mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-30 03:51:56 +00:00
set connection error null if poll returns 2xx
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { EMPTY, map, merge, Observable, shareReplay, Subject } from 'rxjs'
|
import { EMPTY, map, merge, Observable, shareReplay, Subject } from 'rxjs'
|
||||||
import { catchError, switchMap } from 'rxjs/operators'
|
import { catchError, filter, switchMap, tap } from 'rxjs/operators'
|
||||||
import { Store } from './store'
|
import { Store } from './store'
|
||||||
import { DBCache, Http } from './types'
|
import { DBCache, Http } from './types'
|
||||||
import { Source } from './source/source'
|
import { Source } from './source/source'
|
||||||
@@ -17,9 +17,10 @@ export class PatchDB<T> {
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
tap(_ => this.connectionError$.next(null)),
|
||||||
|
filter(Boolean),
|
||||||
map(res => {
|
map(res => {
|
||||||
this.store.update(res)
|
this.store.update(res)
|
||||||
|
|
||||||
return this.store.cache
|
return this.store.cache
|
||||||
}),
|
}),
|
||||||
shareReplay(1),
|
shareReplay(1),
|
||||||
|
|||||||
@@ -14,12 +14,20 @@ export class PollSource<T> implements Source<T> {
|
|||||||
private readonly http: Http<T>,
|
private readonly http: Http<T>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
watch$({ sequence$ }: Store<T>): Observable<Update<T>> {
|
watch$({ sequence$ }: Store<T>): Observable<Update<T> | null> {
|
||||||
return sequence$.pipe(
|
return sequence$.pipe(
|
||||||
concatMap(seq => this.http.getRevisions(seq)),
|
concatMap(seq => this.http.getRevisions(seq)),
|
||||||
take(1),
|
take(1),
|
||||||
// convert Revision[] it into Observable<Revision>. Convert Dump<T> into Observable<Dump<T>>
|
concatMap(res => {
|
||||||
concatMap(res => (Array.isArray(res) ? from(res) : of(res))),
|
// If Revision[]
|
||||||
|
if (Array.isArray(res)) {
|
||||||
|
// Convert Revision[] it into Observable<Revision> OR return null
|
||||||
|
return res.length ? from(res) : of(null)
|
||||||
|
// If Dump<T>
|
||||||
|
}
|
||||||
|
// Convert Dump<T> into Observable<Dump<T>>
|
||||||
|
return of(res)
|
||||||
|
}),
|
||||||
repeat({ delay: this.pollConfig.cooldown }),
|
repeat({ delay: this.pollConfig.cooldown }),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ import { Store } from '../store'
|
|||||||
import { Update } from '../types'
|
import { Update } from '../types'
|
||||||
|
|
||||||
export interface Source<T> {
|
export interface Source<T> {
|
||||||
watch$(store?: Store<T>): Observable<Update<T>>
|
watch$(store?: Store<T>): Observable<Update<T> | null>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
"uuid": "8.3.2"
|
"uuid": "8.3.2"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"rxjs": ">=6.0.0"
|
"rxjs": ">=7.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "16.4.13",
|
"@types/node": "16.4.13",
|
||||||
|
|||||||
Reference in New Issue
Block a user