Improve RED.actions api to ensure actions cannot be overridden

Also alows multiple args to be passed to an action.
This commit is contained in:
Nick O'Leary 2021-10-02 23:25:16 +01:00
parent 8a5eda9c1f
commit 061afb3a94
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
1 changed files with 10 additions and 2 deletions

View File

@ -4,6 +4,12 @@ RED.actions = (function() {
}
function addAction(name,handler) {
if (typeof handler !== 'function') {
throw new Error("Action handler not a function");
}
if (actions[name]) {
throw new Error("Cannot override existing action");
}
actions[name] = handler;
}
function removeAction(name) {
@ -12,9 +18,11 @@ RED.actions = (function() {
function getAction(name) {
return actions[name];
}
function invokeAction(name,args) {
function invokeAction() {
var args = Array.prototype.slice.call(arguments);
var name = args.shift();
if (actions.hasOwnProperty(name)) {
actions[name](args);
actions[name].apply(null, args);
}
}
function listActions() {