Search API

- Preparing search index...
- The search index is not available

Show Summaries
GoJS® Diagramming Components
version 1.8.15 for JavaScript/HTML
by Northwoods Software®

## Class ChangedEvent

A ChangedEvent represents a change to an object, typically a GraphObject, but also for model data, a Model, or a Diagram. The most common case is for remembering the name of a property and the before-and-after values for that property.

You can listen for changed events on the model using Model.addChangedListener and on the Diagram using Diagram.addChangedListener.

There are four kinds of changes, represented by enumerated values: ChangedEvent.Property (the most common), ChangedEvent.Insert and ChangedEvent.Remove (to represent inserting or removing objects from collections), and ChangedEvent.Transaction (to notify about beginning or ending transactions or undo or redo).

The most common kind of ChangedEvent is a Property change. The name of the property is given by propertyName. The modified object is given by object. Use the oldValue and newValue properties for the before and after property values.

For an Insert ChangedEvent, the modified collection (often an Array) is a property value on the object. The propertyName helps distinguish between different collections on the object. Use the newValue property to indicate the value that was inserted. Use the newParam property to indicate where or how, such as an array index or dictionary key.

For a Remove ChangedEvent, the modified collection is a property value on the object. The propertyName helps distinguish between different collections on the object. Use the oldValue property to indicate the value that was removed. Use the oldParam property to indicate where or how, such as an array index or dictionary key.

Transaction ChangedEvents are generated by the UndoManager. The propertyName names the nature of the ChangedEvent. For the very first transaction, the property name is "StartingFirstTransaction". This ChangedEvent precedes a ChangedEvent whose property name is "StartedTransaction", which occurs for every top-level transaction.

When ending a transaction, there is first a ChangedEvent whose name is "ComittingTransaction". This is followed by one with either "CommittedTransaction" or "RolledBackTransaction", depending on how the transaction is ending. The oldValue provides the transaction name and the object is the Transaction being finished. (Note that the Transaction value may be null if no Transaction is available at that time, perhaps because there were no changes made during the transaction.) That Transaction can be scanned to look for ChangedEvents that you may wish to record in a database, all within a single database transaction.

There are also Transaction ChangedEvents corresponding to "StartingUndo", "FinishedUndo", "StartingRedo", and "FinishedRedo". The object property provides the Transaction that is about-to-be or just-was undone or redone.

Non-Transaction ChangedEvents are remembered by the UndoManager, if UndoManager.isEnabled, and held in the UndoManager.history as Transactions which hold lists of ChangedEvents. That is why ChangedEvent implements undo and redo of the change that it remembers.

When the ChangedEvent represents a change to a Model, the value of model is non-null and the value of diagram is meaningless. If the change is a structural change to the model, the value of modelChange indicates the kind of change. Currently defined model changed event names include:

- "nodeDataArray", after the model's Model.nodeDataArray is replaced, inserted into or removed from (setting Model.nodeDataArray or calling Model.addNodeData or Model.removeNodeData)
- "nodeKey", after changing a node data's unique key (Model.setKeyForNodeData)
- "nodeCategory", after changing a node data's category (Model.setCategoryForNodeData)
- "linkFromKey", after changing a link data's "from" node key (GraphLinksModel.setFromKeyForLinkData)
- "linkToKey", after changing a link data's "to" node key (GraphLinksModel.setToKeyForLinkData)
- "linkFromPortId", after changing a link data's "from" port (GraphLinksModel.setFromPortIdForLinkData)
- "linkToPortId", after changing a link data's "to" port (GraphLinksModel.setToPortIdForLinkData)
- "linkLabelKeys", after replacing, inserting into, or removing from a link data's array of keys to label nodes (calling GraphLinksModel.setLabelKeysForLinkData, GraphLinksModel.addLabelKeyForLinkData, or GraphLinksModel.removeLabelKeyForLinkData)
- "linkDataArray", after the model's GraphLinksModel.linkDataArray is replaced, inserted into or removed from (setting GraphLinksModel.linkDataArray or calling GraphLinksModel.addLinkData or GraphLinksModel.removeLinkData)
- "nodeGroupKey", after changing a node data's key for a containing group data (GraphLinksModel.setGroupKeyForNodeData)
- "linkCategory", after changing a link data's category (GraphLinksModel.setCategoryForLinkData)
- "nodeParentKey", after changing a node data's "parent" node key (TreeModel.setParentKeyForNodeData)
- "parentLinkCategory", after changing a node data's "parent" link's category(TreeModel.setParentLinkCategoryForNodeData)
- "SourceChanged", for internal implementation use only

The value of ChangedEvent.propertyName indicates the actual name of the property that was modified. ChangedEvent.modelChange is a non-empty string only when there is a known structural change to the model, not just the setting of some property on some object.

When the ChangedEvent represents a change to a Diagram or a GraphObject within a diagram, the value of diagram is non-null and the values of model and modelChange are meaningless.

## Constructor Summary Details

Name | Description
--- | ---
ChangedEvent() | The ChangedEvent class constructor produces an empty ChangedEvent object.

## Properties Summary Details

