mirror of
https://github.com/flynx/pWiki.git
synced 2025-10-29 18:10:09 +00:00
cleanup and refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
bfbace1711
commit
ef3c8119a4
78
pwiki2.js
78
pwiki2.js
@ -142,6 +142,20 @@ module.path = {
|
|||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
//
|
||||||
|
// To create a store adapter:
|
||||||
|
// - inherit from BaseStore
|
||||||
|
// - overload:
|
||||||
|
// .exists(..)
|
||||||
|
// .paths(..)
|
||||||
|
// .__get__(..)
|
||||||
|
// - optionally (for writable stores)
|
||||||
|
// .__update__(..)
|
||||||
|
// .__set__(..)
|
||||||
|
// .delete(..)
|
||||||
|
// .load(..)
|
||||||
|
//
|
||||||
|
//
|
||||||
// NOTE: store keys must be normalized...
|
// NOTE: store keys must be normalized...
|
||||||
//
|
//
|
||||||
// XXX BUG: mixing up '/' and '' paths...
|
// XXX BUG: mixing up '/' and '' paths...
|
||||||
@ -150,12 +164,14 @@ module.path = {
|
|||||||
// XXX would be nice to be able to create sub-stores, i.e. an object that
|
// XXX would be nice to be able to create sub-stores, i.e. an object that
|
||||||
// would store multiple sub-pages for things like todo docs... (???)
|
// would store multiple sub-pages for things like todo docs... (???)
|
||||||
// ...the question is how to separate the two from the wiki side...
|
// ...the question is how to separate the two from the wiki side...
|
||||||
// XXX must support store stacks...
|
|
||||||
// XXX path macros???
|
// XXX path macros???
|
||||||
// XXX should we support page symlinking???
|
// XXX should we support page symlinking???
|
||||||
var BaseStore =
|
var BaseStore =
|
||||||
module.BaseStore = {
|
module.BaseStore = {
|
||||||
|
|
||||||
|
// XXX NEXT need to think about this...
|
||||||
|
next: undefined,
|
||||||
|
|
||||||
// XXX need a way to integrate these better...
|
// XXX need a way to integrate these better...
|
||||||
// ...i.e. need a way to layer stores...
|
// ...i.e. need a way to layer stores...
|
||||||
data: {
|
data: {
|
||||||
@ -171,6 +187,10 @@ module.BaseStore = {
|
|||||||
return this.get('..').dir },
|
return this.get('..').dir },
|
||||||
'System/name': function(){
|
'System/name': function(){
|
||||||
return this.get('..').name },
|
return this.get('..').name },
|
||||||
|
'System/ctime': function(){
|
||||||
|
return this.get('..').data.ctime },
|
||||||
|
'System/mtime': function(){
|
||||||
|
return this.get('..').data.mtime },
|
||||||
|
|
||||||
'System/title': function(){
|
'System/title': function(){
|
||||||
var p = this.get('..')
|
var p = this.get('..')
|
||||||
@ -195,21 +215,6 @@ module.BaseStore = {
|
|||||||
// XXX System/reverse
|
// XXX System/reverse
|
||||||
},
|
},
|
||||||
|
|
||||||
// store chain actions...
|
|
||||||
//
|
|
||||||
// XXX NEXT need to think about this...
|
|
||||||
next: undefined,
|
|
||||||
|
|
||||||
// XXX NEXT EXPERIMENTAL...
|
|
||||||
nest: function(base){
|
|
||||||
return {
|
|
||||||
__proto__: base
|
|
||||||
?? module.BaseStore,
|
|
||||||
next: this,
|
|
||||||
data: {}
|
|
||||||
} },
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// XXX might be a good idea to cache this...
|
// XXX might be a good idea to cache this...
|
||||||
exists: function(path){
|
exists: function(path){
|
||||||
@ -336,18 +341,27 @@ module.BaseStore = {
|
|||||||
// XXX FUNC handle functions as pages...
|
// 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){
|
||||||
|
this.data[key] = Object.assign(
|
||||||
|
{ctime: Date.now()},
|
||||||
|
this.data[key] ?? {},
|
||||||
|
data,
|
||||||
|
{mtime: Date.now()})
|
||||||
|
return this },
|
||||||
|
__set__: function(key, data){
|
||||||
|
this.data[key] = Object.assign(
|
||||||
|
{ctime: Date.now()},
|
||||||
|
data,
|
||||||
|
{mtime: Date.now()})
|
||||||
|
return this },
|
||||||
update: function(path, data, mode='update'){
|
update: function(path, data, mode='update'){
|
||||||
var d = this.data
|
|
||||||
path = module.path.normalize('/'+ path, 'string')
|
path = module.path.normalize('/'+ path, 'string')
|
||||||
path = path[path.length-1] == '/' ?
|
path = path[path.length-1] == '/' ?
|
||||||
path.slice(0, -1)
|
path.slice(0, -1)
|
||||||
: path
|
: path
|
||||||
d[path] =
|
mode == 'update' ?
|
||||||
mode == 'update' ?
|
this.__update__(path, data)
|
||||||
Object.assign(
|
: this.__set__(path, data)
|
||||||
d[path] ?? {},
|
|
||||||
data)
|
|
||||||
: data
|
|
||||||
return this },
|
return this },
|
||||||
// XXX revise...
|
// XXX revise...
|
||||||
delete: function(path){
|
delete: function(path){
|
||||||
@ -370,6 +384,16 @@ module.BaseStore = {
|
|||||||
load: function(...data){
|
load: function(...data){
|
||||||
Object.assign(this.data, ...data)
|
Object.assign(this.data, ...data)
|
||||||
return this },
|
return this },
|
||||||
|
|
||||||
|
// XXX NEXT EXPERIMENTAL...
|
||||||
|
nest: function(base){
|
||||||
|
return {
|
||||||
|
__proto__: base
|
||||||
|
?? module.BaseStore,
|
||||||
|
next: this,
|
||||||
|
data: {}
|
||||||
|
} },
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -380,6 +404,12 @@ module.store =
|
|||||||
BaseStore.nest()
|
BaseStore.nest()
|
||||||
|
|
||||||
|
|
||||||
|
// XXX EXPERIMENTAL
|
||||||
|
var localStorageStore =
|
||||||
|
module.localStorageStore = {
|
||||||
|
// XXX
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
@ -1237,7 +1267,7 @@ object.Constructor('Page', BasePage, {
|
|||||||
return this.macros.include.call(this,
|
return this.macros.include.call(this,
|
||||||
args, body, state, 'sources',
|
args, body, state, 'sources',
|
||||||
function(){
|
function(){
|
||||||
return this.__parser__.parse(this, this.get(src).raw, state) }) },
|
return this.__parser__.parse(this, this.get(src).raw +'', state) }) },
|
||||||
//
|
//
|
||||||
// @quote(<src>)
|
// @quote(<src>)
|
||||||
//
|
//
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user