Question

Merry Christmas, everyone !

I have to updatethe events for joint.shapes.uml.State element, which is introduced by JointJS library, after some events are triggered. I use the set('events', events) function. I print the element to the console, and find the element's events has already been updated. But the events shown on the graph haven't changed. The sample code can be accessed at:

http://jsfiddle.net/GJH_ICT/6pmbQ/5/.

You can drag the end of a link to trigger events. This is the update function:

function resetEvents(id, old, newer) {
    var events = graph.getCell(id).get('events');
    for(var i = 0; i < events.length; ++i) {
        events[i] = events[i].replace(old, newer);
    }
    graph.getCell(id).set('events', events);
    console.log(graph.getCell(id).get('events'));
}

Besides, I have noticed the updateEvents() function in joint.shapes.uml.State element, and tried that function, but it does not work fine. What does this function do?

Thanks!

Was it helpful?

Solution

This is because you're changing the events array in place. When you call .set() later on, the internal mechanism of set() thinks it is exactly the same object - the reference is the same - in other words, the === operator between the object passed and the one that has been previously stored returns true.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top