mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-06 01:06:05 +08:00
feat: use current vars hooks
This commit is contained in:
parent
625a8cc371
commit
36724a2b47
31
web/app/components/workflow/hooks/use-current-vars.ts
Normal file
31
web/app/components/workflow/hooks/use-current-vars.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { useCurrentVarsStore } from '../current-vars-store/store'
|
||||
import { useLastRunStore } from '../last-run-store/store'
|
||||
const useCurrentVars = () => {
|
||||
const currentVars = useCurrentVarsStore(state => state.nodes)
|
||||
const getCurrentVar = useCurrentVarsStore(state => state.getVar)
|
||||
const getLastRunVar = useLastRunStore(state => state.getVar)
|
||||
const setCurrentVar = useCurrentVarsStore(state => state.setVar)
|
||||
const clearCurrentVars = useCurrentVarsStore(state => state.clearVars)
|
||||
const clearNodeVars = useCurrentVarsStore(state => state.clearNodeVars)
|
||||
|
||||
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,
|
||||
isVarChanged,
|
||||
clearCurrentVars,
|
||||
clearNodeVars,
|
||||
setCurrentVar,
|
||||
resetToLastRunVar,
|
||||
}
|
||||
}
|
||||
|
||||
export default useCurrentVars
|
Loading…
x
Reference in New Issue
Block a user