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

Change the order of arguments

This commit is contained in:
Hiroki Uchikawa 2018-05-23 11:42:53 +09:00 committed by HirokiUchikawa
parent 84f598e143
commit 7fafa21a1b
6 changed files with 72 additions and 73 deletions

View File

@ -145,12 +145,12 @@ function createContext(id,seed) {
obj.get = function(key) {
var keyPath = parseKey(key);
var context = getContextStorage(keyPath.storage);
return context.get(keyPath.key, scope);
return context.get(scope, keyPath.key);
};
obj.set = function(key, value) {
var keyPath = parseKey(key);
var context = getContextStorage(keyPath.storage);
return context.set(keyPath.key, value, scope);
return context.set(scope, keyPath.key, value);
};
obj.keys = function(storage) {
//TODO: discuss about keys() behavior

View File

@ -66,7 +66,7 @@ var localfilesystem = {
storageBaseDir = configs.dir;
}
},
get: function (key, scope) {
get: function (scope, key) {
if(!storages[scope]){
createStorage(scope);
}
@ -82,7 +82,7 @@ var localfilesystem = {
}
},
set: function (key, value, scope) {
set: function (scope, key, value) {
if(!storages[scope]){
createStorage(scope);
}

View File

@ -17,19 +17,18 @@
var util = require("../../util");
var data;
var seedFlg = false;
var memory = {
init: function(config) {
data = {};
},
get: function(key, scope) {
get: function(scope, key) {
if(!data[scope]){
data[scope] = {};
}
return util.getMessageProperty(data[scope],key);
},
set: function(key, value, scope) {
set: function(scope, key, value) {
if(!data[scope]){
data[scope] = {};
}

View File

@ -335,7 +335,7 @@ describe('context', function() {
contextStorage:{
"#%&":{module:"memory"},
\u3042:{module:"memory"},
1:{module:"localfilesystem"},
1:{module:"memory"},
}
});
try {

View File

@ -38,36 +38,36 @@ describe('localfilesystem',function() {
describe('#get/set',function() {
it('should store property',function() {
should.not.exist(context.get("foo","nodeX"));
context.set("foo","test","nodeX");
context.get("foo","nodeX").should.eql("test");
should.not.exist(context.get("nodeX","foo"));
context.set("nodeX","foo","test");
context.get("nodeX","foo").should.eql("test");
});
it('should store property - creates parent properties',function() {
context.set("foo.bar","test","nodeX");
context.get("foo","nodeX").should.eql({bar:"test"});
context.set("nodeX","foo.bar","test");
context.get("nodeX","foo").should.eql({bar:"test"});
});
it('should delete property',function() {
context.set("foo.abc.bar1","test1","nodeX");
context.set("foo.abc.bar2","test2","nodeX");
context.get("foo.abc","nodeX").should.eql({bar1:"test1",bar2:"test2"});
context.set("foo.abc.bar1",undefined,"nodeX");
context.get("foo.abc","nodeX").should.eql({bar2:"test2"});
context.set("foo.abc",undefined,"nodeX");
should.not.exist(context.get("foo.abc","nodeX"));
context.set("foo",undefined,"nodeX");
should.not.exist(context.get("foo","nodeX"));
context.set("nodeX","foo.abc.bar1","test1");
context.set("nodeX","foo.abc.bar2","test2");
context.get("nodeX","foo.abc").should.eql({bar1:"test1",bar2:"test2"});
context.set("nodeX","foo.abc.bar1",undefined);
context.get("nodeX","foo.abc").should.eql({bar2:"test2"});
context.set("nodeX","foo.abc",undefined);
should.not.exist(context.get("nodeX","foo.abc"));
context.set("nodeX","foo",undefined);
should.not.exist(context.get("nodeX","foo"));
});
it('should not shared context with other scope', function() {
should.not.exist(context.get("foo","nodeX"));
should.not.exist(context.get("foo","nodeY"));
context.set("foo","testX","nodeX");
context.set("foo","testY","nodeY");
should.not.exist(context.get("nodeX","foo"));
should.not.exist(context.get("nodeY","foo"));
context.set("nodeX","foo","testX");
context.set("nodeY","foo","testY");
context.get("foo","nodeX").should.eql("testX");
context.get("foo","nodeY").should.eql("testY");
context.get("nodeX","foo").should.eql("testX");
context.get("nodeY","foo").should.eql("testY");
});
});
@ -77,12 +77,12 @@ describe('localfilesystem',function() {
keys.should.be.an.Array();
keys.should.be.empty();
context.set("foo","bar","nodeX");
context.set("nodeX","foo","bar");
keys = context.keys("nodeX");
keys.should.have.length(1);
keys[0].should.eql("foo");
context.set("abc.def","bar","nodeX");
context.set("nodeX","abc.def","bar");
keys = context.keys("nodeX");
keys.should.have.length(2);
keys[1].should.eql("abc");
@ -97,8 +97,8 @@ describe('localfilesystem',function() {
keysY.should.be.an.Array();
keysY.should.be.empty();
context.set("foo","bar","nodeX");
context.set("hoge","piyo","nodeY");
context.set("nodeX","foo","bar");
context.set("nodeY","hoge","piyo");
keysX = context.keys("nodeX");
keysX.should.have.length(1);
keysX[0].should.eql("foo");
@ -111,16 +111,16 @@ describe('localfilesystem',function() {
describe('#delete',function() {
it('should delete context',function() {
should.not.exist(context.get("foo","nodeX"));
should.not.exist(context.get("foo","nodeY"));
context.set("foo","abc","nodeX");
context.set("foo","abc","nodeY");
context.get("foo","nodeX").should.eql("abc");
context.get("foo","nodeY").should.eql("abc");
should.not.exist(context.get("nodeX","foo"));
should.not.exist(context.get("nodeY","foo"));
context.set("nodeX","foo","abc");
context.set("nodeY","foo","abc");
context.get("nodeX","foo").should.eql("abc");
context.get("nodeY","foo").should.eql("abc");
context.delete("nodeX");
should.not.exist(context.get("foo","nodeX"));
should.exist(context.get("foo","nodeY"));
should.not.exist(context.get("nodeX","foo"));
should.exist(context.get("nodeY","foo"));
});
});
});

View File

@ -25,36 +25,36 @@ describe('memory',function() {
describe('#get/set',function() {
it('should store property',function() {
should.not.exist(context.get("foo","nodeX"));
context.set("foo","test","nodeX");
context.get("foo","nodeX").should.eql("test");
should.not.exist(context.get("nodeX","foo"));
context.set("nodeX","foo","test");
context.get("nodeX","foo").should.eql("test");
});
it('should store property - creates parent properties',function() {
context.set("foo.bar","test","nodeX");
context.get("foo","nodeX").should.eql({bar:"test"});
context.set("nodeX","foo.bar","test");
context.get("nodeX","foo").should.eql({bar:"test"});
});
it('should delete property',function() {
context.set("foo.abc.bar1","test1","nodeX");
context.set("foo.abc.bar2","test2","nodeX");
context.get("foo.abc","nodeX").should.eql({bar1:"test1",bar2:"test2"});
context.set("foo.abc.bar1",undefined,"nodeX");
context.get("foo.abc","nodeX").should.eql({bar2:"test2"});
context.set("foo.abc",undefined,"nodeX");
should.not.exist(context.get("foo.abc","nodeX"));
context.set("foo",undefined,"nodeX");
should.not.exist(context.get("foo","nodeX"));
context.set("nodeX","foo.abc.bar1","test1");
context.set("nodeX","foo.abc.bar2","test2");
context.get("nodeX","foo.abc").should.eql({bar1:"test1",bar2:"test2"});
context.set("nodeX","foo.abc.bar1",undefined);
context.get("nodeX","foo.abc").should.eql({bar2:"test2"});
context.set("nodeX","foo.abc",undefined);
should.not.exist(context.get("nodeX","foo.abc"));
context.set("nodeX","foo",undefined);
should.not.exist(context.get("nodeX","foo"));
});
it('should not shared context with other scope', function() {
should.not.exist(context.get("foo","nodeX"));
should.not.exist(context.get("foo","nodeY"));
context.set("foo","testX","nodeX");
context.set("foo","testY","nodeY");
should.not.exist(context.get("nodeX","foo"));
should.not.exist(context.get("nodeY","foo"));
context.set("nodeX","foo","testX");
context.set("nodeY","foo","testY");
context.get("foo","nodeX").should.eql("testX");
context.get("foo","nodeY").should.eql("testY");
context.get("nodeX","foo").should.eql("testX");
context.get("nodeY","foo").should.eql("testY");
});
});
@ -64,12 +64,12 @@ describe('memory',function() {
keys.should.be.an.Array();
keys.should.be.empty();
context.set("foo","bar","nodeX");
context.set("nodeX","foo","bar");
keys = context.keys("nodeX");
keys.should.have.length(1);
keys[0].should.eql("foo");
context.set("abc.def","bar","nodeX");
context.set("nodeX","abc.def","bar");
keys = context.keys("nodeX");
keys.should.have.length(2);
keys[1].should.eql("abc");
@ -84,8 +84,8 @@ describe('memory',function() {
keysY.should.be.an.Array();
keysY.should.be.empty();
context.set("foo","bar","nodeX");
context.set("hoge","piyo","nodeY");
context.set("nodeX","foo","bar");
context.set("nodeY","hoge","piyo");
keysX = context.keys("nodeX");
keysX.should.have.length(1);
keysX[0].should.eql("foo");
@ -112,16 +112,16 @@ describe('memory',function() {
describe('#delete',function() {
it('should delete context',function() {
should.not.exist(context.get("foo","nodeX"));
should.not.exist(context.get("foo","nodeY"));
context.set("foo","abc","nodeX");
context.set("foo","abc","nodeY");
context.get("foo","nodeX").should.eql("abc");
context.get("foo","nodeY").should.eql("abc");
should.not.exist(context.get("nodeX","foo"));
should.not.exist(context.get("nodeY","foo"));
context.set("nodeX","foo","abc");
context.set("nodeY","foo","abc");
context.get("nodeX","foo").should.eql("abc");
context.get("nodeY","foo").should.eql("abc");
context.delete("nodeX");
should.not.exist(context.get("foo","nodeX"));
should.exist(context.get("foo","nodeY"));
should.not.exist(context.get("nodeX","foo"));
should.exist(context.get("nodeY","foo"));
});
});
@ -135,7 +135,7 @@ describe('memory',function() {
foo: "bar"
}
context.setGlobalContext(data);
context.get("foo","global").should.eql("bar");
context.get("global","foo").should.eql("bar");
});
});
});