mirror of
https://github.com/flynx/pWiki.git
synced 2025-10-30 18:40:08 +00:00
refactoring and cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
b580c6b0c3
commit
7775a3a1de
81
pwiki2.js
81
pwiki2.js
@ -157,8 +157,7 @@ module.path = {
|
|||||||
// -> <data>
|
// -> <data>
|
||||||
// - optionally (for writable stores)
|
// - optionally (for writable stores)
|
||||||
// .__update__(..)
|
// .__update__(..)
|
||||||
// .__set__(..)
|
// .__delete__(..)
|
||||||
// .delete(..)
|
|
||||||
// .load(..)
|
// .load(..)
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@ -354,37 +353,28 @@ module.BaseStore = {
|
|||||||
// 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){
|
__update__: function(key, data){
|
||||||
this.data[key] = Object.assign(
|
this.data[key] = data
|
||||||
{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 },
|
return this },
|
||||||
update: function(path, data, mode='update'){
|
update: function(path, data, mode='update'){
|
||||||
path = module.path.normalize('/'+ path, 'string')
|
path = this.exists(path)
|
||||||
path = path[path.length-1] == '/' ?
|
|| module.path.normalize(path, 'string')
|
||||||
path.slice(0, -1)
|
data = Object.assign(
|
||||||
: path
|
{ctime: Date.now()},
|
||||||
mode == 'update' ?
|
mode == 'update' ?
|
||||||
this.__update__(path, data)
|
this.get(path)
|
||||||
: this.__set__(path, data)
|
: {},
|
||||||
|
data,
|
||||||
|
{mtime: Date.now()})
|
||||||
|
this.__update__(path, data, mode)
|
||||||
|
return this },
|
||||||
|
__delete__: function(path){
|
||||||
|
delete this.data[path]
|
||||||
return this },
|
return this },
|
||||||
// XXX revise...
|
|
||||||
delete: function(path){
|
delete: function(path){
|
||||||
var data = this.data
|
var data = this.data
|
||||||
path = module.path.normalize(path, 'string')
|
path = this.exists(path)
|
||||||
path = path[path.length-1] == '/' ?
|
path
|
||||||
path.slice(0, -1)
|
&& this.__delete__(path)
|
||||||
: path
|
|
||||||
// XXX revise...
|
|
||||||
delete data[path]
|
|
||||||
delete data['/'+ path]
|
|
||||||
return this },
|
return this },
|
||||||
|
|
||||||
|
|
||||||
@ -420,6 +410,10 @@ module.store =
|
|||||||
// - cache
|
// - cache
|
||||||
// - fs
|
// - fs
|
||||||
// - PouchDB
|
// - PouchDB
|
||||||
|
// XXX need a way do load several stores at the same time on different
|
||||||
|
// paths..
|
||||||
|
// - a router?
|
||||||
|
// - substores?
|
||||||
|
|
||||||
// XXX EXPERIMENTAL
|
// XXX EXPERIMENTAL
|
||||||
var localStorageStore =
|
var localStorageStore =
|
||||||
@ -449,33 +443,16 @@ module.localStorageStore = {
|
|||||||
return path in this.data ?
|
return path in this.data ?
|
||||||
JSON.parse(this.data[path])
|
JSON.parse(this.data[path])
|
||||||
: undefined },
|
: undefined },
|
||||||
__set__: function(path, data={}){
|
|
||||||
path = (this.__prefix__ ?? '')+ path
|
|
||||||
var t = Date.now()
|
|
||||||
this.data[path] =
|
|
||||||
JSON.stringify(
|
|
||||||
Object.assign(
|
|
||||||
{ctime: t},
|
|
||||||
data,
|
|
||||||
{mtime: t}))
|
|
||||||
return this },
|
|
||||||
// XXX for some magical reason this overwrites both ctime and mtime...
|
|
||||||
__update__: function(path, data={}){
|
__update__: function(path, data={}){
|
||||||
path = (this.__prefix__ ?? '')+ path
|
this.data[(this.__prefix__ ?? '')+ path] =
|
||||||
var t = Date.now()
|
JSON.stringify(data)
|
||||||
this.data[path] =
|
return this },
|
||||||
JSON.stringify(
|
__delete__: function(path){
|
||||||
Object.assign(
|
delete this.data[(this.__prefix__ ?? '')+ path]
|
||||||
{ctime: t},
|
|
||||||
this.__get__(path),
|
|
||||||
data,
|
|
||||||
{mtime: t}))
|
|
||||||
return this },
|
return this },
|
||||||
// XXX
|
|
||||||
delete: function(){
|
|
||||||
},
|
|
||||||
|
|
||||||
load: function(){},
|
load: function(){
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var localStorageNestedStore =
|
var localStorageNestedStore =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user