mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
refactor: type event emitter payloads
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-Claude) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@ -61,7 +61,7 @@ const InstructionEditor: FC<Props> = ({
|
||||
)
|
||||
|
||||
const handleInsertVariable = () => {
|
||||
eventEmitter?.emit({ type: PROMPT_EDITOR_INSERT_QUICKLY, instanceId: editorKey } as any)
|
||||
eventEmitter?.emit({ type: PROMPT_EDITOR_INSERT_QUICKLY, instanceId: editorKey })
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@ -157,7 +157,7 @@ const Editor: FC<Props> = ({
|
||||
|
||||
const handleInsertVariable = () => {
|
||||
setFocus()
|
||||
eventEmitter?.emit({ type: PROMPT_EDITOR_INSERT_QUICKLY, instanceId } as any)
|
||||
eventEmitter?.emit({ type: PROMPT_EDITOR_INSERT_QUICKLY, instanceId })
|
||||
}
|
||||
|
||||
const getVarType = useWorkflowVariableType()
|
||||
|
||||
@ -143,7 +143,7 @@ const Right: FC<Props> = ({
|
||||
type: PROMPT_EDITOR_UPDATE_VALUE_BY_EVENT_EMITTER,
|
||||
instanceId: `${nodeId}-chat-workflow-llm-prompt-editor`,
|
||||
payload: res.modified,
|
||||
} as any)
|
||||
})
|
||||
handleHidePromptGenerator()
|
||||
}, [setInputs, blockType, nodeId, node?.data, handleHidePromptGenerator])
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ const VariableInspectTrigger: FC = () => {
|
||||
const handleStop = () => {
|
||||
eventEmitter?.emit({
|
||||
type: EVENT_WORKFLOW_STOP,
|
||||
} as any)
|
||||
})
|
||||
}
|
||||
|
||||
const handleClearAll = () => {
|
||||
|
||||
@ -127,8 +127,7 @@ const VariablesTab: FC<InspectHeaderProps> = (headerProps) => {
|
||||
const { eventEmitter } = useEventEmitterContextContext()
|
||||
|
||||
const onStopListening = useCallback(() => {
|
||||
// eslint-disable-next-line ts/no-explicit-any -- EventEmitter is typed as string but project-wide convention passes { type } objects
|
||||
eventEmitter?.emit({ type: EVENT_WORKFLOW_STOP } as any)
|
||||
eventEmitter?.emit({ type: EVENT_WORKFLOW_STOP })
|
||||
}, [eventEmitter])
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@ -4,7 +4,9 @@ import type { EventEmitter } from 'ahooks/lib/useEventEmitter'
|
||||
import { useEventEmitter } from 'ahooks'
|
||||
import { createContext, useContext } from 'use-context-selector'
|
||||
|
||||
const EventEmitterContext = createContext<{ eventEmitter: EventEmitter<string> | null }>({
|
||||
export type EventPayload = string | ({ type: string } & Record<string, unknown>)
|
||||
|
||||
const EventEmitterContext = createContext<{ eventEmitter: EventEmitter<EventPayload> | null }>({
|
||||
eventEmitter: null,
|
||||
})
|
||||
|
||||
@ -16,7 +18,7 @@ type EventEmitterContextProviderProps = {
|
||||
export const EventEmitterContextProvider = ({
|
||||
children,
|
||||
}: EventEmitterContextProviderProps) => {
|
||||
const eventEmitter = useEventEmitter<string>()
|
||||
const eventEmitter = useEventEmitter<EventPayload>()
|
||||
|
||||
return (
|
||||
<EventEmitterContext.Provider value={{ eventEmitter }}>
|
||||
|
||||
Reference in New Issue
Block a user