# Class Transaction

GoJS® Diagramming Components
version 3.0.13
by Northwoods Software®

A Transaction holds a list of ChangedEvents collected during a transaction, as the value of the read-only changes property.

Start a transaction by calling UndoManager.startTransaction (or Model.startTransaction or Diagram.startTransaction, which call that method). Be sure to finish a transaction with a matching call to UndoManager.commitTransaction (or Model.commitTransaction or Diagram.commitTransaction), or a call to UndoManager.rollbackTransaction (or the same named methods on Model or Diagram).

If you are performing multiple or repeated changes to a model or diagram, surround all of the code with calls to start and commit the transaction -- do not perform repeated calls to start-commit-start-commit. Typically each change caused by the user, such as a button click or a change of focus or a mouse drag, should perform one transaction in which all changes are made. All of the predefined commands and tools perform transactions.

Undoing or redoing a transaction is done by calling UndoManager.undo or UndoManager.redo. Those methods call the undo or redo methods here.

The UndoManager holds a list of Transactions in its UndoManager.history.

#####
Index

### Constructors

constructor

### Accessors

changes
isComplete
name

### Methods

canRedo
canUndo
clear
optimize
redo
undo

## Constructors

### constructor

- new Transaction(): Transaction

- Construct an object holding an empty list of ChangedEvents and no name. It would be very unusual to call this -- normally transactions are constructed automatically upon calls to Model.commit, Diagram.commit, Model.startTransaction, or Diagram.startTransaction.

  #### Returns Transaction

## Accessors

### `Readonly` changes
: List<ChangedEvent>

- This read-only property returns the list of ChangedEvents. The changes are stored in order of occurrence.

  You should not modify this list.

### isComplete
: boolean

- Gets or sets whether we can add more ChangedEvents to this list of changes. This is initially false. It is set to true by UndoManager.commitTransaction and UndoManager.rollbackTransaction.

### name
: string

- Gets or sets the transaction name for this collection of changes. This is set by a top-level call to UndoManager.commitTransaction.

## Methods

### canRedo

- canRedo(): boolean

- This predicate returns true if you can call redo, namely when isComplete is true.

  #### Returns boolean

  true if ready for redo to be called.

### canUndo

- canUndo(): boolean

- This predicate returns true if you can call undo, namely when isComplete is true.

  #### Returns boolean

  true if ready for undo to be called.

### clear

- clear(): void

- Clear all of the saved changes.

  #### Returns void

### optimize

- optimize(): void

- Remove all but the first and last Property ChangedEvents for each property for each object.

  This is now called by DraggingTool.stopTransaction in order to reduce the memory saved by each dragging transaction.

  #### Returns void

  `since`

  2.2

### redo

- redo(): void

- Re-perform these changes after an undo. This is normally called only by the UndoManager. canRedo must be true for this method to have any effect.

  #### Returns void

### undo

- undo(): void

- Undo all of the changes, in reverse order. This is normally called only by the UndoManager. canUndo must be true for this method to have any effect.

  #### Returns void

Copyright © 1998-2024 by Northwoods Software Corporation.