/** * A transaction is created for every change on the Yjs model. It is possible * to bundle changes on the Yjs model in a single transaction to * minimize the number on messages sent and the number of observer calls. * If possible the user of this library should bundle as many changes as * possible. Here is an example to illustrate the advantages of bundling: * * @example * const map = y.define('map', YMap) * // Log content when change is triggered * map.observe(() => { * console.log('change triggered') * }) * // Each change on the map type triggers a log message: * map.set('a', 0) // => "change triggered" * map.set('b', 0) // => "change triggered" * // When put in a transaction, it will trigger the log after the transaction: * y.transact(() => { * map.set('a', 1) * map.set('b', 1) * }) // => "change triggered" * * @public */ export class Transaction { /** * @param {Doc} doc * @param {any} origin * @param {boolean} local */ constructor(doc: Doc, origin: any, local: boolean); /** * The Yjs instance. * @type {Doc} */ doc: Doc; /** * Describes the set of deleted items by ids * @type {DeleteSet} */ deleteSet: DeleteSet; /** * Holds the state before the transaction started. * @type {Map} */ beforeState: Map; /** * Holds the state after the transaction. * @type {Map} */ afterState: Map; /** * All types that were directly modified (property added or child * inserted/deleted). New types are not included in this Set. * Maps from type to parentSubs (`item.parentSub = null` for YArray) * @type {Map,Set>} */ changed: Map, Set>; /** * Stores the events for the types that observe also child elements. * It is mainly used by `observeDeep`. * @type {Map,Array>} */ changedParentTypes: Map, Array>; /** * @type {Array} */ _mergeStructs: Array; /** * @type {any} */ origin: any; /** * Stores meta information on the transaction * @type {Map} */ meta: Map; /** * Whether this change originates from this doc. * @type {boolean} */ local: boolean; /** * @type {Set} */ subdocsAdded: Set; /** * @type {Set} */ subdocsRemoved: Set; /** * @type {Set} */ subdocsLoaded: Set; } export function writeUpdateMessageFromTransaction(encoder: UpdateEncoderV1 | UpdateEncoderV2, transaction: Transaction): boolean; export function nextID(transaction: Transaction): import("./ID.js").ID; export function addChangedTypeToTransaction(transaction: Transaction, type: AbstractType, parentSub: string | null): void; export function tryGc(ds: DeleteSet, store: StructStore, gcFilter: (arg0: Item) => boolean): void; export function transact(doc: Doc, f: (arg0: Transaction) => void, origin?: any, local?: boolean): void; import { Doc } from "./Doc.js"; import { DeleteSet } from "./DeleteSet.js"; import { AbstractType } from "../types/AbstractType.js"; import { YEvent } from "./YEvent.js"; import { AbstractStruct } from "../structs/AbstractStruct.js"; import { UpdateEncoderV1 } from "./UpdateEncoder.js"; import { UpdateEncoderV2 } from "./UpdateEncoder.js"; import { StructStore } from "./StructStore.js"; import { Item } from "../structs/Item.js";