What's the difference between `beforeAllTransactions` and `beforeTransaction`?

Thanks for the great work on yjs :grinning:!

But, I’m confused with the transact behaviour.

According to the documentation:

beforeTransaction: Emitted before each transaction.
beforeAllTransactions: Transactions can be nested (e.g. when an event within a transaction calls another transaction). Emitted before the first transaction.

I’ve tested on nested transactions, it’ll always trigger one beforeAllTransactions event and one beforeTransaction event.

I’ve digged a little bit on the transact code:

export const transact = (doc, f, origin = null, local = true) => {
  const transactionCleanups = doc._transactionCleanups
  let initialCall = false
  if (doc._transaction === null) {
    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 {
    f(doc._transaction)
  } finally {
    if (initialCall && transactionCleanups[0] === doc._transaction) {
      cleanupTransactions(transactionCleanups, 0)
    }
  }
}

When will transactionCleanups.length not be 1?