1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Apply linting suggestions to the registry enclosure

This commit is contained in:
Steve-Mcl 2022-07-11 10:28:31 +01:00
parent e4098d3991
commit 5c69599e78

View File

@ -32,12 +32,12 @@ module.exports = function(RED) {
let registry = { id: {}, name: {} }
function getIndex (/** @type {[LinkTarget]} */ targets, id) {
for (let index = 0; index < (targets || []).length; index++) {
const element = targets[index];
const element = targets[index]
if (element.id === id) {
return index;
return index
}
}
return -1;
return -1
}
/**
* Generate a target object from a node
@ -45,7 +45,7 @@ module.exports = function(RED) {
* @returns {LinkTarget} a link target object
*/
function generateTarget (node) {
const isSubFlow = node._flow.TYPE === "subflow";
const isSubFlow = node._flow.TYPE === 'subflow'
return {
id: node.id,
name: node.name || node.id,
@ -62,11 +62,11 @@ module.exports = function(RED) {
* @returns {[LinkTarget]} Targets registerd to this name.
*/
getTargets (name, excludeSubflows) {
const targets = registry.name[name] || [];
const targets = registry.name[name] || []
if (excludeSubflows) {
return targets.filter(e => e.isSubFlow != true);
return targets.filter(e => e.isSubFlow !== true)
}
return targets;
return targets
},
/**
* Get a single target by registered name.
@ -78,16 +78,16 @@ module.exports = function(RED) {
*/
getTarget (name, flowId) {
/** @type {[LinkTarget]} */
let possibleTargets = this.getTargets(name);
let possibleTargets = this.getTargets(name)
/** @type {LinkTarget} */
let target;
let target
if (possibleTargets.length && flowId) {
possibleTargets = possibleTargets.filter(e => e.flowId == flowId);
possibleTargets = possibleTargets.filter(e => e.flowId === flowId)
}
if (possibleTargets.length === 1) {
target = possibleTargets[0];
target = possibleTargets[0]
}
return target;
return target
},
/**
* Get a target by node ID
@ -95,35 +95,35 @@ module.exports = function(RED) {
* @returns {LinkTarget} target
*/
getTargetById (nodeId) {
return registry.id[nodeId];
return registry.id[nodeId]
},
register (/** @type {LinkInNode} */ node) {
const target = generateTarget(node);
const tByName = this.getTarget(target.name, target.flowId);
const target = generateTarget(node)
const tByName = this.getTarget(target.name, target.flowId)
if (!tByName || tByName.id !== target.id) {
registry.name[target.name] = registry.name[target.name] || [];
registry.name[target.name] = registry.name[target.name] || []
registry.name[target.name].push(target)
}
registry.id[target.id] = target;
return target;
registry.id[target.id] = target
return target
},
remove (node) {
const target = generateTarget(node);
const targs = this.getTargets(target.name);
const idx = getIndex(targs, target.id);
const target = generateTarget(node)
const targs = this.getTargets(target.name)
const idx = getIndex(targs, target.id)
if (idx > -1) {
targs.splice(idx, 1);
targs.splice(idx, 1)
}
if (targs.length === 0) {
delete registry.name[target.name]
}
delete registry.id[target.id];
delete registry.id[target.id]
},
clear () {
registry = { id: {}, name: {} };
registry = { id: {}, name: {} }
}
}
})();
})()
function LinkInNode(n) {
RED.nodes.createNode(this,n);