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:
@@ -10,16 +10,16 @@ import {
|
||||
|
||||
type SocketIO = SocketV2 | SocketV3 | SocketV4
|
||||
|
||||
export type SIOClientVersion = "v4" | "v3" | "v2"
|
||||
|
||||
type HoppSIORequest = {
|
||||
endpoint: string
|
||||
path: string
|
||||
version: string
|
||||
version: SIOClientVersion
|
||||
}
|
||||
|
||||
type HoppSIOSession = {
|
||||
request: HoppSIORequest
|
||||
connectingState: boolean
|
||||
connectionState: boolean
|
||||
log: HoppRealtimeLog
|
||||
socket: SocketIO | null
|
||||
}
|
||||
@@ -32,8 +32,6 @@ const defaultSIORequest: HoppSIORequest = {
|
||||
|
||||
const defaultSIOSession: HoppSIOSession = {
|
||||
request: defaultSIORequest,
|
||||
connectionState: false,
|
||||
connectingState: false,
|
||||
socket: null,
|
||||
log: [],
|
||||
}
|
||||
@@ -63,7 +61,10 @@ const dispatchers = defineDispatchers({
|
||||
},
|
||||
}
|
||||
},
|
||||
setVersion(curr: HoppSIOSession, { newVersion }: { newVersion: string }) {
|
||||
setVersion(
|
||||
curr: HoppSIOSession,
|
||||
{ newVersion }: { newVersion: SIOClientVersion }
|
||||
) {
|
||||
return {
|
||||
request: {
|
||||
...curr.request,
|
||||
@@ -76,16 +77,6 @@ const dispatchers = defineDispatchers({
|
||||
socket,
|
||||
}
|
||||
},
|
||||
setConnectionState(_: HoppSIOSession, { state }: { state: boolean }) {
|
||||
return {
|
||||
connectionState: state,
|
||||
}
|
||||
},
|
||||
setConnectingState(_: HoppSIOSession, { state }: { state: boolean }) {
|
||||
return {
|
||||
connectingState: state,
|
||||
}
|
||||
},
|
||||
setLog(_: HoppSIOSession, { log }: { log: HoppRealtimeLog }) {
|
||||
return {
|
||||
log,
|
||||
@@ -145,23 +136,6 @@ export function setSIOSocket(socket: SocketIO) {
|
||||
})
|
||||
}
|
||||
|
||||
export function setSIOConnectionState(state: boolean) {
|
||||
SIOSessionStore.dispatch({
|
||||
dispatcher: "setConnectionState",
|
||||
payload: {
|
||||
state,
|
||||
},
|
||||
})
|
||||
}
|
||||
export function setSIOConnectingState(state: boolean) {
|
||||
SIOSessionStore.dispatch({
|
||||
dispatcher: "setConnectingState",
|
||||
payload: {
|
||||
state,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function setSIOLog(log: HoppRealtimeLog) {
|
||||
SIOSessionStore.dispatch({
|
||||
dispatcher: "setLog",
|
||||
@@ -200,11 +174,6 @@ export const SIOPath$ = SIOSessionStore.subject$.pipe(
|
||||
distinctUntilChanged()
|
||||
)
|
||||
|
||||
export const SIOConnectingState$ = SIOSessionStore.subject$.pipe(
|
||||
pluck("connectingState"),
|
||||
distinctUntilChanged()
|
||||
)
|
||||
|
||||
export const SIOConnectionState$ = SIOSessionStore.subject$.pipe(
|
||||
pluck("connectionState"),
|
||||
distinctUntilChanged()
|
||||
|
||||
Reference in New Issue
Block a user