mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-05 05:00:39 +08:00
36 lines
827 B
TypeScript
36 lines
827 B
TypeScript
import { useWorkflowStore } from '../store'
|
|
const useCurrentVars = () => {
|
|
const workflowStore = useWorkflowStore()
|
|
const {
|
|
currentNodes,
|
|
getCurrentVar,
|
|
setCurrentVar,
|
|
clearCurrentVars,
|
|
clearCurrentNodeVars,
|
|
getLastRunVar,
|
|
getLastRunInfos,
|
|
} = workflowStore.getState()
|
|
|
|
const isVarChanged = (nodeId: string, key: string) => {
|
|
return getCurrentVar(nodeId, key) !== getLastRunVar(nodeId, key)
|
|
}
|
|
|
|
const resetToLastRunVar = (nodeId: string, key: string) => {
|
|
const lastRunVar = getLastRunVar(nodeId, key)
|
|
if (lastRunVar)
|
|
setCurrentVar(nodeId, key, lastRunVar)
|
|
}
|
|
|
|
return {
|
|
currentVars: currentNodes,
|
|
getLastRunInfos,
|
|
isVarChanged,
|
|
clearCurrentVars,
|
|
clearCurrentNodeVars,
|
|
setCurrentVar,
|
|
resetToLastRunVar,
|
|
}
|
|
}
|
|
|
|
export default useCurrentVars
|