Async Commit Types

Import from @zvndev/yable-core:

CellPatch

interface CellPatch<TData, TValue = unknown> {
  rowId: string
  columnId: string
  /** The value the user typed. */
  value: TValue
  /** The most recent saved value at the moment we dispatched. */
  previousValue: TValue
  /** The full row snapshot at dispatch time. */
  row: TData
  /** Aborts when the user starts a new commit on the same cell. */
  signal: AbortSignal
}

CellStatus

type CellStatus = 'idle' | 'pending' | 'error' | 'conflict'

OnCommitFn

type OnCommitFn<TData> = (
  patches: CellPatch<TData>[]
) => Promise<CommitResult> | CommitResult

CommitResult

type CommitResult = void | {
  resolved?: Record<string, Record<string, unknown>>
}

CommitError

class CommitError extends Error {
  cells: CommitErrorCells
  constructor(cells: CommitErrorCells, message?: string)
}

// rowId -> columnId -> human-readable error message
type CommitErrorCells = Record<string, Record<string, string>>

Throw from onCommit to mark specific cells as failed. Throw a generic Error to fail all cells in the batch.

CommitRecord

interface CommitRecord {
  status: 'pending' | 'error' | 'conflict'
  pendingValue: unknown
  previousValue: unknown
  opId: number
  errorMessage?: string     // only when status === 'error'
  conflictWith?: unknown    // only when status === 'conflict'
  abortController: AbortController
}

Table Options (Async Commits)

OptionTypeDefaultDescription
onCommitOnCommitFn<TData>--Async handler for saving cell edits. Resolve = success, throw = failure.
autoCommitbooleantrueFire onCommit after each cell edit. If false, batch edits until table.commit().
rowCommitRetryMode'failed' | 'batch''failed''failed': retry only failed cells. 'batch': retry entire original batch.

Per-Column Commit

Columns can define their own commit handler that takes precedence over onCommit:

columnHelper.accessor('price', {
  commit: async (patch: CellPatch) => {
    await updatePrice(patch.rowId, patch.value)
  },
})