yjs/src/Transaction.js
2017-11-07 22:44:43 -08:00

28 lines
800 B
JavaScript

export default class Transaction {
constructor (y) {
this.y = y
// types added during transaction
this.newTypes = new Set()
// changed types (does not include new types)
// maps from type to parentSubs (item._parentSub = null for array elements)
this.changedTypes = new Map()
this.deletedStructs = new Set()
this.beforeState = new Map()
this.changedParentTypes = new Map()
}
}
export function transactionTypeChanged (y, type, sub) {
if (type !== y && !type._deleted && !y._transaction.newTypes.has(type)) {
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)
}
}