makeUniqueKeyFunction when drop node

I have 2 diagramA and diagramB
I am want my own key maker. so I set it to makeUniqueKeyFunction. like this.

diagramA.model.makeUniqueKeyFunction = UniqueKeyFunc;
diagramB.model.makeUniqueKeyFunction = UniqueKeyFunc;

when i drag node from A drop to B, first time makeUniqueKeyFunction don’t work. at the second time drag same node to B makeUniqueKeyFunction work and make new key for me.

then, I add
diagramB.addDiagramListener(“ExternalObjectsDropped”, function(e) {
e.subject.each(function (node) {
e.diagram.model.setKeyForNodeData(, SV.minid());

it work fine, but I hit Ctrl+z to undo the Incremental Json is still old key to delete.

Here it ModelChangedListener.

diagramB.addModelChangedListener(function(evt) {
if (!evt.isTransactionFinished) return;
var json = evt.model.toIncrementalJson(evt);

any suggestion ?

Your Model.makeUniqueKeyFunction is called when adding a node data object to the model and its key either is not already present or is there but is not unique within the model.

So the first time dragging a node from another diagram it turns out that its key is not already present in the target diagram, so the model does not need to assign a new key. But the second time copying the same node it sees the same key.

If you want to make sure every node data object has a unique identifier even across models, you might want to provide a data copying function: Model.copyNodeDataFunction.

thanks it seems work. I use this code for testing.

function copyNodeDataFunction(object, model) {
    var newObject = {}
      if(key != "__gohashid" && key !="id")
        newObject[key] = object[key];
    return newObject;