diff --git a/browser.js b/browser.js index e4655b2..fc2df1a 100755 --- a/browser.js +++ b/browser.js @@ -15,6 +15,7 @@ var page = require('./pwiki/page') var basestore = require('./pwiki/store/base') var localstoragestore = require('./pwiki/store/localstorage') +var indexeddb = require('./pwiki/store/indexeddb') var pouchdbstore = require('./pwiki/store/pouchdb') @@ -61,17 +62,20 @@ Promise.all([ // persistent stores... // - store.update('@local', { + store.update('/Stores/local', { __proto__: localstoragestore.localStorageStore, data: localStorage, }), - store.update('@session', { + store.update('Stores/session', { __proto__: localstoragestore.localStorageStore, data: sessionStorage, }), - store.update('@pouch', { + store.update('Stores/pouch', { __proto__: pouchdbstore.PouchDBStore, }), + store.update('Stores/idb', { + __proto__: indexeddb.IndexedDBStore, + }), /*/ XXX next testing... store.next.update('NextPage', { diff --git a/pwiki/store/indexeddb.js b/pwiki/store/indexeddb.js new file mode 100755 index 0000000..a27f1aa --- /dev/null +++ b/pwiki/store/indexeddb.js @@ -0,0 +1,88 @@ +/********************************************************************** +* +* +* +**********************************************************************/ +((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define) +(function(require){ var module={} // make module AMD/node compatible... +/*********************************************************************/ + +var idb = require('idb-keyval') + +var object = require('ig-object') +var types = require('ig-types') + +var pwpath = require('../path') + +var base = require('./base') + + +//--------------------------------------------------------------------- + +// XXX EXPERIMENTAL, needs testing in browser... +var IndexedDBStore = +module.IndexedDBStore = { + __proto__: base.Store, + + __db__: 'pwiki', + __store__: 'pages', + + // XXX add caching of unserialized data??? + //__data: undefined, + get data(){ + return this.__data + ?? (this.__data = idb.createStore(this.__db__, this.__store__)) }, + + __paths__: function(){ + return idb.keys(this.data) }, + __exists__: function(path){ + return idb.get(path, this.data) !== undefined + && path }, + __get__: function(path){ + return idb.get(path, this.data) }, + // XXX should this use idb.update(..) ??? + __update__: function(path, data={}){ + // XXX we seem to have some trouble caching things... + return idb.set(path, data, this.data) }, + /*/ + return idb.update(path, + function(value){ + return data }, + this.data) }, + //*/ + __delete__: function(path){ + idb.del(path, this.data) + return this }, + + clear: function(){ + idb.clear(this.data) + return this }, +} + + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// XXX +var localStorageNestedStore = +module.localStorageNestedStore = { + __proto__: base.BaseStore, + __data__: '__pwiki_data__', + __cache__: '__pwiki_cache__', + + __data: undefined, + get data(){ + return this.__data + ?? (this.__data = + Object.assign( + { __proto__: JSON.parse(localStorage[this.__data__] || '{}') }, + JSON.parse(localStorage[this.__cache__] || '{}') )) }, + + // XXX do partials saves -> cache + write cache... + // XXX on full save merge cache and save... +} + + + + +/********************************************************************** +* vim:set ts=4 sw=4 : */ return module }) diff --git a/pwiki2.html b/pwiki2.html index a5338f9..fb8eab2 100755 --- a/pwiki2.html +++ b/pwiki2.html @@ -218,6 +218,7 @@ require.config({ 'jszip': 'node_modules/jszip/dist/jszip', 'pouchdb': 'node_modules/pouchdb/dist/pouchdb', 'showdown': 'node_modules/showdown/dist/showdown', + 'idb-keyval': 'node_modules/idb-keyval/dist/umd', }, ['ext-lib']), }, packages: [ diff --git a/pwiki2.js b/pwiki2.js index e66ed5c..5b3744a 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -15,6 +15,12 @@ * - images * * +* XXX IndexedDB: after editing a page for some reason we do not see the +* final version until a full refresh -- cache??? +* XXX Chrome started spamming CORS error: +* Access to manifest at 'file:///L:/work/pWiki/manifest.json' +* from origin 'null' ... +* not sure why... * XXX test: can we store the file handler with permissions in a ServiceWorker?? * XXX store: add an indexedDB backend -- save on serialization... * - idb-keyval