mirror of https://github.com/node-red/node-red.git
Fix `onremove` is not called on a pure editor plugin
parent
0c92332033
commit
79bfe6a353
|
|
@ -1612,22 +1612,32 @@ RED.palette.editor = (function() {
|
|||
refreshUpdateStatus();
|
||||
}
|
||||
|
||||
const pluginList = [];
|
||||
Object.entries(entry.pluginSet).forEach(([key, set]) => {
|
||||
if (set.plugins && set.plugins.length) {
|
||||
// Adds ID of plugins that exist in the runtime
|
||||
pluginList.push(...set.plugins.map((plugin) => plugin.id));
|
||||
} else {
|
||||
// Adds ID of plugins that only exist in the editor
|
||||
pluginList.push(key);
|
||||
}
|
||||
});
|
||||
|
||||
// We assume that a plugin that implements onremove
|
||||
// cleans the editor accordingly of its left-overs.
|
||||
let found_onremove = true;
|
||||
|
||||
let keys = Object.keys(entry.pluginSet);
|
||||
keys.forEach((key) => {
|
||||
let set = entry.pluginSet[key];
|
||||
for (let i=0; i<set.plugins?.length; i++) {
|
||||
let plgn = RED.plugins.getPlugin(set.plugins[i].id);
|
||||
if (plgn && plgn.onremove && typeof plgn.onremove === 'function') {
|
||||
plgn.onremove();
|
||||
} else {
|
||||
if (plgn && plgn.onadd && typeof plgn.onadd === 'function') {
|
||||
// if there's no 'onadd', there shouldn't be any left-overs
|
||||
found_onremove = false;
|
||||
pluginList.forEach((id) => {
|
||||
const plugin = RED.plugins.getPlugin(id);
|
||||
if (plugin) {
|
||||
if (plugin.onremove && typeof plugin.onremove === 'function') {
|
||||
try {
|
||||
plugin.onremove();
|
||||
} catch (error) {
|
||||
console.warn(`Error while calling 'onremove' for plugin '${id}': `, error);
|
||||
}
|
||||
} else if (plugin.onadd && typeof plugin.onadd === 'function') {
|
||||
// if there's no 'onadd', there shouldn't be any left-overs
|
||||
found_onremove = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue