dify/web/app/components/workflow/context.tsx
zxhlyh efe5db38ee
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
Chore/slice workflow (#18351)
2025-04-18 13:59:12 +08:00

30 lines
911 B
TypeScript

import {
createContext,
useRef,
} from 'react'
import {
createWorkflowStore,
} from './store'
import type { StateCreator } from 'zustand'
import type { WorkflowSliceShape } from '@/app/components/workflow-app/store/workflow/workflow-slice'
type WorkflowStore = ReturnType<typeof createWorkflowStore>
export const WorkflowContext = createContext<WorkflowStore | null>(null)
export type WorkflowProviderProps = {
children: React.ReactNode
injectWorkflowStoreSliceFn?: StateCreator<WorkflowSliceShape>
}
export const WorkflowContextProvider = ({ children, injectWorkflowStoreSliceFn }: WorkflowProviderProps) => {
const storeRef = useRef<WorkflowStore | undefined>(undefined)
if (!storeRef.current)
storeRef.current = createWorkflowStore({ injectWorkflowStoreSliceFn })
return (
<WorkflowContext.Provider value={storeRef.current}>
{children}
</WorkflowContext.Provider>
)
}