Name, Value Type | Description
--- | ---
change {EnumValue} | Gets or sets the nature of change that occurred.More... The default is ChangedEvent.Property. Other values are ChangedEvent.Insert, ChangedEvent.Remove, and ChangedEvent.Transaction.
diagram {Diagram} | Gets or sets the Diagram that was modified.More... When this property is non-null, the model property will be null. However this property and the model property may both be null simultaneously, when no particular model or diagram applies.
isTransactionFinished {boolean} | This read-only property is true when this ChangedEvent is of type ChangedEvent.Transaction and represents the end of a transactional change.More... It is implemented as:
    return (this.change === ChangedEvent.Transaction &&
            (this.propertyName === "CommittedTransaction" ||
             this.propertyName === "FinishedUndo" ||
             this.propertyName === "FinishedRedo"));
model {Model} | Gets or sets the Model or TreeModel or GraphLinksModel that was modified.More... When this property is non-null, the diagram property will be null. However this property and the diagram property may both be null simultaneously, when no particular model or diagram applies.
modelChange {string} | Gets the name of the model change, reflecting a change to model data in addition to a change to the model itself.More... The default is an empty string, which indicates that this is just a regular change to some object's state, probably its property. For a list of possible model change names, see the documentation for ChangedEvent.
newParam {*} | Gets or sets an optional value associated with the new value.More... Most properties do not require any parameter to describe the change. This is typically a value that helps distinguish the new value, such as an index into an array. It is null if it is not used. The default is null.
newValue {*} | Gets or sets the next or current value that the property has.More... The default is null.
object {Object} | Gets or sets the Object that was modified.More... The default is null. For ChangedEvent.Transaction changes, this may be the Transaction.
oldParam {*} | Gets or sets an optional value associated with the old value.More... Most properties do not require any parameter to describe the change. This is typically a value that helps distinguish the old value, such as an index into an array. It is null if it is not used. The default is null.
oldValue {*} | Gets or sets the previous or old value that the property had.More... The default is null.
propertyName {string|function(Object):*} | Gets or sets the name of the property change.More... The default is an empty string, which is not a valid property name. This property can be useful even when the type of change is not ChangedEvent.Property, because it can help identify the collection in the object that was modified (for ChangedEvent.Insert or ChangedEvent.Remove) or the stage of the current transaction (for ChangedEvent.Transaction).

## Method Summary Details

Name, Return Type | Description
--- | ---
canRedo() {boolean} | This predicate returns true if you can call redo(). Returns: {boolean} true if ready for redo() to be called.
canUndo() {boolean} | This predicate returns true if you can call undo(). Returns: {boolean} true if ready for undo() to be called.
clear() | Forget any object references that this ChangedEvent may have.
copy() {ChangedEvent} | Make a copy of this ChangedEvent.More... ChangedEvents are copied when the UndoManager adds to a Transaction. Returns: {ChangedEvent}
getParam(undo) {*} | This is a convenient method to get the right parameter value, depending on the value of undo, when implementing a state change as part of an undo or a redo.More... Parameters: {boolean} undo If true, returns the oldParam, otherwise returns the newParam. Returns: {*} Either the oldParam or the newParam.
getValue(undo) {*} | This is a convenient method to get the right value, depending on the value of undo, when implementing a state change as part of an undo or a redo.More... Parameters: {boolean} undo If true, returns the oldValue, otherwise returns the newValue. Returns: {*} Either the oldValue or the newValue.
redo() | Re-perform this object change after an undo().More... canRedo() must be true for this method to have any effect.
undo() | Reverse the effects of this object change.More... canUndo() must be true for this method to have any effect.

## Constants Summary Details

Name | Description
--- | ---
Insert {EnumValue} | For inserting into collections, and used as the value for ChangedEvent.change.More... The modified object is given by ChangedEvent.object. Use the optional ChangedEvent.propertyName to distinguish between different collections on the object. Use the ChangedEvent.newValue property to indicate the value that was inserted. Use the optional ChangedEvent.newParam property to indicate where or how, such as an array index or dictionary key.
Property {EnumValue} | For simple property changes, and used as the value for ChangedEvent.change.More... The name of the property is given by ChangedEvent.propertyName. The modified object is given by ChangedEvent.object. Use the ChangedEvent.oldValue and ChangedEvent.newValue properties for the previous and next property values. For model changes, the ChangedEvent.modelChange may be non-empty, indicating a structural change to the model.
Remove {EnumValue} | For removing from collections, and used as the value for ChangedEvent.change.More... The modified object is given by ChangedEvent.object. Use the optional ChangedEvent.propertyName to distinguish between different collections on the object. Use the ChangedEvent.oldValue property to indicate the value that was removed. Use the optional ChangedEvent.oldParam property to indicate where or how, such as an array index or dictionary key.
Transaction {EnumValue} | For informational events, such as transactions and undo/redo operations, and used as the value for ChangedEvent.change.More... The ChangedEvent.object refers to the Transaction affected, if any. The ChangedEvent.propertyName distinguishes the different transaction or undo or redo stages. The ChangedEvent.oldValue may provide the transaction name, if available, as given to UndoManager.commitTransaction.