cleanup and testing of history...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-04-22 12:00:48 +03:00
parent 0cd619d255
commit 1fd467f375

View File

@ -292,7 +292,7 @@ var relProxy =
function(name){ function(name){
return function(path='.', ...args){ return function(path='.', ...args){
return this.store[name]( return this.store[name](
module.path.relative(this.path, path), module.path.relative(this.location, path),
...args) } } ...args) } }
// XXX do we need history management??? // XXX do we need history management???
@ -333,8 +333,8 @@ object.Constructor('BasePage', {
if(this.__history === false){ if(this.__history === false){
return false } return false }
if(!this.hasOwnProperty('__history')){ if(!this.hasOwnProperty('__history')){
//this.__history = [] } this.__history = [] }
this.__history = (this.__history ?? []).slice() } //this.__history = (this.__history ?? []).slice() }
return this.__history }, return this.__history },
back: function(offset=1){ back: function(offset=1){
var h = this.history var h = this.history
@ -398,7 +398,7 @@ object.Constructor('BasePage', {
: [paths] : [paths]
return paths return paths
.map(function(path){ .map(function(path){
return that.get(path) }) }, return that.get('/'+ path) }) },
map: function(func){ map: function(func){
return this.each().map(func) }, return this.each().map(func) },
@ -410,22 +410,31 @@ object.Constructor('BasePage', {
// //
// Clone a page optionally asigning data into it... // Clone a page optionally asigning data into it...
// .clone() // .clone()
// .clone({ .. }) // .clone({ .. }[, <clone-history>])
// -> <page> // -> <page>
// //
// Fully clone a page optionally asigning data into it... // Fully clone a page optionally asigning data into it...
// .clone(true) // .clone(true[, <clone-history>])
// .clone(true, { .. }) // .clone(true, { .. }[, <clone-history>])
// -> <page> // -> <page>
// //
// //
// Normal cloning will inherit all the "clones" from the original // Normal cloning will inherit all the "clones" from the original
// page overloading .location and .referrer // page overloading .location and .referrer
// //
clone: function(data={}){ // NOTE: <clone-history> by default is false unless fully cloning
//
// XXX revise...
// XXX HISTORY should we clear history by default...
clone: function(data={}, history=false){
var [data, ...args] = [...arguments]
var full = data === true var full = data === true
history =
typeof(args[args.length-1]) == 'boolean' ?
args.pop()
: full
data = full ? data = full ?
arguments[1] ?? {} args[0] ?? {}
: data : data
return Object.assign( return Object.assign(
full ? full ?
@ -442,6 +451,14 @@ object.Constructor('BasePage', {
location: this.location, location: this.location,
referrer: this.referrer, referrer: this.referrer,
}, },
// XXX HISTORY...
this.__history !== false ?
{ __history:
history ?
(this.__history ?? []).slice()
: [] }
:{},
//*/
data) }, data) },
__init__: function(path, referrer, store){ __init__: function(path, referrer, store){
@ -713,6 +730,7 @@ object.Constructor('Page', BasePage, {
'else': ['macro'], 'else': ['macro'],
}, },
// XXX
expand: function(state={}){ expand: function(state={}){
return expand(this, parse(this.text), state) return expand(this, parse(this.text), state)
.join('') }, .join('') },
@ -732,8 +750,15 @@ var WIKIWORD_PATTERN =
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// XXX experiments and testing...
module.pwiki =
Page('/', '/',
Object.assign(
Object.create(store),
require('./bootstrap')))