* Execute collection operations within this transaction * @param callback - Synchronous function containing collection operations to group together. * The transaction context is active only for the synchronous duration of this callback. * Async work should happen in `mutationFn`; collection
(callback: () => void)
| 294 | * await tx.commit() |
| 295 | */ |
| 296 | mutate(callback: () => void): Transaction<T> { |
| 297 | if (this.state !== `pending`) { |
| 298 | throw new TransactionNotPendingMutateError() |
| 299 | } |
| 300 | |
| 301 | registerTransaction(this) |
| 302 | |
| 303 | try { |
| 304 | callback() |
| 305 | } finally { |
| 306 | unregisterTransaction(this) |
| 307 | } |
| 308 | |
| 309 | if (this.autoCommit) { |
| 310 | this.commit().catch(() => { |
| 311 | // Errors from autoCommit are handled via isPersisted.promise |
| 312 | // This catch prevents unhandled promise rejections |
| 313 | }) |
| 314 | } |
| 315 | |
| 316 | return this |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * Apply new mutations to this transaction, intelligently merging with existing mutations |
no test coverage detected