mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
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:
parent
8a5eda9c1f
commit
061afb3a94
@ -4,6 +4,12 @@ RED.actions = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addAction(name,handler) {
|
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;
|
actions[name] = handler;
|
||||||
}
|
}
|
||||||
function removeAction(name) {
|
function removeAction(name) {
|
||||||
@ -12,9 +18,11 @@ RED.actions = (function() {
|
|||||||
function getAction(name) {
|
function getAction(name) {
|
||||||
return actions[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)) {
|
if (actions.hasOwnProperty(name)) {
|
||||||
actions[name](args);
|
actions[name].apply(null, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function listActions() {
|
function listActions() {
|
||||||
|
Loading…
Reference in New Issue
Block a user