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

Tidy up variable naming in split.js

This commit is contained in:
Nick O'Leary 2019-01-01 23:05:13 +00:00
parent d5ef428edd
commit 747af44fc1
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -233,22 +233,22 @@ module.exports = function(RED) {
RED.nodes.registerType("split",SplitNode); RED.nodes.registerType("split",SplitNode);
var _max_kept_msgs_count; var _maxKeptMsgsCount;
function max_kept_msgs_count(node) { function maxKeptMsgsCount(node) {
if (_max_kept_msgs_count === undefined) { if (_maxKeptMsgsCount === undefined) {
var name = "nodeMessageBufferMaxLength"; var name = "nodeMessageBufferMaxLength";
if (RED.settings.hasOwnProperty(name)) { if (RED.settings.hasOwnProperty(name)) {
_max_kept_msgs_count = RED.settings[name]; _maxKeptMsgsCount = RED.settings[name];
} }
else { else {
_max_kept_msgs_count = 0; _maxKeptMsgsCount = 0;
} }
} }
return _max_kept_msgs_count; return _maxKeptMsgsCount;
} }
function apply_r(exp, accum, msg, index, count) { function applyReduce(exp, accum, msg, index, count) {
exp.assign("I", index); exp.assign("I", index);
exp.assign("N", count); exp.assign("N", count);
exp.assign("A", accum); exp.assign("A", accum);
@ -263,7 +263,7 @@ module.exports = function(RED) {
}); });
} }
function apply_f(exp, accum, count) { function applyFixup(exp, accum, count) {
exp.assign("N", count); exp.assign("N", count);
exp.assign("A", accum); exp.assign("A", accum);
return new Promise((resolve,reject) => { return new Promise((resolve,reject) => {
@ -290,8 +290,8 @@ module.exports = function(RED) {
var flag = is_right ? -1 : 1; var flag = is_right ? -1 : 1;
var msgs = group.msgs; var msgs = group.msgs;
return getInitialReduceValue(node, node.exp_init, node.exp_init_type).then(accum => { return getInitialReduceValue(node, node.exp_init, node.exp_init_type).then(accum => {
var reduce_exp = node.reduce_exp; var reduceExpression = node.reduceExpression;
var reduce_fixup = node.reduce_fixup; var fixupExpression = node.fixupExpression;
var count = group.count; var count = group.count;
msgs.sort(function(x,y) { msgs.sort(function(x,y) {
var ix = x.parts.index; var ix = x.parts.index;
@ -301,10 +301,10 @@ module.exports = function(RED) {
return 0; return 0;
}); });
return msgs.reduce((promise, msg) => promise.then(accum => apply_r(reduce_exp, accum, msg, msg.parts.index, count)), Promise.resolve(accum)) return msgs.reduce((promise, msg) => promise.then(accum => applyReduce(reduceExpression, accum, msg, msg.parts.index, count)), Promise.resolve(accum))
.then(accum => { .then(accum => {
if(reduce_fixup !== undefined) { if(fixupExpression !== undefined) {
return apply_f(reduce_fixup, accum, count).then(accum => { return applyFixup(fixupExpression, accum, count).then(accum => {
node.send({payload: accum}); node.send({payload: accum});
}); });
} else { } else {
@ -316,7 +316,7 @@ module.exports = function(RED) {
}); });
} }
function reduce_msg(node, msg) { function reduceMessage(node, msg) {
var promise; var promise;
if (msg.hasOwnProperty('parts')) { if (msg.hasOwnProperty('parts')) {
var parts = msg.parts; var parts = msg.parts;
@ -342,7 +342,7 @@ module.exports = function(RED) {
pending_count++; pending_count++;
var completeProcess = function() { var completeProcess = function() {
node.pending_count = pending_count; node.pending_count = pending_count;
var max_msgs = max_kept_msgs_count(node); var max_msgs = maxKeptMsgsCount(node);
if ((max_msgs > 0) && (pending_count > max_msgs)) { if ((max_msgs > 0) && (pending_count > max_msgs)) {
node.pending = {}; node.pending = {};
node.pending_count = 0; node.pending_count = 0;
@ -404,8 +404,8 @@ module.exports = function(RED) {
var exp_fixup = exp_or_undefined(n.reduceFixup); var exp_fixup = exp_or_undefined(n.reduceFixup);
this.reduce_right = n.reduceRight; this.reduce_right = n.reduceRight;
try { try {
this.reduce_exp = RED.util.prepareJSONataExpression(exp_reduce, this); this.reduceExpression = RED.util.prepareJSONataExpression(exp_reduce, this);
this.reduce_fixup = (exp_fixup !== undefined) ? RED.util.prepareJSONataExpression(exp_fixup, this) : undefined; this.fixupExpression = (exp_fixup !== undefined) ? RED.util.prepareJSONataExpression(exp_fixup, this) : undefined;
} catch(e) { } catch(e) {
this.error(RED._("join.errors.invalid-expr",{error:e.message})); this.error(RED._("join.errors.invalid-expr",{error:e.message}));
return; return;
@ -426,9 +426,6 @@ module.exports = function(RED) {
this.build = n.build || "array"; this.build = n.build || "array";
this.accumulate = n.accumulate || "false"; this.accumulate = n.accumulate || "false";
this.topics = (n.topics || []).map(function(x) { return x.topic; });
this.merge_on_change = n.mergeOnChange || false;
this.topic_counts = undefined;
this.output = n.output || "stream"; this.output = n.output || "stream";
this.pending = {}; this.pending = {};
this.pending_count = 0; this.pending_count = 0;
@ -518,7 +515,7 @@ module.exports = function(RED) {
// There are more messages to process. Get the next message and // There are more messages to process. Get the next message and
// start processing it. Recurse back in to check for any more // start processing it. Recurse back in to check for any more
var nextMsg = pendingMessages.shift(); var nextMsg = pendingMessages.shift();
activeMessagePromise = reduce_msg(node, nextMsg) activeMessagePromise = reduceMessage(node, nextMsg)
.then(processReduceMessageQueue) .then(processReduceMessageQueue)
.catch((err) => { .catch((err) => {
node.error(err,nextMsg); node.error(err,nextMsg);