simplify websocket opening and response types from BE

This commit is contained in:
Matt Hill
2022-08-15 16:59:05 -06:00
parent ebbb347128
commit 4aadfed740
5 changed files with 27 additions and 82 deletions

View File

@@ -3,7 +3,6 @@ import { concatMap, map, take } from 'rxjs/operators'
import { Store } from '../store'
import { Http, Update } from '../types'
import { Source } from './source'
import { RPCResponse } from './ws-source'
export type PollConfig = {
cooldown: number
@@ -15,13 +14,12 @@ export class PollSource<T> implements Source<T> {
private readonly http: Http<T>,
) {}
watch$({ sequence$ }: Store<T>): Observable<RPCResponse<Update<T>>> {
watch$({ sequence$ }: Store<T>): Observable<Update<T>> {
return sequence$.pipe(
concatMap(seq => this.http.getRevisions(seq)),
take(1),
// Revision[] converted it into Observable<Revision>, 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))),
map(result => ({ result, jsonrpc: '2.0' as const })),
repeatWhen(() => timer(this.pollConfig.cooldown)),
)
}