mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fix global.get("foo.bar") for functionGlobalContext set values
This commit is contained in:
parent
048f9c0294
commit
0f4d46671f
@ -17,6 +17,7 @@
|
||||
var clone = require("clone");
|
||||
var log = require("../../log");
|
||||
var memory = require("./memory");
|
||||
var util = require("../../util");
|
||||
|
||||
var settings;
|
||||
|
||||
@ -209,12 +210,12 @@ function createContext(id,seed) {
|
||||
insertSeedValues = function(keys,values) {
|
||||
if (!Array.isArray(keys)) {
|
||||
if (values[0] === undefined) {
|
||||
values[0] = seed[keys];
|
||||
values[0] = util.getObjectProperty(seed,keys);
|
||||
}
|
||||
} else {
|
||||
for (var i=0;i<keys.length;i++) {
|
||||
if (values[i] === undefined) {
|
||||
values[i] = seed[keys[i]];
|
||||
values[i] = util.getObjectProperty(seed,keys[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -258,7 +259,7 @@ function createContext(id,seed) {
|
||||
if (Array.isArray(key)) {
|
||||
insertSeedValues(key,results);
|
||||
} else if (results === undefined){
|
||||
results = seed[key];
|
||||
results = util.getObjectProperty(seed,key);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
|
@ -191,15 +191,26 @@ describe('context', function() {
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('returns functionGlobalContext value if store value undefined', function() {
|
||||
Context.init({functionGlobalContext: {foo:"bar"}});
|
||||
Context.load().then(function(){
|
||||
return Context.load().then(function(){
|
||||
var context = Context.get("1","flowA");
|
||||
var v = context.global.get('foo');
|
||||
v.should.equal('bar');
|
||||
});
|
||||
})
|
||||
|
||||
it('returns functionGlobalContext sub-value if store value undefined', function() {
|
||||
Context.init({functionGlobalContext: {foo:{bar:123}}});
|
||||
return Context.load().then(function(){
|
||||
var context = Context.get("1","flowA");
|
||||
var v = context.global.get('foo.bar');
|
||||
should.equal(v,123);
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('external context storage',function() {
|
||||
@ -579,16 +590,16 @@ describe('context', function() {
|
||||
});
|
||||
|
||||
it('should return multiple functionGlobalContext values if key is an array', function(done) {
|
||||
var fGC = { "foo1": 456, "foo2": 789 };
|
||||
var fGC = { "foo1": 456, "foo2": {"bar":789} };
|
||||
Context.init({contextStorage:memoryStorage, functionGlobalContext:fGC });
|
||||
Context.load().then(function(){
|
||||
var context = Context.get("1","flow");
|
||||
context.global.get(["foo1","foo2","foo3"], "memory", function(err,foo1,foo2,foo3){
|
||||
context.global.get(["foo1","foo2.bar","foo3"], "memory", function(err,foo1,foo2,foo3){
|
||||
if (err) {
|
||||
done(err);
|
||||
} else {
|
||||
foo1.should.be.equal(456);
|
||||
foo2.should.be.equal(789);
|
||||
should.equal(foo1, 456);
|
||||
should.equal(foo2, 789);
|
||||
should.not.exist(foo3);
|
||||
done();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user