export type LoadingTaskStatus = 'pending' | 'loading' | 'success' | 'error'; export interface LoadingTask { /** Unique identifier for the task */ id: string; /** Human-readable label */ label: string; /** Current status */ status: LoadingTaskStatus; /** Task dependencies (IDs of tasks that must complete first) */ dependsOn?: string[]; /** Progress percentage (0-100) */ progress?: number; /** Error object if task failed */ error?: Error; } export interface OrchestratorOptions { /** Execution mode: parallel or sequential */ mode?: 'parallel' | 'sequential'; /** Stop all tasks on first error */ stopOnError?: boolean; /** Callback when a task starts */ onTaskStart?: (taskId: string) => void; /** Callback when a task completes successfully */ onTaskComplete?: (taskId: string) => void; /** Callback when a task fails */ onTaskError?: (taskId: string, error: Error) => void; /** Callback when all tasks complete */ onAllComplete?: () => void; } export interface UseLoadingOrchestratorReturn { /** Current state of all tasks */ tasks: LoadingTask[]; /** Start a specific task */ startTask: (taskId: string) => Promise; /** Mark a task as complete */ completeTask: (taskId: string) => void; /** Mark a task as failed */ failTask: (taskId: string, error: Error) => void; /** Update progress for a task */ updateProgress: (taskId: string, progress: number) => void; /** Reset all tasks to pending */ resetTasks: () => void; /** Overall progress (0-100) */ overallProgress: number; /** Whether all tasks are complete */ allComplete: boolean; /** Whether any task has errors */ hasErrors: boolean; } /** * useLoadingOrchestrator - Manage multiple loading states with dependencies * * Coordinates multiple loading tasks with dependency management, progress tracking, * and execution control (parallel or sequential). * * @param initialTasks - Array of loading tasks * @param options - Configuration options * @returns Task state and control functions * * @example * ```tsx * function DataLoader() { * const { * tasks, * startTask, * completeTask, * failTask, * updateProgress, * overallProgress, * } = useLoadingOrchestrator( * [ * { id: 'auth', label: 'Authenticating...', status: 'pending' }, * { id: 'data', label: 'Fetching data...', status: 'pending', dependsOn: ['auth'] }, * { id: 'render', label: 'Rendering...', status: 'pending', dependsOn: ['data'] }, * ], * { * mode: 'sequential', * onAllComplete: () => console.log('All done!'), * } * ); * * const loadAll = async () => { * await startTask('auth'); * // ... perform auth * completeTask('auth'); * * await startTask('data'); * // ... fetch data * completeTask('data'); * }; * * return ( *
* * {tasks.map(task => ( *
{task.label}: {task.status}
* ))} *
* ); * } * ``` */ export declare function useLoadingOrchestrator(initialTasks: LoadingTask[], options?: OrchestratorOptions): UseLoadingOrchestratorReturn; //# sourceMappingURL=useLoadingOrchestrator.d.ts.map