TinyBase logoTinyBase β

DidSetRowCallback

The DidSetRowCallback type describes a function called after a Row is changed during a transaction, and after mutator listeners have fired.

(
  tableId: Id,
  rowId: Id,
  oldRow: Row,
  newRow: Row,
): Row
TypeDescription
tableIdId

The Id of the Table containing the changed Row.

rowIdId

The Id of the Row that was changed.

oldRowRow

The Row as it was at the start of the transaction.

newRowRow

The Row as it is now, after all cell writes including those made by mutating listeners.

returnsRow

The Row to use as the final state.

Unlike the willSet* callbacks, which intercept writes as they happen, didSetRow fires once per touched Row after all cell writes in the transaction have completed. This means multiple cell changes to the same Row within a single transaction result in just one didSetRow call, with the full before-transaction and after-transaction Row states.

The callback receives the Table Id, Row Id, the Row as it was at the start of the transaction (oldRow), and the Row as it is now (newRow). It must return a Row:

  • newRow to accept the changes.
  • a different [Row](/api/store/type-aliases/store/row/) to replace the final state.
  • oldRow to revert all changes to the Row.
  • an empty object to delete the Row.

Multiple DidSetRowCallback functions can be registered for the same table and they will be called sequentially, each receiving the Row returned by the previous callback. The chain never short-circuits: all registered callbacks always run.

Note that addDidSetRowCallback is table-scoped: you must specify the table Id when registering. Callbacks are only invoked for rows in the specified table, keeping overhead to zero for other tables.

Since

v8.0.0