MCPcopy Index your code
hub / github.com/simstudioai/sim / bumpRunState

Function bumpRunState

apps/sim/hooks/queries/tables.ts:351–374  ·  view source on GitHub ↗

Optimistically reflect a run on the "X running" badge + per-row gutter Stop * instantly (the optimistic stamp eats the dispatcher's `pending` SSE, so * `applyCell` never bumps the count, and the server's dispatch-scope count * isn't live until the first window). `stampedByRow` drives the per-r

(
  queryClient: ReturnType<typeof useQueryClient>,
  tableId: string,
  stampedByRow: Record<string, number>,
  cellCountDelta?: number
)

Source from the content-addressed store, hash-verified

349 * scope (rows × groups) for Run-all so it matches the server, or omit to use
350 * the stamped total. Returns the prior snapshot for rollback. */
351function bumpRunState(
352 queryClient: ReturnType<typeof useQueryClient>,
353 tableId: string,
354 stampedByRow: Record<string, number>,
355 cellCountDelta?: number
356): { snapshot: TableRunState | undefined } | null {
357 const stampedTotal = Object.values(stampedByRow).reduce((s, n) => s + n, 0)
358 const countDelta = cellCountDelta ?? stampedTotal
359 if (countDelta === 0 && stampedTotal === 0) return null
360 const snapshot = queryClient.getQueryData<TableRunState>(tableKeys.activeDispatches(tableId))
361 queryClient.setQueryData<TableRunState>(tableKeys.activeDispatches(tableId), (prev) => {
362 const base = prev ?? { dispatches: [], runningCellCount: 0, runningByRowId: {} }
363 const nextByRow = { ...base.runningByRowId }
364 for (const [rid, n] of Object.entries(stampedByRow)) {
365 nextByRow[rid] = (nextByRow[rid] ?? 0) + n
366 }
367 return {
368 ...base,
369 runningCellCount: base.runningCellCount + countDelta,
370 runningByRowId: nextByRow,
371 }
372 })
373 return { snapshot }
374}
375
376/**
377 * Aggregate live state for a table: active dispatches (drives the "about to

Callers 4

useCreateTableRowFunction · 0.85
useUpdateTableRowFunction · 0.85
useBatchUpdateTableRowsFunction · 0.85
useRunColumnFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected