refactor: real-time system (#2228)
Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com> Co-authored-by: liyasthomas <liyascthomas@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
HoppRealtimeLog,
|
||||
HoppRealtimeLogLine,
|
||||
} from "~/helpers/types/HoppRealtimeLog"
|
||||
import { SSEConnection } from "~/helpers/realtime/SSEConnection"
|
||||
|
||||
type HoppSSERequest = {
|
||||
endpoint: string
|
||||
@@ -12,10 +13,8 @@ type HoppSSERequest = {
|
||||
|
||||
type HoppSSESession = {
|
||||
request: HoppSSERequest
|
||||
connectingState: boolean
|
||||
connectionState: boolean
|
||||
log: HoppRealtimeLog
|
||||
socket: EventSource | null
|
||||
socket: SSEConnection
|
||||
}
|
||||
|
||||
const defaultSSERequest: HoppSSERequest = {
|
||||
@@ -25,9 +24,7 @@ const defaultSSERequest: HoppSSERequest = {
|
||||
|
||||
const defaultSSESession: HoppSSESession = {
|
||||
request: defaultSSERequest,
|
||||
connectionState: false,
|
||||
connectingState: false,
|
||||
socket: null,
|
||||
socket: new SSEConnection(),
|
||||
log: [],
|
||||
}
|
||||
|
||||
@@ -56,21 +53,11 @@ const dispatchers = defineDispatchers({
|
||||
},
|
||||
}
|
||||
},
|
||||
setSocket(_: HoppSSESession, { socket }: { socket: EventSource }) {
|
||||
setSocket(_: HoppSSESession, { socket }: { socket: SSEConnection }) {
|
||||
return {
|
||||
socket,
|
||||
}
|
||||
},
|
||||
setConnectionState(_: HoppSSESession, { state }: { state: boolean }) {
|
||||
return {
|
||||
connectionState: state,
|
||||
}
|
||||
},
|
||||
setConnectingState(_: HoppSSESession, { state }: { state: boolean }) {
|
||||
return {
|
||||
connectingState: state,
|
||||
}
|
||||
},
|
||||
setLog(_: HoppSSESession, { log }: { log: HoppRealtimeLog }) {
|
||||
return {
|
||||
log,
|
||||
@@ -112,7 +99,7 @@ export function setSSEEventType(newType: string) {
|
||||
})
|
||||
}
|
||||
|
||||
export function setSSESocket(socket: EventSource) {
|
||||
export function setSSESocket(socket: SSEConnection) {
|
||||
SSESessionStore.dispatch({
|
||||
dispatcher: "setSocket",
|
||||
payload: {
|
||||
@@ -121,23 +108,6 @@ export function setSSESocket(socket: EventSource) {
|
||||
})
|
||||
}
|
||||
|
||||
export function setSSEConnectionState(state: boolean) {
|
||||
SSESessionStore.dispatch({
|
||||
dispatcher: "setConnectionState",
|
||||
payload: {
|
||||
state,
|
||||
},
|
||||
})
|
||||
}
|
||||
export function setSSEConnectingState(state: boolean) {
|
||||
SSESessionStore.dispatch({
|
||||
dispatcher: "setConnectingState",
|
||||
payload: {
|
||||
state,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function setSSELog(log: HoppRealtimeLog) {
|
||||
SSESessionStore.dispatch({
|
||||
dispatcher: "setLog",
|
||||
@@ -176,11 +146,6 @@ export const SSEConnectingState$ = SSESessionStore.subject$.pipe(
|
||||
distinctUntilChanged()
|
||||
)
|
||||
|
||||
export const SSEConnectionState$ = SSESessionStore.subject$.pipe(
|
||||
pluck("connectionState"),
|
||||
distinctUntilChanged()
|
||||
)
|
||||
|
||||
export const SSESocket$ = SSESessionStore.subject$.pipe(
|
||||
pluck("socket"),
|
||||
distinctUntilChanged()
|
||||
|
||||
Reference in New Issue
Block a user