addModelChangedListener method

Diagram addModelChangedListener(
  1. void listener(
    1. ChangedEvent
    )
)

Register an event handler on this Diagram's Diagram#model that is called when there is a ChangedEvent on the Model, not in this diagram. Be sure to call #removeModelChangedListener when you are done with the diagram.

This is convenient when the Diagram#model may be replaced. Using this method to register a Model Changed listener is more convenient than calling Model#addChangedListener directly because when this diagram's Model is replaced, one does not need to call Model#removeChangedListener on the old Model and then Model#addChangedListener again on the new Model.

You can establish Model Changed listeners when you create a Diagram. The Diagram init options are passed to GraphObject.make, which accepts "ModelChanged" as a shorthand. For example:

new go.Diagram("myDiagramDiv",
   {
       "ModelChanged": e => { if (e.isTransactionFinished) saveModel(e.model); }
       // ... other Diagram properties
   })

This is equivalent to:

new go.Diagram("myDiagramDiv",
   {
       // ... Diagram properties
   })
   .addModelChangedListener(e => { if (e.isTransactionFinished) saveModel(e.model); })

Do not add or remove Changed listeners during the execution of a Changed listener. @param {function(ChangedEvent)} listener a function that takes a ChangedEvent as its argument. @see #removeModelChangedListener @since 1.6 @return {Diagram} this Diagram

Implementation

_i3.Diagram addModelChangedListener(
        void Function(_i3.ChangedEvent) listener) =>
    _i4.callMethod(
      this,
      'addModelChangedListener',
      [_i4.allowInterop(listener)],
    );