The following code checks the length of the associative array incorrectly
function detach(eventName, className, handler, root) {
if (eventHandlers[eventName]) {
for(var i = 0; i < eventHandlers[eventName].length; i++){
if(eventHandlers[eventName][i].root == root){
eventHandlers[eventName].splice(i, 1);
i--;
}
}
}
}
The correct way to check the length is ‘Object.keys(eventHandlers[eventName]).length’ not ‘eventHandlers[eventName].length’
function detach(eventName, className, handler, root) {
if (eventHandlers[eventName]) {
for(var i = 0; i < Object.keys(eventHandlers[eventName]).length; i++){
if(eventHandlers[eventName][i].root == root){
eventHandlers[eventName].splice(i, 1);
i--;
}
}
}
}
This bug results in a buildup of event handlers each time the timeline is initialized after a destroy.
Here is what eventHandlers[‘click’] is holding after 5 reloads
click:
gantt_add:(5) [{…}, {…}, {…}, {…}, {…}]
gantt_close:(5) [{…}, {…}, {…}, {…}, {…}]
gantt_grid_head_cell:(5) [{…}, {…}, {…}, {…}, {…}]
gantt_header_arrow:(25) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
gantt_open:(5) [{…}, {…}, {…}, {…}, {…}]
gantt_row:(5) [{…}, {…}, {…}, {…}, {…}]
gantt_scale_cell:(5) [{…}, {…}, {…}, {…}, {…}]
gantt_task_link:(5) [{…}, {…}, {…}, {…}, {…}]