@tour-kit/checklistsUtilities
Dependency Utilities
Dependency resolution utilities: topological sort, circular reference detection, and prerequisite task validation functions
Dependency Utilities
Functions for resolving and validating task dependencies.
canCompleteTask
Check if a task's dependencies are satisfied:
import { canCompleteTask } from '@tour-kit/checklists';
const completed = new Set(['step1', 'step2']);
const task = { id: 'step3', dependsOn: ['step1', 'step2'] };
const canComplete = canCompleteTask(task, completed, allTasks);
// trueresolveTaskDependencies
Get ordered list of task dependencies:
import { resolveTaskDependencies } from '@tour-kit/checklists';
const deps = resolveTaskDependencies('step3', allTasks);
// ['step1', 'step2']hasCircularDependency
Detect circular dependencies:
import { hasCircularDependency } from '@tour-kit/checklists';
const tasks = [
{ id: 'a', dependsOn: ['b'] },
{ id: 'b', dependsOn: ['a'] }, // Circular!
];
if (hasCircularDependency(tasks)) {
throw new Error('Circular dependency detected');
}Always validate dependencies in development to catch circular references early.
Example: Dependency Graph
function DependencyGraph({ tasks }) {
const deps = {};
tasks.forEach((task) => {
deps[task.id] = resolveTaskDependencies(task.id, tasks);
});
return (
<div>
{Object.entries(deps).map(([taskId, dependencies]) => (
<div key={taskId}>
<strong>{taskId}</strong>
{dependencies.length > 0 && (
<ul>
{dependencies.map((depId) => (
<li key={depId}>{depId}</li>
))}
</ul>
)}
</div>
))}
</div>
);
}Related
- ChecklistProvider - Handles dependencies automatically
- useTask - Check if task is locked