implement before/afterAllTransactions

This commit is contained in:
Kevin Jahns 2020-08-07 17:47:20 +02:00
parent 68109b033f
commit 6f9a2c9df7
3 changed files with 9 additions and 1 deletions

View File

@ -597,6 +597,10 @@ peers. You can apply document updates in any order and multiple times.
<dd>Emitted before each transaction.</dd>
<b><code>on('afterTransaction', function(Y.Transaction, Y.Doc):void)</code></b>
<dd>Emitted after each transaction.</dd>
<b><code>on('beforeAllTransactions', function(Y.Doc):void)</code></b>
<dd>Transactions can be nested (e.g. when an event within a transaction calls another transaction). Emitted before the first transaction.</dd>
<b><code>on('afterAllTransactions', function(Y.Doc, Array&lt;Y.Transaction&gt;):void)</code></b>
<dd>Emitted after the last transaction is cleaned up.</dd>
</dl>
### Document Updates

View File

@ -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 {

View File

@ -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()