Class ChangedEvent

GoJS® Diagramming Components
version 3.0.16
by Northwoods Software®

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 or Diagram.addModelChangedListener, and on the Diagram using Diagram.addChangedListener.

There are four kinds of changes, represented by enumerated values: ChangeType.Property (the most common), ChangeType.Insert and ChangeType.Remove (to represent inserting or removing objects from collections), and ChangeType.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:

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.

Please note that ChangedEvents can be raised for many different causes. You may not be interested in changes to temporary objects -- in that case ignore the ChangedEvent when Model.skipsUndoManager or Diagram.skipsUndoManager is true.

Index

Constructors

  • The ChangedEvent class constructor produces an empty ChangedEvent object. It would be unusual to need to call this constructor. Normally the Diagram automatically constructs ChangedEvents as the diagram or its GraphObjects are modified, and the Model automatically constructs ChangedEvents as the model or its data are modified.

    Returns ChangedEvent

Accessors

  • Gets or sets the Diagram that was modified. 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.

  • This read-only property is true when this ChangedEvent is of type ChangeType.Transaction and represents the end of a transactional change. It is implemented as:

    return (this.change === ChangeType.Transaction &&
    (this.propertyName === "CommittedTransaction" ||
    this.propertyName === "FinishedUndo" ||
    this.propertyName === "FinishedRedo"));
  • Gets or sets the Model or TreeModel or GraphLinksModel that was modified. 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.

  • Gets or sets the name of the model change, reflecting a change to model data in addition to a change to the model itself.

    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. The names are compared in a case-sensitive manner.

  • Gets or sets an optional value associated with the new value. 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.

  • Gets or sets the next or current value that the property has. The default is null.

  • Gets or sets an optional value associated with the old value. 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.

  • Gets or sets the previous or old value that the property had. The default is null.

Methods

  • This predicate returns true if you can call redo().

    Returns boolean

    True if ready for redo() to be called.

  • This predicate returns true if you can call undo().

    Returns boolean

    True if ready for undo() to be called.

  • Forget any object references that this ChangedEvent may have.

    Returns void

  • 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.

    Parameters

    • undo: boolean

      If true, returns the oldParam, otherwise returns the newParam.

    Returns any

    Either the oldParam or the newParam.

  • 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.

    Parameters

    • undo: boolean

      If true, returns the oldValue, otherwise returns the newValue.

    Returns any

    Either the oldValue or the newValue.

  • Re-perform this object change after an undo(). canRedo() must be true for this method to have any effect.

    Returns void

  • Reverse the effects of this object change. canUndo() must be true for this method to have any effect.

    Returns void

Properties

deprecated

See ChangeType.Insert.

deprecated

See ChangeType.Property.

deprecated

See ChangeType.Remove.

deprecated

See ChangeType.Transaction.