I have an animation on a collection of nodes. However, after completion of the animation I want it to call a function just once, but the function is apparently called as many times as there are nodes in the collection. Is there a way to stop this? I just want it to run once. Fairly new to Javascript, appreciate any help.
collection.animate({
style: {
'line-color': 'red',
'target-arrow-color': 'red',
'border-width': 20,
'border-color': 'red'
}
}, {
'duration': 3000,
'complete': () => "hello world";
});
Prints 9x "hello world" since my collection of nodes and edges is of length 9 (subbranch of nodes & edges in a directed graph)
This should be easy. Just put a boolean variable to check if is already executed.
let isExecuted = false;
collection.animate({
style: {
'line-color': 'red',
'target-arrow-color': 'red',
'border-width': 20,
'border-color': 'red'
}
}, {
'duration': 3000,
'complete': () => {
if (isExecuted) {
return;
}
console.log("hello world");
isExecuted = true;
};
});