| 174 | } |
| 175 | |
| 176 | export function createBatchedUpdater(set: (updates: Partial<WorkflowDiffState>) => void) { |
| 177 | let updateTimer: NodeJS.Timeout | null = null |
| 178 | const UPDATE_DEBOUNCE_MS = 16 |
| 179 | let pendingUpdates: Partial<WorkflowDiffState> = {} |
| 180 | return (updates: Partial<WorkflowDiffState>) => { |
| 181 | Object.assign(pendingUpdates, updates) |
| 182 | if (updateTimer) { |
| 183 | clearTimeout(updateTimer) |
| 184 | } |
| 185 | updateTimer = setTimeout(() => { |
| 186 | set(pendingUpdates) |
| 187 | pendingUpdates = {} |
| 188 | updateTimer = null |
| 189 | }, UPDATE_DEBOUNCE_MS) |
| 190 | } |
| 191 | } |