implement before/afterAllTransactions
This commit is contained in:
parent
68109b033f
commit
6f9a2c9df7
@ -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<Y.Transaction>):void)</code></b>
|
||||
<dd>Emitted after the last transaction is cleaned up.</dd>
|
||||
</dl>
|
||||
|
||||
### Document Updates
|
||||
|
@ -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 {
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user