ChangedListener event object diagram always null

I add some function to addModelChangedListener, but I always got event.diagram is null.

function somefunction (event) {
if (!evt.isTransactionFinished) return;
var diag = event.diagram;
}
diagram.addModelChangedListener(somefunction);

why it is always null, or something work around ?

I got some information from gojs document

When this property is non-null, the model property will be null

so, how can i get diagram.

Yes, you are adding a listener to the Diagram’s Model, so the listener is getting the model’s ChangedEvents. This is what is usually desired.

When dealing with Models one should not assume that there is exactly one Diagram that is showing that model. There might be several diagrams or none at all.

I don’t know your situation and what you want to accomplish, so it’s hard for me to recommend anything.

Ok thank you, maybe I can pass the diagram to event function. let me try. (^ ^)

ChangedEvent.isTransactionFinished only applies to model ChangedEvents, because only they can be “Transaction” ChangedEvents.

OK I got I think I can make it. I can pass the diagram object to event function object. my model just show in in one diagram. not two or more.