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) { obj.get = function(key) {
var keyPath = parseKey(key); var keyPath = parseKey(key);
var context = getContextStorage(keyPath.storage); var context = getContextStorage(keyPath.storage);
return context.get(keyPath.key, scope); return context.get(scope, keyPath.key);
}; };
obj.set = function(key, value) { obj.set = function(key, value) {
var keyPath = parseKey(key); var keyPath = parseKey(key);
var context = getContextStorage(keyPath.storage); var context = getContextStorage(keyPath.storage);
return context.set(keyPath.key, value, scope); return context.set(scope, keyPath.key, value);
}; };
obj.keys = function(storage) { obj.keys = function(storage) {
//TODO: discuss about keys() behavior //TODO: discuss about keys() behavior

View File

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

View File

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

View File

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

View File

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

View File

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