Skip to content

Commit

Permalink
addListener and removeListener are only invoked on defined (and valid…
Browse files Browse the repository at this point in the history
…) values
  • Loading branch information
DAcodedBEAT committed Feb 20, 2024
1 parent ef5e4d4 commit 8930d19
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/platform/platform.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,15 @@ function initCanvas(canvas, aspectRatio) {
const eventListenerOptions = supportsEventListenerOptions ? {passive: true} : false;

function addListener(node, type, listener) {
node.addEventListener(type, listener, eventListenerOptions);
if (node) {
node.addEventListener(type, listener, eventListenerOptions);
}
}

function removeListener(chart, type, listener) {
chart.canvas.removeEventListener(type, listener, eventListenerOptions);
if (chart && chart.canvas) {
chart.canvas.removeEventListener(type, listener, eventListenerOptions);
}
}

function fromNativeEvent(event, chart) {
Expand Down

0 comments on commit 8930d19

Please sign in to comment.