mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-26 10:21:53 +00:00
removes temps, massive refactor
This commit is contained in:
committed by
Aiden McClelland
parent
0dcbb3956e
commit
950773e542
@@ -1,7 +1,6 @@
|
||||
import { BehaviorSubject, concat, from, Observable, of } from 'rxjs'
|
||||
import { catchError, concatMap, delay, skip, switchMap, take, tap } from 'rxjs/operators'
|
||||
import { Http } from '../patch-db'
|
||||
import { UpdateReal } from '../sequence-store'
|
||||
import { Http, Update } from '../types'
|
||||
import { Source } from './source'
|
||||
|
||||
export type PollConfig = {
|
||||
@@ -15,7 +14,7 @@ export class PollSource<T> implements Source<T> {
|
||||
private readonly http: Http<T>,
|
||||
) { }
|
||||
|
||||
watch$ (sequence$: Observable<number>): Observable<UpdateReal<T>> {
|
||||
watch$ (sequence$: Observable<number>): Observable<Update<T>> {
|
||||
console.log('POLL_SOURCE - watch$()')
|
||||
|
||||
const polling$ = new BehaviorSubject('')
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Observable } from 'rxjs'
|
||||
import { Update } from '../sequence-store'
|
||||
import { Update } from '../types'
|
||||
|
||||
export interface Source<T> {
|
||||
watch$ (sequence$?: Observable<number>): Observable<Update<T>>
|
||||
|
||||
@@ -1,21 +1,27 @@
|
||||
import { Observable } from 'rxjs'
|
||||
import { webSocket, WebSocketSubject, WebSocketSubjectConfig } from 'rxjs/webSocket'
|
||||
import { UpdateReal } from '../sequence-store'
|
||||
import { Update } from '../types'
|
||||
import { Source } from './source'
|
||||
|
||||
export class WebsocketSource<T> implements Source<T> {
|
||||
private websocket$: WebSocketSubject<UpdateReal<T>>
|
||||
private websocket$: WebSocketSubject<Update<T>>
|
||||
|
||||
constructor (
|
||||
readonly url: string,
|
||||
) {
|
||||
const fullConfig: WebSocketSubjectConfig<UpdateReal<T>> = {
|
||||
const fullConfig: WebSocketSubjectConfig<Update<T>> = {
|
||||
url,
|
||||
openObserver: {
|
||||
next: () => console.log('WebSocket connection open'),
|
||||
next: () => {
|
||||
console.log('WebSocket connection open')
|
||||
this.websocket$.next('open message' as any)
|
||||
},
|
||||
},
|
||||
closeObserver: {
|
||||
next: () => console.log('WebSocket connection closed'),
|
||||
next: () => {
|
||||
console.log('WebSocket connection closed')
|
||||
// @TODO re-open websocket on retry loop
|
||||
},
|
||||
},
|
||||
closingObserver: {
|
||||
next: () => console.log('Websocket subscription cancelled, websocket closing'),
|
||||
@@ -24,5 +30,5 @@ export class WebsocketSource<T> implements Source<T> {
|
||||
this.websocket$ = webSocket(fullConfig)
|
||||
}
|
||||
|
||||
watch$ (): Observable<UpdateReal<T>> { return this.websocket$.asObservable() }
|
||||
watch$ (): Observable<Update<T>> { return this.websocket$.asObservable() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user