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

new-style callback function (template node)

This commit is contained in:
Kunihiko Toumura 2019-11-29 16:12:06 +09:00
parent ca46bc5366
commit 77bd7541ca

View File

@ -107,7 +107,7 @@ module.exports = function(RED) {
var node = this; var node = this;
function output(msg,value) { function output(msg,value,send,done) {
/* istanbul ignore else */ /* istanbul ignore else */
if (node.outputFormat === "json") { if (node.outputFormat === "json") {
value = JSON.parse(value); value = JSON.parse(value);
@ -119,22 +119,24 @@ module.exports = function(RED) {
if (node.fieldType === 'msg') { if (node.fieldType === 'msg') {
RED.util.setMessageProperty(msg, node.field, value); RED.util.setMessageProperty(msg, node.field, value);
node.send(msg); send(msg);
done();
} else if ((node.fieldType === 'flow') || } else if ((node.fieldType === 'flow') ||
(node.fieldType === 'global')) { (node.fieldType === 'global')) {
var context = RED.util.parseContextStore(node.field); var context = RED.util.parseContextStore(node.field);
var target = node.context()[node.fieldType]; var target = node.context()[node.fieldType];
target.set(context.key, value, context.store, function (err) { target.set(context.key, value, context.store, function (err) {
if (err) { if (err) {
node.error(err, msg); done(err);
} else { } else {
node.send(msg); send(msg);
done();
} }
}); });
} }
} }
node.on("input", function(msg) { node.on("input", function(msg, send, done) {
try { try {
/*** /***
@ -179,16 +181,16 @@ module.exports = function(RED) {
Promise.all(promises).then(function() { Promise.all(promises).then(function() {
var value = mustache.render(template, new NodeContext(msg, node.context(), null, is_json, resolvedTokens)); var value = mustache.render(template, new NodeContext(msg, node.context(), null, is_json, resolvedTokens));
output(msg, value); output(msg, value, send, done);
}).catch(function (err) { }).catch(function (err) {
node.error(err.message,msg); done(err.message);
}); });
} else { } else {
output(msg, template); output(msg, template, send, done);
} }
} }
catch(err) { catch(err) {
node.error(err.message, msg); done(err.message);
} }
}); });
} }