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