fixes and tweaks...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-05-08 10:53:03 +03:00
parent 4fe2a6b499
commit bd5ec44bd9

View File

@ -137,7 +137,12 @@ module.path = {
split: function(path){ split: function(path){
return this.normalize(path, 'array') }, return this.normalize(path, 'array') },
join: function(...parts){ join: function(...parts){
return this.normalize(parts.join('/'), 'string') }, return this.normalize(
(parts[0] instanceof Array ?
parts[0]
: parts)
.join('/'),
'string') },
} }
@ -230,6 +235,11 @@ module.BaseStore = {
this.next.paths() this.next.paths()
: []) }, : []) },
//
// .exists(<path>)
// -> <normalized-path>
// -> false
//
// XXX might be a good idea to cache this... // XXX might be a good idea to cache this...
__exists__: function(path){ __exists__: function(path){
return (path in this.data return (path in this.data
@ -252,7 +262,9 @@ module.BaseStore = {
|| this.next.__exists__( || this.next.__exists__(
path[0] == '/' ? path[0] == '/' ?
path.slice(1) path.slice(1)
: ('/'+ path)))) }, : ('/'+ path))))
// normalize the output...
|| false },
/*/ XXX do we actually need this??? /*/ XXX do we actually need this???
// ...this is the same as .get('**') // ...this is the same as .get('**')
@ -357,6 +369,8 @@ module.BaseStore = {
path = this.exists(path) path = this.exists(path)
|| module.path.normalize(path, 'string') || module.path.normalize(path, 'string')
data = Object.assign( data = Object.assign(
// XXX do we need to isolate/clone data here???
data,
{ctime: Date.now()}, {ctime: Date.now()},
mode == 'update' ? mode == 'update' ?
this.get(path) this.get(path)
@ -416,18 +430,20 @@ module.store =
// XXX might be a good idea to normalize args... // XXX might be a good idea to normalize args...
var metaProxy = var metaProxy =
function(meth, drop_cache=false, pre){ function(meth, drop_cache=false, pre){
if(drop_cache instanceof Function){
pre = drop_cache
drop_cache = false }
return function(path, ...args){ return function(path, ...args){
if(pre
&& pre.call(this, path, ...args) === false){
return }
var store = this.substore(path)
var res = store == null ?
object.parentCall(MetaStore, meth, this, path, ...args)
: this.data[store][meth](path.slice(store.length), ...args)
if(drop_cache){ if(drop_cache){
delete this.__substores } delete this.__substores }
if(pre){ return res} }
var res = pre.call(this, path, ...args)
if(res === false){
return }}
var store = this.substore(path)
return store == null ?
// XXX this breaks for some reason...
object.parentCall(MetaStore, meth, this, path, ...args)
: this.data[store][meth](path.slice(store.length), ...args) } }
// XXX STORETEST for this to work need a way to test if something is a store -- i.e. // XXX STORETEST for this to work need a way to test if something is a store -- i.e.
// either make things Constructor's or some other test... // either make things Constructor's or some other test...
@ -476,11 +492,7 @@ module.MetaStore = {
__exists__: metaProxy('__exists__'), __exists__: metaProxy('__exists__'),
__get__: metaProxy('__get__'), __get__: metaProxy('__get__'),
__delete__: metaProxy('__delete__', true), __delete__: metaProxy('__delete__', true),
__update__: metaProxy('__update__', true, __update__: metaProxy('__update__', true),
function(path, data, mode){
if(object.childOf(data, module.module.BaseStore)){
this.data[path] = data
return false } }),
} }