refactoring and tweaking...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-05-11 15:27:15 +03:00
parent 5f31d419de
commit 9c986b553f

103
pwiki2.js
View File

@ -182,51 +182,14 @@ module.BaseStore = {
// XXX NEXT need to think about this... // XXX NEXT need to think about this...
next: undefined, next: undefined,
// XXX need a way to integrate these better... // XXX should this be a prop???
// ...i.e. need a way to layer stores... // ...if yes then remove unnecessary "this.data ?? {}" checks...
data: { __data: undefined,
// metadata... get data(){
// return this.__data
'System/path': function(){ ?? (this.__data = {}) },
return this.get('..').path }, set data(value){
'System/location': function(){ this.__data = value },
return this.get('..').path },
'System/resolved': function(){
return this.get('..').match() },
'System/dir': function(){
return this.get('..').dir },
'System/name': function(){
return this.get('..').name },
'System/ctime': function(){
return this.get('..').data.ctime },
'System/mtime': function(){
return this.get('..').data.mtime },
'System/title': function(){
var p = this.get('..')
return p.title
?? p.name },
// utils...
//
// XXX System/subpaths
// actions...
//
'System/delete': function(){
this.location = '..'
this.delete()
return this.text },
// XXX System/back
// XXX System/forward
// XXX System/sort
// XXX System/reverse
},
/*/
data: {},
//*/
__paths__: function(){ __paths__: function(){
@ -245,8 +208,8 @@ module.BaseStore = {
// //
// 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
&& path) }, && path },
exists: function(path){ exists: function(path){
path = module.path.normalize(path, 'string') path = module.path.normalize(path, 'string')
return this.__exists__(path, 'string') return this.__exists__(path, 'string')
@ -363,22 +326,23 @@ module.BaseStore = {
// NOTE: edit methods are local-only... // NOTE: edit methods are local-only...
// //
// XXX do we copy the data here or modify it???? // XXX do we copy the data here or modify it????
// XXX FUNC handle functions as pages...
// XXX BUG: for path '/' this adds an entry at '', but when getting // XXX BUG: for path '/' this adds an entry at '', but when getting
// '/', the later is not found... // '/', the later is not found...
__update__: function(key, data, mode='update'){ __update__: function(key, data, mode='update'){
this.data[key] = data this.data[key] = data
return this }, return this },
// XXX don't like this -- revise...
update: function(path, data, mode='update'){ update: function(path, data, mode='update'){
var exists = this.exists(path) var exists = this.exists(path)
path = exists path = exists
|| module.path.normalize(path, 'string') || module.path.normalize(path, 'string')
data = Object.assign( data =
{}, data instanceof Function ?
// XXX do we need to isolate/clone data here??? data
data, : Object.assign(
{ctime: Date.now()}, {
__proto__: data.__proto__,
ctime: Date.now(),
},
(mode == 'update' && exists) ? (mode == 'update' && exists) ?
this.get(path) this.get(path)
: {}, : {},
@ -390,7 +354,6 @@ module.BaseStore = {
delete this.data[path] delete this.data[path]
return this }, return this },
delete: function(path){ delete: function(path){
var data = this.data
path = this.exists(path) path = this.exists(path)
path path
&& this.__delete__(path) && this.__delete__(path)
@ -403,7 +366,7 @@ module.BaseStore = {
// XXX do we need this??? // XXX do we need this???
load: function(...data){ load: function(...data){
Object.assign(this.data, ...data) this.data = Object.assign(this.data, ...data)
return this }, return this },
// XXX NEXT EXPERIMENTAL... // XXX NEXT EXPERIMENTAL...
@ -464,7 +427,6 @@ module.MetaStore = {
__proto__: BaseStore, __proto__: BaseStore,
//data: undefined, //data: undefined,
data: {},
__substores: undefined, __substores: undefined,
get substores(){ get substores(){
@ -1688,17 +1650,12 @@ var WIKIWORD_PATTERN =
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// XXX experiments and testing... // XXX experiments and testing...
// XXX need to specify page format....
// XXX need a way to set the page path...
var store =
module.store =
BaseStore.nest()
/*/
var store = var store =
module.store = module.store =
//BaseStore.nest()
BaseStore.nest(MetaStore) BaseStore.nest(MetaStore)
var System = { var System = {
// metadata... // metadata...
// //
@ -1739,7 +1696,23 @@ var System = {
// XXX System/sort // XXX System/sort
// XXX System/reverse // XXX System/reverse
} }
store.update('System', System)
// XXX note sure how to organize the system actions -- there can be two
// options:
// - a root ram store with all the static stuff and nest the rest
// - a nested store (as is the case here)
// XXX nested system store...
store.update('System', Object.create(BaseStore).load(System))
/*/ // XXX chained system store...
// Create a new system action-set with paths starting with 'System/'
var RootSystem =
Object.entries(System)
.reduce(function(res, [key, func]){
res[module.path.join('System', key)] = func
return res }, {})
store.next.load(RootSystem)
//*/ //*/