SSESession.ts (hoppscotch-2.2.1) | : | SSESession.ts (hoppscotch-3.0.0) | ||
---|---|---|---|---|
import { pluck, distinctUntilChanged } from "rxjs/operators" | import { pluck, distinctUntilChanged } from "rxjs/operators" | |||
import DispatchingStore, { defineDispatchers } from "./DispatchingStore" | import DispatchingStore, { defineDispatchers } from "./DispatchingStore" | |||
import { | import { | |||
HoppRealtimeLog, | HoppRealtimeLog, | |||
HoppRealtimeLogLine, | HoppRealtimeLogLine, | |||
} from "~/helpers/types/HoppRealtimeLog" | } from "~/helpers/types/HoppRealtimeLog" | |||
import { SSEConnection } from "~/helpers/realtime/SSEConnection" | ||||
type HoppSSERequest = { | type HoppSSERequest = { | |||
endpoint: string | endpoint: string | |||
eventType: string | eventType: string | |||
} | } | |||
type HoppSSESession = { | type HoppSSESession = { | |||
request: HoppSSERequest | request: HoppSSERequest | |||
connectingState: boolean | ||||
connectionState: boolean | ||||
log: HoppRealtimeLog | log: HoppRealtimeLog | |||
socket: EventSource | null | socket: SSEConnection | |||
} | } | |||
const defaultSSERequest: HoppSSERequest = { | const defaultSSERequest: HoppSSERequest = { | |||
endpoint: "https://express-eventsource.herokuapp.com/events", | endpoint: "https://express-eventsource.herokuapp.com/events", | |||
eventType: "data", | eventType: "data", | |||
} | } | |||
const defaultSSESession: HoppSSESession = { | const defaultSSESession: HoppSSESession = { | |||
request: defaultSSERequest, | request: defaultSSERequest, | |||
connectionState: false, | socket: new SSEConnection(), | |||
connectingState: false, | ||||
socket: null, | ||||
log: [], | log: [], | |||
} | } | |||
const dispatchers = defineDispatchers({ | const dispatchers = defineDispatchers({ | |||
setRequest( | setRequest( | |||
_: HoppSSESession, | _: HoppSSESession, | |||
{ newRequest }: { newRequest: HoppSSERequest } | { newRequest }: { newRequest: HoppSSERequest } | |||
) { | ) { | |||
return { | return { | |||
request: newRequest, | request: newRequest, | |||
skipping to change at line 59 | skipping to change at line 56 | |||
} | } | |||
}, | }, | |||
setEventType(curr: HoppSSESession, { newType }: { newType: string }) { | setEventType(curr: HoppSSESession, { newType }: { newType: string }) { | |||
return { | return { | |||
request: { | request: { | |||
endpoint: curr.request.endpoint, | endpoint: curr.request.endpoint, | |||
eventType: newType, | eventType: newType, | |||
}, | }, | |||
} | } | |||
}, | }, | |||
setSocket(_: HoppSSESession, { socket }: { socket: EventSource }) { | setSocket(_: HoppSSESession, { socket }: { socket: SSEConnection }) { | |||
return { | return { | |||
socket, | socket, | |||
} | } | |||
}, | }, | |||
setConnectionState(_: HoppSSESession, { state }: { state: boolean }) { | ||||
return { | ||||
connectionState: state, | ||||
} | ||||
}, | ||||
setConnectingState(_: HoppSSESession, { state }: { state: boolean }) { | ||||
return { | ||||
connectingState: state, | ||||
} | ||||
}, | ||||
setLog(_: HoppSSESession, { log }: { log: HoppRealtimeLog }) { | setLog(_: HoppSSESession, { log }: { log: HoppRealtimeLog }) { | |||
return { | return { | |||
log, | log, | |||
} | } | |||
}, | }, | |||
addLogLine(curr: HoppSSESession, { line }: { line: HoppRealtimeLogLine }) { | addLogLine(curr: HoppSSESession, { line }: { line: HoppRealtimeLogLine }) { | |||
return { | return { | |||
log: [...curr.log, line], | log: [...curr.log, line], | |||
} | } | |||
}, | }, | |||
skipping to change at line 115 | skipping to change at line 102 | |||
export function setSSEEventType(newType: string) { | export function setSSEEventType(newType: string) { | |||
SSESessionStore.dispatch({ | SSESessionStore.dispatch({ | |||
dispatcher: "setEventType", | dispatcher: "setEventType", | |||
payload: { | payload: { | |||
newType, | newType, | |||
}, | }, | |||
}) | }) | |||
} | } | |||
export function setSSESocket(socket: EventSource) { | export function setSSESocket(socket: SSEConnection) { | |||
SSESessionStore.dispatch({ | SSESessionStore.dispatch({ | |||
dispatcher: "setSocket", | dispatcher: "setSocket", | |||
payload: { | payload: { | |||
socket, | socket, | |||
}, | }, | |||
}) | }) | |||
} | } | |||
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) { | export function setSSELog(log: HoppRealtimeLog) { | |||
SSESessionStore.dispatch({ | SSESessionStore.dispatch({ | |||
dispatcher: "setLog", | dispatcher: "setLog", | |||
payload: { | payload: { | |||
log, | log, | |||
}, | }, | |||
}) | }) | |||
} | } | |||
export function addSSELogLine(line: HoppRealtimeLogLine) { | export function addSSELogLine(line: HoppRealtimeLogLine) { | |||
skipping to change at line 179 | skipping to change at line 149 | |||
export const SSEEventType$ = SSESessionStore.subject$.pipe( | export const SSEEventType$ = SSESessionStore.subject$.pipe( | |||
pluck("request", "eventType"), | pluck("request", "eventType"), | |||
distinctUntilChanged() | distinctUntilChanged() | |||
) | ) | |||
export const SSEConnectingState$ = SSESessionStore.subject$.pipe( | export const SSEConnectingState$ = SSESessionStore.subject$.pipe( | |||
pluck("connectingState"), | pluck("connectingState"), | |||
distinctUntilChanged() | distinctUntilChanged() | |||
) | ) | |||
export const SSEConnectionState$ = SSESessionStore.subject$.pipe( | ||||
pluck("connectionState"), | ||||
distinctUntilChanged() | ||||
) | ||||
export const SSESocket$ = SSESessionStore.subject$.pipe( | export const SSESocket$ = SSESessionStore.subject$.pipe( | |||
pluck("socket"), | pluck("socket"), | |||
distinctUntilChanged() | distinctUntilChanged() | |||
) | ) | |||
export const SSELog$ = SSESessionStore.subject$.pipe( | export const SSELog$ = SSESessionStore.subject$.pipe( | |||
pluck("log"), | pluck("log"), | |||
distinctUntilChanged() | distinctUntilChanged() | |||
) | ) | |||
End of changes. 9 change blocks. | ||||
40 lines changed or deleted | 5 lines changed or added |