MetaStore now appears to be working...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-05-08 23:36:59 +03:00
parent bd5ec44bd9
commit b5e3832394

View File

@ -418,6 +418,8 @@ module.store =
BaseStore.nest() BaseStore.nest()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// XXX stores to experiment with: // XXX stores to experiment with:
// - cache // - cache
// - fs // - fs
@ -429,24 +431,25 @@ 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, post){
var target = meth.replace(/__/g, '')
if(drop_cache instanceof Function){ if(drop_cache instanceof Function){
pre = drop_cache post = drop_cache
drop_cache = false } 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 store = this.substore(path)
var res = store == null ? var res = store == null ?
object.parentCall(MetaStore, meth, this, path, ...args) object.parentCall(MetaStore, meth, this, path, ...args)
: this.data[store][meth](path.slice(store.length), ...args) //: this.data[store][meth](path.slice(store.length), ...args)
: this.data[store][target](path.slice(store.length), ...args)
//console.log('---', path, target, '(', store, ...args, ') ->', res)
if(drop_cache){ if(drop_cache){
delete this.__substores } delete this.__substores }
post
&& (res = post.call(this, res, store, path, ...args))
return res} } return res} }
// 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...
// XXX should this be a mixin??? // XXX should this be a mixin???
// XXX TEST... // XXX TEST...
var MetaStore = var MetaStore =
@ -456,7 +459,6 @@ module.MetaStore = {
//data: undefined, //data: undefined,
data: {}, data: {},
// XXX STORETEST revise store test....
__substores: undefined, __substores: undefined,
get substores(){ get substores(){
return this.__substores return this.__substores
@ -478,7 +480,6 @@ module.MetaStore = {
undefined undefined
: store }, : store },
// XXX STORETEST revise store test....
__paths__: function(){ __paths__: function(){
var that = this var that = this
var data = this.data var data = this.data
@ -489,13 +490,23 @@ module.MetaStore = {
: data[path] }) : data[path] })
.flat() }, .flat() },
__exists__: metaProxy('__exists__'), // XXX revise...
__exists__: metaProxy('__exists__',
function(res, store, path){
return store ?
// XXX which way should we go???
//module.path.join(store, res)
path
: res }),
__get__: metaProxy('__get__'), __get__: metaProxy('__get__'),
__delete__: metaProxy('__delete__', true), __delete__: metaProxy('__delete__', true),
__update__: metaProxy('__update__', true), __update__: metaProxy('__update__', true),
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// XXX EXPERIMENTAL, needs testing in browser... // XXX EXPERIMENTAL, needs testing in browser...
var localStorageStore = var localStorageStore =
module.localStorageStore = { module.localStorageStore = {
@ -538,6 +549,8 @@ module.localStorageStore = {
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var localStorageNestedStore = var localStorageNestedStore =
module.localStorageNestedStore = { module.localStorageNestedStore = {
__proto__: BaseStore, __proto__: BaseStore,
@ -557,6 +570,8 @@ module.localStorageNestedStore = {
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var FileStore = var FileStore =
module.FileStore = { module.FileStore = {
__proto__: BaseStore, __proto__: BaseStore,
@ -566,6 +581,8 @@ module.FileStore = {
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var PouchDBStore = var PouchDBStore =
module.PouchDBStore = { module.PouchDBStore = {
__proto__: BaseStore, __proto__: BaseStore,
@ -574,7 +591,7 @@ module.PouchDBStore = {
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //---------------------------------------------------------------------
var relProxy = var relProxy =
function(name){ function(name){