diff --git a/src/ExecutionSimulator.tsx b/src/ExecutionSimulator.tsx index 4e365de..c99b422 100644 --- a/src/ExecutionSimulator.tsx +++ b/src/ExecutionSimulator.tsx @@ -10,13 +10,25 @@ import { Button } from '@/components/ui/button'; import { Play, Pause, BookOpen } from 'lucide-react'; import { CanvasTimeline, TimelineEvent, PatternType } from './CanvasTimeline'; import { DocsModal } from './DocsModal'; -import { GithubIcon } from '@/components/GithubIcon'; +import { StrategyConfig, StrategyConfiguration } from './StrategyConfig'; +import { GithubIcon } from "@/components/GithubIcon"; + +const DEFAULT_STRATEGY_CONFIG: StrategyConfiguration = { + debounceWait: 500, + throttleWait: 500, + rateLimitCount: 3, + rateLimitWindow: 2000, + batchMaxSize: 5, + batchMaxWait: 1000, + queueConcurrency: 1, +}; export function ExecutionSimulator() { const [events, setEvents] = useState([]); const [windowMs, setWindowMs] = useState(6000); const [isPaused, setIsPaused] = useState(false); const [showDoc, setShowDoc] = useState(false); + const [strategyConfig, setStrategyConfig] = useState(DEFAULT_STRATEGY_CONFIG); // Refs for tracking pause duration offsets const isPausedRef = useRef(isPaused); @@ -49,19 +61,19 @@ export function ExecutionSimulator() { // 1. Debounce const handleDebounce = useDebouncedCallback( useCallback((tTime?: number) => logEvent('debounce', tTime), [logEvent]), - { wait: 500 } + { wait: strategyConfig.debounceWait } ); // 2. Throttle const handleThrottle = useThrottledCallback( useCallback((tTime?: number) => logEvent('throttle', tTime), [logEvent]), - { wait: 500 } + { wait: strategyConfig.throttleWait } ); // 3. Rate Limit const handleRateLimit = useRateLimitedCallback( useCallback((tTime?: number) => logEvent('rateLimit', tTime), [logEvent]), - { limit: 3, window: 2000 } + { limit: strategyConfig.rateLimitCount, window: strategyConfig.rateLimitWindow } ); // 4. Queue @@ -77,7 +89,7 @@ export function ExecutionSimulator() { await new Promise(resolve => setTimeout(resolve, 400)); }, [logEvent]); - const handleQueue = useAsyncQueuer(processQueue, { concurrency: 1, started: true }); + const handleQueue = useAsyncQueuer(processQueue, { concurrency: strategyConfig.queueConcurrency, started: true }); // 5. Batch const processBatch = useCallback(async (items: string[]) => { @@ -93,7 +105,11 @@ export function ExecutionSimulator() { logEvent('batch', tTime); }, [logEvent]); - const handleBatch = useBatcher(processBatch, { maxSize: 5, wait: 1000, started: true }); + const handleBatch = useBatcher(processBatch, { + maxSize: strategyConfig.batchMaxSize, + wait: strategyConfig.batchMaxWait, + started: true, + }); // The Master Trigger const triggerAll = () => { @@ -126,7 +142,8 @@ export function ExecutionSimulator() { Execution Timing Simulator

- Click rapidly to see how different architectural patterns handle high-frequency events. + Click rapidly to see how different architectural patterns handle + high-frequency events.

@@ -142,7 +159,7 @@ export function ExecutionSimulator() { GitHub - - - -