diff --git a/dist/thunderJS.cjs b/dist/thunderJS.cjs index a72daf4..94a6090 100644 --- a/dist/thunderJS.cjs +++ b/dist/thunderJS.cjs @@ -2,7 +2,7 @@ * If not stated otherwise in this file or this component's LICENSE file the * following copyright and licenses apply: * - * Copyright 2024 Metrological + * Copyright 2025 Metrological * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -58,7 +58,7 @@ var notificationListener = data => { const callbacks = listeners[data.method]; if (callbacks && Array.isArray(callbacks) && callbacks.length) { callbacks.forEach(callback => { - callback(data.params); + if (callback) callback(data.params); }); } } @@ -230,8 +230,8 @@ function listener(plugin, event, callback, errorCallback) { dispose() { const listener_id = makeListenerId(plugin, event); if (listeners[listener_id] === undefined) return - listeners[listener_id].splice(index, 1); - if (listeners[listener_id].length === 0) { + listeners[listener_id][index] = undefined; + if (listeners[listener_id].every(item => item === undefined)) { unregister.call(thunder, plugin, event, errorCallback); } }, diff --git a/dist/thunderJS.js b/dist/thunderJS.js index e09882d..d060b80 100644 --- a/dist/thunderJS.js +++ b/dist/thunderJS.js @@ -2,7 +2,7 @@ * If not stated otherwise in this file or this component's LICENSE file the * following copyright and licenses apply: * - * Copyright 2024 Metrological + * Copyright 2025 Metrological * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -17,4 +17,4 @@ * limitations under the License. */ -var ThunderJS=function(){"use strict";function c(n){return(c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(n)}function e(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),t.push.apply(t,r)}return t}function t(o){for(var n=1;nn.length)&&(e=n.length);for(var t=0,r=new Array(e);tn.length)&&(e=n.length);for(var t=0,r=new Array(e);t { const callbacks = listeners[data.method]; if (callbacks && Array.isArray(callbacks) && callbacks.length) { callbacks.forEach(callback => { - callback(data.params); + if (callback) callback(data.params); }); } } @@ -230,8 +230,8 @@ function listener(plugin, event, callback, errorCallback) { dispose() { const listener_id = makeListenerId(plugin, event); if (listeners[listener_id] === undefined) return - listeners[listener_id].splice(index, 1); - if (listeners[listener_id].length === 0) { + listeners[listener_id][index] = undefined; + if (listeners[listener_id].every(item => item === undefined)) { unregister.call(thunder, plugin, event, errorCallback); } }, diff --git a/src/api/notificationListener.js b/src/api/notificationListener.js index 5ae0781..e95d446 100644 --- a/src/api/notificationListener.js +++ b/src/api/notificationListener.js @@ -33,7 +33,7 @@ export default data => { const callbacks = listeners[data.method] if (callbacks && Array.isArray(callbacks) && callbacks.length) { callbacks.forEach(callback => { - callback(data.params) + if (callback) callback(data.params) }) } } diff --git a/src/listener.js b/src/listener.js index affffe3..4d373db 100644 --- a/src/listener.js +++ b/src/listener.js @@ -31,9 +31,9 @@ export default function(plugin, event, callback, errorCallback) { //early return if the listener is already deleted and someone is calling dispose twice if (listeners[listener_id] === undefined) return - listeners[listener_id].splice(index, 1) - - if (listeners[listener_id].length === 0) { + // invalidate the callback with the given index to mark it as deleted without changing the array dimensions + listeners[listener_id][index] = undefined; + if (listeners[listener_id].every(item => item === undefined)) { unregister.call(thunder, plugin, event, errorCallback) } },