diff --git a/README.md b/README.md
index d859b7f5..09857eae 100644
--- a/README.md
+++ b/README.md
@@ -597,6 +597,10 @@ peers. You can apply document updates in any order and multiple times.
Emitted before each transaction.
on('afterTransaction', function(Y.Transaction, Y.Doc):void)
Emitted after each transaction.
+ on('beforeAllTransactions', function(Y.Doc):void)
+ Transactions can be nested (e.g. when an event within a transaction calls another transaction). Emitted before the first transaction.
+ on('afterAllTransactions', function(Y.Doc, Array<Y.Transaction>):void)
+ Emitted after the last transaction is cleaned up.
### Document Updates
diff --git a/src/utils/Transaction.js b/src/utils/Transaction.js
index c09579e9..6be4e8ee 100644
--- a/src/utils/Transaction.js
+++ b/src/utils/Transaction.js
@@ -337,6 +337,7 @@ const cleanupTransactions = (transactionCleanups, i) => {
}
if (transactionCleanups.length <= i + 1) {
doc._transactionCleanups = []
+ doc.emit('afterAllTransactions', [doc, transactionCleanups])
} else {
cleanupTransactions(transactionCleanups, i + 1)
}
@@ -360,6 +361,9 @@ export const transact = (doc, f, origin = null, local = true) => {
initialCall = true
doc._transaction = new Transaction(doc, origin, local)
transactionCleanups.push(doc._transaction)
+ if (transactionCleanups.length === 1) {
+ doc.emit('beforeAllTransactions', [doc])
+ }
doc.emit('beforeTransaction', [doc._transaction, doc])
}
try {
diff --git a/tests/y-text.tests.js b/tests/y-text.tests.js
index a517e7c3..0083630d 100644
--- a/tests/y-text.tests.js
+++ b/tests/y-text.tests.js
@@ -293,7 +293,7 @@ const tryGc = () => {
* @param {t.TestCase} tc
*/
export const testLargeFragmentedDocument = tc => {
- const itemsToInsert = 5000000
+ const itemsToInsert = 1000000
let update = /** @type {any} */ (null)
;(() => {
const doc1 = new Y.Doc()