Quantcast
Channel: GoJS - Northwoods Software
Viewing all articles
Browse latest Browse all 7069

Infinite Loop When Starting A Transaction

$
0
0

@mayyildiz wrote:

Hello,

I am experiencing a problem with transactions. When I add a node or link without using transactions, it adds perfectly.
However, using transactions, it starts an infinite loop and crashes.

My main purpose is to add some extra nodes when a node is added to diagram.

So, this is my modelChanged:

onModelChanged() {
    let me = this;
    return e => {
        if (e.isTransactionFinished) {
            me.modelChanged.emit(true);
            let modelsToOperate = [];
            let txn = e.object;
            if (txn !== null) {
                txn.changes.each(function (ch) {
                    if (ch.change === go.ChangedEvent.Insert && ch.modelChange === "nodeDataArray") {
                        modelsToOperate.push(ch.getValue());
                        console.log("model changed");
                    }
                });
                modelsToOperate.forEach(model => {
                    me.modelChangeOperations(model);
                });
                return;
            }
        }
    };
}

And this is the modelChangeOperations:
modelChangeOperations(newNode: any) {
this.diagram.startTransaction("model change transaction");
this.diagram.commitTransaction("model change transaction");
}

Even if I removed the logic in this method and does not add anything, it still starts an infinite loop.
Any help would be appreciated.
Thank you

Posts: 8

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 7069

Trending Articles