nit
This commit is contained in:
@@ -54,36 +54,39 @@ export function useSyncConnectionStatus(
|
||||
state: NodeConnectionStatusState
|
||||
): void {
|
||||
const ctx = useContext(ConnectionPathContext)
|
||||
const ctxRef = useRef(ctx)
|
||||
ctxRef.current = ctx
|
||||
const { updating, error, paused } = state
|
||||
const prevRef = useRef({ updating: false, error: false, paused: false })
|
||||
|
||||
useEffect(() => {
|
||||
const pathCtx = ctxRef.current
|
||||
const prev = prevRef.current
|
||||
const nowUpdating = Boolean(updating)
|
||||
const nowError = Boolean(error)
|
||||
const nowPaused = Boolean(paused)
|
||||
|
||||
if (prev.updating !== nowUpdating) {
|
||||
if (nowUpdating) ctx?.startConnectionPathUpdate?.(nodeId)
|
||||
else ctx?.endConnectionPathUpdate?.(nodeId)
|
||||
if (nowUpdating) pathCtx?.startConnectionPathUpdate?.(nodeId)
|
||||
else pathCtx?.endConnectionPathUpdate?.(nodeId)
|
||||
prev.updating = nowUpdating
|
||||
}
|
||||
if (prev.error !== nowError) {
|
||||
if (nowError) ctx?.addConnectionPathError?.(nodeId)
|
||||
else ctx?.removeConnectionPathError?.(nodeId)
|
||||
if (nowError) pathCtx?.addConnectionPathError?.(nodeId)
|
||||
else pathCtx?.removeConnectionPathError?.(nodeId)
|
||||
prev.error = nowError
|
||||
}
|
||||
if (prev.paused !== nowPaused) {
|
||||
if (nowPaused) ctx?.addConnectionPathPausedNode?.(nodeId)
|
||||
else ctx?.removeConnectionPathPausedNode?.(nodeId)
|
||||
if (nowPaused) pathCtx?.addConnectionPathPausedNode?.(nodeId)
|
||||
else pathCtx?.removeConnectionPathPausedNode?.(nodeId)
|
||||
prev.paused = nowPaused
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (prevRef.current.updating) ctx?.endConnectionPathUpdate?.(nodeId)
|
||||
if (prevRef.current.error) ctx?.removeConnectionPathError?.(nodeId)
|
||||
if (prevRef.current.paused) ctx?.removeConnectionPathPausedNode?.(nodeId)
|
||||
if (prevRef.current.updating) pathCtx?.endConnectionPathUpdate?.(nodeId)
|
||||
if (prevRef.current.error) pathCtx?.removeConnectionPathError?.(nodeId)
|
||||
if (prevRef.current.paused) pathCtx?.removeConnectionPathPausedNode?.(nodeId)
|
||||
prevRef.current = { updating: false, error: false, paused: false }
|
||||
}
|
||||
}, [nodeId, updating, error, paused, ctx])
|
||||
}, [nodeId, updating, error, paused])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user