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>
|
<dd>Emitted before each transaction.</dd>
|
||||||
<b><code>on('afterTransaction', function(Y.Transaction, Y.Doc):void)</code></b>
|
<b><code>on('afterTransaction', function(Y.Transaction, Y.Doc):void)</code></b>
|
||||||
<dd>Emitted after each transaction.</dd>
|
<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>
|
</dl>
|
||||||
|
|
||||||
### Document Updates
|
### Document Updates
|
||||||
|
@ -337,6 +337,7 @@ const cleanupTransactions = (transactionCleanups, i) => {
|
|||||||
}
|
}
|
||||||
if (transactionCleanups.length <= i + 1) {
|
if (transactionCleanups.length <= i + 1) {
|
||||||
doc._transactionCleanups = []
|
doc._transactionCleanups = []
|
||||||
|
doc.emit('afterAllTransactions', [doc, transactionCleanups])
|
||||||
} else {
|
} else {
|
||||||
cleanupTransactions(transactionCleanups, i + 1)
|
cleanupTransactions(transactionCleanups, i + 1)
|
||||||
}
|
}
|
||||||
@ -360,6 +361,9 @@ export const transact = (doc, f, origin = null, local = true) => {
|
|||||||
initialCall = true
|
initialCall = true
|
||||||
doc._transaction = new Transaction(doc, origin, local)
|
doc._transaction = new Transaction(doc, origin, local)
|
||||||
transactionCleanups.push(doc._transaction)
|
transactionCleanups.push(doc._transaction)
|
||||||
|
if (transactionCleanups.length === 1) {
|
||||||
|
doc.emit('beforeAllTransactions', [doc])
|
||||||
|
}
|
||||||
doc.emit('beforeTransaction', [doc._transaction, doc])
|
doc.emit('beforeTransaction', [doc._transaction, doc])
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -293,7 +293,7 @@ const tryGc = () => {
|
|||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
*/
|
*/
|
||||||
export const testLargeFragmentedDocument = tc => {
|
export const testLargeFragmentedDocument = tc => {
|
||||||
const itemsToInsert = 5000000
|
const itemsToInsert = 1000000
|
||||||
let update = /** @type {any} */ (null)
|
let update = /** @type {any} */ (null)
|
||||||
;(() => {
|
;(() => {
|
||||||
const doc1 = new Y.Doc()
|
const doc1 = new Y.Doc()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user