change parameter order of transaction events

This commit is contained in:
Kevin Jahns
2019-04-19 23:36:00 +02:00
parent cd82de7742
commit fa3c92f44c
3 changed files with 34 additions and 12 deletions

View File

@@ -133,7 +133,7 @@ export const transact = (y, f) => {
if (y._transaction === null) {
initialCall = true
y._transaction = new Transaction(y)
y.emit('beforeTransaction', [y, y._transaction])
y.emit('beforeTransaction', [y._transaction, y])
}
const transaction = y._transaction
try {
@@ -141,7 +141,7 @@ export const transact = (y, f) => {
} finally {
if (initialCall) {
y._transaction = null
y.emit('beforeObserverCalls', [y, y._transaction])
y.emit('beforeObserverCalls', [transaction, y])
// emit change events on changed types
transaction.changed.forEach((subs, itemtype) => {
itemtype._callObserver(transaction, subs)
@@ -167,7 +167,7 @@ export const transact = (y, f) => {
const ds = transaction.deleteSet
// replace deleted items with ItemDeleted / GC
sortAndMergeDeleteSet(ds)
y.emit('afterTransaction', [y, transaction])
y.emit('afterTransaction', [transaction, y])
for (const [client, deleteItems] of ds.clients) {
/**
* @type {Array<AbstractStruct>}
@@ -238,7 +238,7 @@ export const transact = (y, f) => {
tryToMergeWithLeft(structs, replacedStructPos)
}
}
y.emit('afterTransactionCleanup', [y, transaction])
y.emit('afterTransactionCleanup', [transaction, y])
}
}
}

View File

@@ -27,6 +27,7 @@ export class Y extends Observable {
*/
constructor (conf = {}) {
super()
// todo: change to clientId
this.clientID = random.uint32()
/**
* @type {Map<string, AbstractType<YEvent>>}
@@ -151,4 +152,18 @@ export class Y extends Observable {
this.emit('destroyed', [true])
super.destroy()
}
/**
* @param {string} eventName
* @param {function} f
*/
on (eventName, f) {
super.on(eventName, f)
}
/**
* @param {string} eventName
* @param {function} f
*/
off (eventName, f) {
super.off(eventName, f)
}
}