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:
parent
e4098d3991
commit
5c69599e78
@ -30,22 +30,22 @@ module.exports = function(RED) {
|
|||||||
const crypto = require("crypto");
|
const crypto = require("crypto");
|
||||||
const targetCache = (function () {
|
const targetCache = (function () {
|
||||||
let registry = { id: {}, name: {} }
|
let registry = { id: {}, name: {} }
|
||||||
function getIndex(/** @type {[LinkTarget]}*/ targets, id) {
|
function getIndex (/** @type {[LinkTarget]} */ targets, id) {
|
||||||
for (let index = 0; index < (targets || []).length; index++) {
|
for (let index = 0; index < (targets || []).length; index++) {
|
||||||
const element = targets[index];
|
const element = targets[index]
|
||||||
if (element.id === id) {
|
if (element.id === id) {
|
||||||
return index;
|
return index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Generate a target object from a node
|
* Generate a target object from a node
|
||||||
* @param {LinkInNode} node
|
* @param {LinkInNode} node
|
||||||
* @returns {LinkTarget} a link target object
|
* @returns {LinkTarget} a link target object
|
||||||
*/
|
*/
|
||||||
function generateTarget(node) {
|
function generateTarget (node) {
|
||||||
const isSubFlow = node._flow.TYPE === "subflow";
|
const isSubFlow = node._flow.TYPE === 'subflow'
|
||||||
return {
|
return {
|
||||||
id: node.id,
|
id: node.id,
|
||||||
name: node.name || node.id,
|
name: node.name || node.id,
|
||||||
@ -61,12 +61,12 @@ module.exports = function(RED) {
|
|||||||
* @param {boolean} [excludeSubflows] set `true` to exclude
|
* @param {boolean} [excludeSubflows] set `true` to exclude
|
||||||
* @returns {[LinkTarget]} Targets registerd to this name.
|
* @returns {[LinkTarget]} Targets registerd to this name.
|
||||||
*/
|
*/
|
||||||
getTargets(name, excludeSubflows) {
|
getTargets (name, excludeSubflows) {
|
||||||
const targets = registry.name[name] || [];
|
const targets = registry.name[name] || []
|
||||||
if (excludeSubflows) {
|
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.
|
* Get a single target by registered name.
|
||||||
@ -76,54 +76,54 @@ module.exports = function(RED) {
|
|||||||
* @param {string} [flowId]
|
* @param {string} [flowId]
|
||||||
* @returns {LinkTarget} target
|
* @returns {LinkTarget} target
|
||||||
*/
|
*/
|
||||||
getTarget(name, flowId) {
|
getTarget (name, flowId) {
|
||||||
/** @type {[LinkTarget]}*/
|
/** @type {[LinkTarget]} */
|
||||||
let possibleTargets = this.getTargets(name);
|
let possibleTargets = this.getTargets(name)
|
||||||
/** @type {LinkTarget}*/
|
/** @type {LinkTarget} */
|
||||||
let target;
|
let target
|
||||||
if (possibleTargets.length && flowId) {
|
if (possibleTargets.length && flowId) {
|
||||||
possibleTargets = possibleTargets.filter(e => e.flowId == flowId);
|
possibleTargets = possibleTargets.filter(e => e.flowId === flowId)
|
||||||
}
|
}
|
||||||
if (possibleTargets.length === 1) {
|
if (possibleTargets.length === 1) {
|
||||||
target = possibleTargets[0];
|
target = possibleTargets[0]
|
||||||
}
|
}
|
||||||
return target;
|
return target
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Get a target by node ID
|
* Get a target by node ID
|
||||||
* @param {string} nodeId ID of the node
|
* @param {string} nodeId ID of the node
|
||||||
* @returns {LinkTarget} target
|
* @returns {LinkTarget} target
|
||||||
*/
|
*/
|
||||||
getTargetById(nodeId) {
|
getTargetById (nodeId) {
|
||||||
return registry.id[nodeId];
|
return registry.id[nodeId]
|
||||||
},
|
},
|
||||||
register(/** @type {LinkInNode} */ node) {
|
register (/** @type {LinkInNode} */ node) {
|
||||||
const target = generateTarget(node);
|
const target = generateTarget(node)
|
||||||
const tByName = this.getTarget(target.name, target.flowId);
|
const tByName = this.getTarget(target.name, target.flowId)
|
||||||
if (!tByName || tByName.id !== target.id) {
|
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.name[target.name].push(target)
|
||||||
}
|
}
|
||||||
registry.id[target.id] = target;
|
registry.id[target.id] = target
|
||||||
return target;
|
return target
|
||||||
},
|
},
|
||||||
remove(node) {
|
remove (node) {
|
||||||
const target = generateTarget(node);
|
const target = generateTarget(node)
|
||||||
const targs = this.getTargets(target.name);
|
const targs = this.getTargets(target.name)
|
||||||
const idx = getIndex(targs, target.id);
|
const idx = getIndex(targs, target.id)
|
||||||
if (idx > -1) {
|
if (idx > -1) {
|
||||||
targs.splice(idx, 1);
|
targs.splice(idx, 1)
|
||||||
}
|
}
|
||||||
if (targs.length === 0) {
|
if (targs.length === 0) {
|
||||||
delete registry.name[target.name]
|
delete registry.name[target.name]
|
||||||
}
|
}
|
||||||
delete registry.id[target.id];
|
delete registry.id[target.id]
|
||||||
},
|
},
|
||||||
clear() {
|
clear () {
|
||||||
registry = { id: {}, name: {} };
|
registry = { id: {}, name: {} }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})();
|
})()
|
||||||
|
|
||||||
function LinkInNode(n) {
|
function LinkInNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
|
Loading…
Reference in New Issue
Block a user