mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
tweaking...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
ff1e1627cc
commit
dacdb01bbe
@ -110,13 +110,17 @@ module.ConfigStore = core.ImageGridFeatures.Feature({
|
|||||||
actions: ConfigStoreActions,
|
actions: ConfigStoreActions,
|
||||||
|
|
||||||
handlers: [
|
handlers: [
|
||||||
|
// XXX need to update rather than rewrite things...
|
||||||
['prepareStoreToSave',
|
['prepareStoreToSave',
|
||||||
function(res){
|
function(res){
|
||||||
|
//var ls_path = '/${ROOT_PATH}/config'
|
||||||
|
var ls_path = 'config'
|
||||||
|
|
||||||
// localStorage...
|
// localStorage...
|
||||||
// NOTE: we do not need to clone anything here as this
|
// NOTE: we do not need to clone anything here as this
|
||||||
// will be done by the localStorage handler...
|
// will be done by the localStorage handler...
|
||||||
if(res.data.localStorage){
|
if(res.data.storage){
|
||||||
res.data.localStorage.config = this.config
|
res.data.storage[ls_path] = this.config
|
||||||
}
|
}
|
||||||
|
|
||||||
if(res.data.fsJSONSync){
|
if(res.data.fsJSONSync){
|
||||||
@ -131,13 +135,15 @@ module.ConfigStore = core.ImageGridFeatures.Feature({
|
|||||||
['storeDataLoaded',
|
['storeDataLoaded',
|
||||||
function(data){
|
function(data){
|
||||||
var base = this.__base_config = this.__base_config || this.config
|
var base = this.__base_config = this.__base_config || this.config
|
||||||
|
//var ls_path = '/${ROOT_PATH}/config'
|
||||||
|
var ls_path = 'config'
|
||||||
|
|
||||||
// XXX sort out load priority/logic...
|
// XXX sort out load priority/logic...
|
||||||
// - one or the other or both?
|
// - one or the other or both?
|
||||||
// - what order?
|
// - what order?
|
||||||
|
|
||||||
if((data.localStorage || {}).config){
|
if((data.storage || {})[ls_path]){
|
||||||
var config = data.localStorage.config || {}
|
var config = data.storage[ls_path] || {}
|
||||||
config.__proto__ = base
|
config.__proto__ = base
|
||||||
this.config = config
|
this.config = config
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,6 +49,7 @@ var StoreActions = actions.Actions({
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// XXX this is almost the same as .collection_handlers...
|
// XXX this is almost the same as .collection_handlers...
|
||||||
|
// XXX add support for aliases...
|
||||||
get stores(){
|
get stores(){
|
||||||
return this.cache('stores', function(d){
|
return this.cache('stores', function(d){
|
||||||
var res = {}
|
var res = {}
|
||||||
@ -145,19 +146,6 @@ var StoreActions = actions.Actions({
|
|||||||
}],
|
}],
|
||||||
|
|
||||||
// base API...
|
// base API...
|
||||||
// XXX we need to be able to save/load specific part of the data...
|
|
||||||
// ...i.e. query by store and/or key...
|
|
||||||
// the syntax could be:
|
|
||||||
// <store>:<path>
|
|
||||||
// <store>:<event>:<path>
|
|
||||||
//
|
|
||||||
// Example:
|
|
||||||
// 'localstorage:config' - save config to localStorage
|
|
||||||
// 'localstorage:*' - save all to localstorage
|
|
||||||
// '*:config' - save config to all supported stores
|
|
||||||
// '*:*' - save everything
|
|
||||||
//
|
|
||||||
// ...this must be supported by .prepareStoreToSave(..)
|
|
||||||
prepareStoreToSave: ['- Store/',
|
prepareStoreToSave: ['- Store/',
|
||||||
core.doc`
|
core.doc`
|
||||||
|
|
||||||
@ -209,6 +197,7 @@ var StoreActions = actions.Actions({
|
|||||||
NOTE: this can be called multiple times, once per each store.
|
NOTE: this can be called multiple times, once per each store.
|
||||||
NOTE: only one store data set is included per call.`,
|
NOTE: only one store data set is included per call.`,
|
||||||
function(data){ return data || {} }],
|
function(data){ return data || {} }],
|
||||||
|
|
||||||
// XXX this is different from .prepareIndexForWrite(..) in that there
|
// XXX this is different from .prepareIndexForWrite(..) in that there
|
||||||
// is no default data set...
|
// is no default data set...
|
||||||
// XXX async???
|
// XXX async???
|
||||||
@ -339,6 +328,7 @@ module.Store = core.ImageGridFeatures.Feature({
|
|||||||
|
|
||||||
// NOTE: the doc is reused for both localStorage and sessionStorage with
|
// NOTE: the doc is reused for both localStorage and sessionStorage with
|
||||||
// appropriate automated changes...
|
// appropriate automated changes...
|
||||||
|
// XXX Q: do we save to ROOT_PATH by default???
|
||||||
var __storageHandler_doc =
|
var __storageHandler_doc =
|
||||||
core.doc`Handle localStorage store data...
|
core.doc`Handle localStorage store data...
|
||||||
|
|
||||||
@ -384,8 +374,9 @@ var __storageHandler_doc =
|
|||||||
|
|
||||||
HOTE: other path syntax is ignored and the key will be saved as-is.
|
HOTE: other path syntax is ignored and the key will be saved as-is.
|
||||||
`
|
`
|
||||||
function makeStorageHandler(storage){
|
function makeStorageHandler(storage, alias){
|
||||||
var func = function(data, key){
|
var func = function(data, key){
|
||||||
|
alias = alias || storage
|
||||||
storage = typeof(storage) == typeof('str') ? window[storage] : storage
|
storage = typeof(storage) == typeof('str') ? window[storage] : storage
|
||||||
|
|
||||||
var root_pattern = /^(\.\.)?[\\\/]/
|
var root_pattern = /^(\.\.)?[\\\/]/
|
||||||
@ -398,6 +389,14 @@ function makeStorageHandler(storage){
|
|||||||
|
|
||||||
// clear...
|
// clear...
|
||||||
if(data === null){
|
if(data === null){
|
||||||
|
// remove specific key...
|
||||||
|
if(key){
|
||||||
|
var data = func.call(this)
|
||||||
|
data[key] = undefined
|
||||||
|
func.call(this, data)
|
||||||
|
|
||||||
|
// clear all...
|
||||||
|
} else {
|
||||||
var d = storage[root]
|
var d = storage[root]
|
||||||
d = d != undefined ? JSON.parse(d) : {}
|
d = d != undefined ? JSON.parse(d) : {}
|
||||||
;(d.__root_paths__ || [])
|
;(d.__root_paths__ || [])
|
||||||
@ -405,13 +404,26 @@ function makeStorageHandler(storage){
|
|||||||
var key = resolvePath(p)
|
var key = resolvePath(p)
|
||||||
delete storage[key] })
|
delete storage[key] })
|
||||||
delete storage[root]
|
delete storage[root]
|
||||||
|
}
|
||||||
|
|
||||||
// set...
|
// set...
|
||||||
|
// NOTE: this will update existing data set...
|
||||||
|
// NOTE: attrs explicitly set to undefined are removed...
|
||||||
} else if(data){
|
} else if(data){
|
||||||
if(key){
|
if(key){
|
||||||
data = { key: data }
|
data = { [key]: data }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update existing data...
|
||||||
|
var old = func.call(this)
|
||||||
|
Object.keys(data).forEach(function(k){
|
||||||
|
if(data[k] === undefined){
|
||||||
|
delete old[k]
|
||||||
|
delete data[k]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
data = Object.assign(old, data)
|
||||||
|
|
||||||
var root_data = {}
|
var root_data = {}
|
||||||
var root_paths = []
|
var root_paths = []
|
||||||
|
|
||||||
@ -471,11 +483,11 @@ var StoreLocalStorageActions = actions.Actions({
|
|||||||
|
|
||||||
// NOTE: for docs see __storageHandler_doc...
|
// NOTE: for docs see __storageHandler_doc...
|
||||||
localStorageDataHandler: ['- Store/',
|
localStorageDataHandler: ['- Store/',
|
||||||
{handle_data_store: 'localStorage',},
|
{handle_data_store: 'storage',},
|
||||||
makeStorageHandler('localStorage')],
|
makeStorageHandler('localStorage', 'storage')],
|
||||||
sessionStorageDataHandler: ['- Store/',
|
sessionStorageDataHandler: ['- Store/',
|
||||||
{handle_data_store: 'sessionStorage',},
|
{handle_data_store: 'session',},
|
||||||
makeStorageHandler('sessionStorage')],
|
makeStorageHandler('sessionStorage', 'session')],
|
||||||
})
|
})
|
||||||
|
|
||||||
var StoreLocalStorage =
|
var StoreLocalStorage =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user