Skip to content
Document Authoring DA  API Docs v1.10.0
npmGitHub

TransactionResultNEW

TransactionResult<T> = undefined | boolean | { commit: boolean; result: T; } | Promise<undefined | boolean | { commit: boolean; result: T; }>

Return type for transaction callbacks that control whether changes are committed and optionally return a result.

T = void

TransactionResult is returned from TransactionCallback functions to control the outcome of a document transaction. It determines whether the changes made during the transaction should be committed to the document and optionally provides a result value to the transaction caller.

Commit behavior:

  • true - Commits the transaction
  • { commit: true } - Commits the transaction
  • { commit: true, result: T } - Commits the transaction and returns a result value
  • false - Does not commit the transaction
  • { commit: false } - Does not commit the transaction
  • { commit: false, result: T } - Does not commit the transaction but still returns a result value

Async support: All return values can be wrapped in a Promise, allowing async transaction callbacks.

Type parameter T:

  • Defaults to void if no result is needed
  • Set to a specific type when you want to return a value from the transaction
  • The result can be returned regardless of whether the transaction commits or not

Explicit commit:

const r = await doc.transaction(async ({ draft }) => {
const replacementCount = draft.replaceText(/old/g, 'new');
return { commit: true, result: replacementCount };
});

TransactionCallback for the callback signature that returns this result type.