Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dist/thunderJS.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
});
}
}
Expand Down Expand Up @@ -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);
}
},
Expand Down
4 changes: 2 additions & 2 deletions dist/thunderJS.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions module/thunderJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
});
}
}
Expand Down Expand Up @@ -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);
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/api/notificationListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
},
Expand Down