From 7cca3f38f6bc6b5f20e40e1d7b1adfb419d37f59 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 16 Aug 2022 11:00:23 +0300 Subject: [PATCH] bugfix + notes... Signed-off-by: Alex A. Naanou --- browser.js | 52 ++++++++++++++++++++++++--------------------- pwiki/page.js | 5 ++--- pwiki/store/base.js | 5 ++--- pwiki2-test.js | 2 ++ pwiki2.html | 16 +++++++++----- pwiki2.js | 7 +++++- 6 files changed, 51 insertions(+), 36 deletions(-) diff --git a/browser.js b/browser.js index b0cf5ec..627f835 100755 --- a/browser.js +++ b/browser.js @@ -29,10 +29,34 @@ module.store = { __proto__: basestore.BaseStore } .nest({ __proto__: basestore.MetaStore }) -store.update('System', - Object.create(basestore.BaseStore).load(page.System)) -store.update('Settings', - Object.create(basestore.BaseStore).load(page.Settings)) +module.setup = +Promise.all([ + // static stores... + // + store.update('System', + Object.create(basestore.BaseStore).load(page.System)), + store.update('Settings', + Object.create(basestore.BaseStore).load(page.Settings)), + + // persistent stores... + // + store.update('@local', { + __proto__: localstoragestore.localStorageStore, + data: localStorage, + }), + store.update('@session', { + __proto__: localstoragestore.localStorageStore, + data: sessionStorage, + }), + store.update('@pouch', { + __proto__: pouchdbstore.PouchDBStore, + }), +]) +// XXX +//typeof(Bootstrap) != 'undefined' +// && pwiki.store.load(Bootstrap) + + var pwiki = module.pwiki = @@ -41,26 +65,6 @@ module.pwiki = page.pWikiPageElement('/', '/', store) -pwiki.store.update('@local', { - __proto__: localstoragestore.localStorageStore, - data: localStorage, -}) - -pwiki.store.update('@session', { - __proto__: localstoragestore.localStorageStore, - data: sessionStorage, -}) - -pwiki.store.update('@pouch', { - __proto__: pouchdbstore.PouchDBStore, -}) - - -// XXX -//typeof(Bootstrap) != 'undefined' -// && pwiki.store.load(Bootstrap) - - /********************************************************************** * vim:set ts=4 sw=4 : */ return module }) diff --git a/pwiki/page.js b/pwiki/page.js index c9c0e7b..1831dcf 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -1060,14 +1060,13 @@ object.Constructor('Page', BasePage, { path = pwpath.join(path) // get the template relative to the top most pattern... + // XXX BUG: this sometimes returns undefined on load... tpl = await this.get(tpl).find(true) if(!tpl){ throw new Error('UNKNOWN RENDER TEMPLATE: '+ tpl_name) } - var data = { - render_root: this, - } // render template in context of page... + var data = { render_root: this } return this.get(path, data) .parse(await this.get(tpl, data).raw) }).call(this) }, set text(value){ diff --git a/pwiki/store/base.js b/pwiki/store/base.js index aa46454..9944891 100755 --- a/pwiki/store/base.js +++ b/pwiki/store/base.js @@ -128,9 +128,8 @@ module.BaseStore = { || false }, // find the closest existing alternative path... find: async function(path, strict=false){ - for(var p of await pwpath.paths(path, !!strict)){ - p = await this.exists(p) - if(p){ + for(var p of pwpath.paths(path, !!strict)){ + if(p = await this.exists(p)){ return p } } }, // // Resolve page for path diff --git a/pwiki2-test.js b/pwiki2-test.js index c1960ce..0828980 100755 --- a/pwiki2-test.js +++ b/pwiki2-test.js @@ -32,6 +32,8 @@ store.next.load( return res }, {})) //*/ +// XXX these are async... +// ...see browser.js for a way to deal with this... pwiki.store.update('@file-ro', { __proto__: filestore.FileStoreRO, __path__: 'bootstrap', diff --git a/pwiki2.html b/pwiki2.html index 1a1863f..bd8f419 100755 --- a/pwiki2.html +++ b/pwiki2.html @@ -88,9 +88,10 @@ document.pwikiloaded = new Event('pwikiloaded') // start loading pWiki... -require(['./browser'], function(pwiki){ - pwiki = window.pwiki = pwiki.pwiki +require(['./browser'], function(browser){ + pwiki = window.pwiki = browser.pwiki pwiki.dom = document.querySelector('#pWiki') + // handle location.hash/history (both directions) window.addEventListener('hashchange', function(evt){ evt.preventDefault() @@ -126,9 +127,14 @@ require(['./browser'], function(pwiki){ && this.dom .querySelector('#'+ this.hash) .scrollIntoView() }) - // show current page... - pwiki.path = location.hash.slice(1) -}) + + // wait for stuff to finish... + browser.setup.then(function(){ + + // show current page... + pwiki.path = location.hash.slice(1) + + }) }) // XXX make this a 2 stage save -- first cache and then save to store... diff --git a/pwiki2.js b/pwiki2.js index e1c546a..b6a376f 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -1,7 +1,6 @@ /********************************************************************** * * -* * XXX BUG: source/include problem... * to reproduce: * .get('/System/_text_macro/_text').text @@ -12,6 +11,10 @@ * ...there are two ways to dance around this: * - make filters run a bit more globaly -- per block... * - find a local parser... +* XXX BUG?: empty stores do not appear to show up in listings... +* ...this is expected but not intuitive... +* might be a good idea to add a special path like /Stores to list +* sub-stores... * XXX OPTIMIZE: /_tree is really slow... * XXX might be a good idea to add page caching (state.page_cache) relative * to a path on parsing, to avoid re-matching the same page over and @@ -265,6 +268,8 @@ module.store = .nest({ __proto__: basestore.MetaStore }) +// XXX these are async... +// ...see browser.js for a way to deal with this... // 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