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.
Type Parameters
Section titled “Type Parameters”T = void
Remarks
Section titled “Remarks”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 valuefalse- 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
voidif 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
Example
Section titled “Example”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.