Skip to content

Commit

Permalink
Add env type to subflow env var types
Browse files Browse the repository at this point in the history
Also remove date and regex types
  • Loading branch information
knolleary committed Feb 6, 2019
1 parent 2a8f0a4 commit d48a09e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
Expand Up @@ -570,7 +570,7 @@ RED.editor = (function() {
}).appendTo(row)

valueField.typedInput({default:'str',
types:['str','num','bool','json','bin','re','date']
types:['str','num','bool','json','bin','env']
});

valueField.typedInput('type', opt.parent?(opt.type||opt.parent.type):opt.type);
Expand Down
Expand Up @@ -265,7 +265,7 @@ class Subflow extends Flow {
if (env && env.hasOwnProperty(name)) {
var val = env[name];
try {
var ret = redUtil.evaluateNodeProperty(val.value, val.type, null, null, null);
var ret = redUtil.evaluateNodeProperty(val.value, val.type, this.node, null, null);
return ret;
}
catch (e) {
Expand Down
19 changes: 8 additions & 11 deletions test/nodes/subflow/subflow_spec.js
Expand Up @@ -166,7 +166,7 @@ describe('subflow', function() {
n1.receive({payload:"foo"});
});
});

it('should access env var of subflow instance', function(done) {
var flow = [
{id:"t0", type:"tab", label:"", disabled:false, info:""},
Expand Down Expand Up @@ -256,13 +256,11 @@ describe('subflow', function() {
{id:"t0", type:"tab", label:"", disabled:false, info:""},
{id:"n1", x:10, y:10, z:"t0", type:"subflow:s1",
env: [
{name: "KS", type: "str", value: "STR"},
{name: "KN", type: "num", value: "100"},
{name: "KB", type: "bool", value: "true"},
{name: "KJ", type: "json", value: "[1,2,3]"},
{name: "Kb", type: "bin", value: "[65,65]"},
{name: "KR", type: "re", value: "[A-Z]"},
{name: "KD", type: "date", value: ""}
{name: "Ke", type: "env", value: "KS"}
],
wires:[["n2"]]},
{id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]},
Expand All @@ -275,10 +273,13 @@ describe('subflow', function() {
out:[{
x:10, y:10,
wires:[ {id:"s1-n1", port:0} ]
}]
}],
env: [
{name: "KS", type: "str", value: "STR"}
]
},
{id:"s1-n1", x:10, y:10, z:"s1", type:"function",
func:"msg.VS = env.get('KS'); msg.VN = env.get('KN'); msg.VB = env.get('KB'); msg.VJ = env.get('KJ'); msg.Vb = env.get('Kb'); msg.VR = env.get('KR'); msg.VD = env.get('KD'); return msg;",
func:"msg.VE = env.get('Ke'); msg.VS = env.get('KS'); msg.VN = env.get('KN'); msg.VB = env.get('KB'); msg.VJ = env.get('KJ'); msg.Vb = env.get('Kb'); return msg;",
wires:[]}
];
helper.load(functionNode, flow, function() {
Expand All @@ -292,14 +293,10 @@ describe('subflow', function() {
msg.should.have.property("VJ", [1,2,3]);
msg.should.have.property("Vb");
should.ok(msg.Vb instanceof Buffer);
msg.should.have.property("VR");
should.ok(msg.VR instanceof RegExp);
msg.should.have.property("VD");
should.ok((typeof msg.VD) === "number");
msg.should.have.property("VE","STR");
done();
}
catch (e) {
console.log(e);
done(e);
}
});
Expand Down

0 comments on commit d48a09e

Please sign in to comment.