Skip to content

Commit

Permalink
Fixed #15983, event did not get removed when updating it to undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
khlieng authored and TorsteinHonsi committed Jul 2, 2021
1 parent 081a4e4 commit 84efc02
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
12 changes: 12 additions & 0 deletions samples/unit-tests/axis/events/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,16 @@ QUnit.test('Axis events', function (assert) {
);

unbindClass();

chart.xAxis[0].update({
events: {
afterSetExtremes: void 0
}
});
chart.xAxis[0].setExtremes(3, 7);
assert.deepEqual(
[calls.afterSetExtremesOptions, calls.afterSetExtremesOptionsUpdated],
[2, 1],
'Event handler should be removed after updating to undefined (#15983)'
);
});
26 changes: 13 additions & 13 deletions ts/Core/Foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,21 @@ const registerEventOptions = (
objectEach(
options.events,
function (event: any, eventType: string): void {
if (isFunction(event)) {
// If event does not exist, or is changed by the .update()
// function
if (component.eventOptions[eventType] !== event) {

// If event does not exist, or is changed by the .update()
// function
if (component.eventOptions[eventType] !== event) {

// Remove existing if set by option
if (isFunction(component.eventOptions[eventType])) {
removeEvent(
component,
eventType,
component.eventOptions[eventType]
);
}
// Remove existing if set by option
if (component.eventOptions[eventType]) {
removeEvent(
component,
eventType,
component.eventOptions[eventType]
);
delete component.eventOptions[eventType];
}

if (isFunction(event)) {
component.eventOptions[eventType] = event;
addEvent(component, eventType, event);
}
Expand Down

0 comments on commit 84efc02

Please sign in to comment.