mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-17 08:31:38 +00:00
added a simple IndexedDB store...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
5ff9906c1e
commit
fe18674f50
10
browser.js
10
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', {
|
||||
|
||||
88
pwiki/store/indexeddb.js
Executable file
88
pwiki/store/indexeddb.js
Executable file
@ -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 })
|
||||
@ -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: [
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user