2017-10-22 19:13:03 +02:00
|
|
|
|
2018-03-05 03:03:40 +01:00
|
|
|
/**
|
|
|
|
|
* Changes that are created within a transaction are bundled and sent as one
|
|
|
|
|
* message to the remote peers. This implies that the changes are applied
|
|
|
|
|
* in one flush and at most one {@link YEvent} per type is created.
|
|
|
|
|
*
|
|
|
|
|
* It is best to bundle as many changes in a single Transaction as possible.
|
|
|
|
|
* This way only few changes need to be computed
|
|
|
|
|
*/
|
2017-10-22 19:13:03 +02:00
|
|
|
export default class Transaction {
|
|
|
|
|
constructor (y) {
|
|
|
|
|
this.y = y
|
|
|
|
|
// types added during transaction
|
|
|
|
|
this.newTypes = new Set()
|
|
|
|
|
// changed types (does not include new types)
|
2017-10-30 11:33:00 +01:00
|
|
|
// maps from type to parentSubs (item._parentSub = null for array elements)
|
2017-10-22 19:13:03 +02:00
|
|
|
this.changedTypes = new Map()
|
2017-10-30 11:33:00 +01:00
|
|
|
this.deletedStructs = new Set()
|
|
|
|
|
this.beforeState = new Map()
|
2017-11-07 22:44:43 -08:00
|
|
|
this.changedParentTypes = new Map()
|
2017-10-22 19:13:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function transactionTypeChanged (y, type, sub) {
|
2017-10-28 23:02:48 +02:00
|
|
|
if (type !== y && !type._deleted && !y._transaction.newTypes.has(type)) {
|
2017-10-22 19:13:03 +02:00
|
|
|
const changedTypes = y._transaction.changedTypes
|
|
|
|
|
let subs = changedTypes.get(type)
|
|
|
|
|
if (subs === undefined) {
|
|
|
|
|
// create if it doesn't exist yet
|
|
|
|
|
subs = new Set()
|
|
|
|
|
changedTypes.set(type, subs)
|
|
|
|
|
}
|
|
|
|
|
subs.add(sub)
|
|
|
|
|
}
|
|
|
|
|
}
|