Prevent ChangedSelection from firing during ExternalObjectsDropped and go.ChangedEvent.Insert

How do I prevent ChangedSelection from firing during ExternalObjectsDropped and go.ChangedEvent.Insert events. This is causing issues because, the entire operation of new part creation has not been completed yet. In ChangeSelection we are getting more data from server specific to the key in the ChangedSelection which is returning undefined from server, since the original event handler (For ExternalObjectsDropped and go.ChangedEvent.Insert) is still in progress.
I am using GraphLinksModel.

The simple answer is that you can’t. The drag-and-drop operation from one Diagram to another is intentionally supposed to select the dropped Parts in the target diagram. The whole operation completes shortly after the “ExternalObjectsDropped” DiagramEvent has been raised, when the transaction is committed.

There’s no problem in having your “ExternalObjectsDropped” DiagramEvent listener initiate some asynchronous operation to update the new Nodes. When you get a successful response from the server, be sure to perform any changes within a transaction. Clearly such changes are additional changes to be made as a result of the drag-and-drop.

It’s not common to look for ChangedEvents. Are you sure you want to do that?

Why should a “ChangedSelection” DiagramEvent result in any changes to the model?

ChangedSelection is not making any changes to the model. In the changed selection, based on the key of the selected part, am just fetching some data from server.
So when a ExternalObjectsDropped occur, I make a server call to first create the part related entries in the database, and when that succeeds, I am adding that new part to the diagram. Otherwise remove it from the diagram. Meanwhile, since the ChangedSelection is firing before my new part related data got created in the database, fetching part related data is failing.

The drag-and-drop creates a new temporary node in the target diagram. It will have some generated key. Your “ExternalObjectsDropped” listener will send a message to the server, passing it that temporary key. Then the server can create the node in the database and send the temporary key, the real key, and any other fields/properties to the diagram, so that the temporary node can be replaced by a permanent one with the correct data. You will also need to handle several failure cases.

Can’t your “ChangedSelection” listener recognize that it’s a temporary node?

That was the question I had too. May be I can capture the key at the beginning of the ExternalObjectsDropped and in the ChangedSelection, if it matches that captured key, then I can skip whatever I am doing. Does that look viable?

The user might drag-and-drop several (temporary) nodes before the server returns the real information about any of them. So whatever you do in your “ChangedSelection” listener needs to be able to tell whether any node is temporary or not.

I have a spinner that pops up immediately when something is dropped onto canvas. Probably that will prevent multiple temp objects at a time. Can’t let the user drop multiple objects immediately at this time due sequence of other actions that needs to be completed on the diagram model for each drop/insert and before next drop/insert.