Keeping track of deleted nodes

Hi,

This is how my delete functionality is implemented:

var nodeToDelete = this.diagram.findNodeForKey(node.data.key);
    model.startTransaction('delete node');
    for (let i = 0; i < this.diagram.model['linkDataArray'].length; i++) {
        if (this.diagram.model['linkDataArray'][i]['from'] === node.data['key']) {
            const toNodeKey = this.diagram.model['linkDataArray'][i]['to'];
            const toNodeData = _.find(this.diagram.model['nodeDataArray'], { 'key': toNodeKey });
        }
    }
    model.remove(nodeToDelete);
    model.commitTransaction('delete node');

I want to be able to keep a separate list of all the deleted nodes from my diagram. So basically when a user deleted a node, i want to make an entry of that node in this list, and if the user hits Undo, that entry must be removed from the list.

How can this be achieved?

I’m not understanding your code. I hope you don’t mind a few questions:
What is nodeToDelete? What is node? Why have both variables?
What is model? What is this.diagram?
Why do you keep writing this.diagram.model['linkDataArray']?
What about link data whose “from” property is the node’s key value?
Why not call Model.findNodeDataForKey instead of doing a linear search of nodeDataArray?
Why are you doing all that searching and then not doing anything with the results?

To answer your question, you can implement a Model Changed listener, looking for e.change === go.ChangedEvent.Transaction && e.propertyName ==="FinishedUndo". And of course you’ll want to do the opposite when it’s a “FinishedRedo” Transaction ChangedEvent. In both cases, though, there might be many undeleted or redeleted nodes, or none, which you can find by traversing the e.object.changes List looking for ChangedEvents that have c.change === go.ChangedEvent.Remove && c.modelChange === "nodeDataArray".
Please read https://gojs.net/latest/intro/changedEvents.html#Transactions