mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 03:10:07 +00:00 
			
		
		
		
	tweaking the api + some cleanup... still thinking...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									6709499554
								
							
						
					
					
						commit
						8320494490
					
				| @ -112,9 +112,10 @@ module.ConfigStore = core.ImageGridFeatures.Feature({ | |||||||
| 	handlers: [ | 	handlers: [ | ||||||
| 		// XXX need to update rather than rewrite things...
 | 		// XXX need to update rather than rewrite things...
 | ||||||
| 		['prepareStoreToSave',  | 		['prepareStoreToSave',  | ||||||
| 			function(res, query){ | 			function(res, query, data){ | ||||||
| 				var ls_path = '${INSTANCE}/config' | 				var ls_path = '${INSTANCE}/config' | ||||||
| 				//var ls_path = 'config'
 | 				//var ls_path = 'config'
 | ||||||
|  | 				query = this.parseStoreQuery(query) | ||||||
| 				 | 				 | ||||||
| 				// config not requested...
 | 				// config not requested...
 | ||||||
| 				if(query.key != '*'  | 				if(query.key != '*'  | ||||||
| @ -127,12 +128,14 @@ module.ConfigStore = core.ImageGridFeatures.Feature({ | |||||||
| 				// 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(query.store.indexOf('storage') >= 0){ | 				if(query.store.indexOf('storage') >= 0){ | ||||||
| 					res.data.storage[ls_path] = this.config | 					//res.data.storage[ls_path] = this.config
 | ||||||
|  | 					res.data.storage[ls_path] = data || this.config | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| 				if(query.store.indexOf('fileSync') >= 0){ | 				if(query.store.indexOf('fileSync') >= 0){ | ||||||
| 					// XXX should this include path???
 | 					// XXX should this include path???
 | ||||||
| 					res.data.fileSync[this.config['config-fs-filename'] || '.ImageGrid.json'] = this.config | 					//res.data.fileSync[this.config['config-fs-filename'] || '.ImageGrid.json'] = this.config
 | ||||||
|  | 					res.data.fileSync[this.config['config-fs-filename'] || '.ImageGrid.json'] = data || this.config | ||||||
| 				} | 				} | ||||||
| 			}], | 			}], | ||||||
| 		//['prepareIndexForLoad',
 | 		//['prepareIndexForLoad',
 | ||||||
|  | |||||||
| @ -192,22 +192,12 @@ var StoreActions = actions.Actions({ | |||||||
| 			return query | 			return query | ||||||
| 		}], | 		}], | ||||||
| 
 | 
 | ||||||
| 	// XXX this should:
 | 
 | ||||||
| 	// 		- parse query
 | 	// HL API...
 | ||||||
| 	// 		- call: .prepareStoreToSave(..) / .prepareStoreToLoad(..) ???
 | 	//
 | ||||||
| 	// 		- call: .saveStore(..) / .loadStore(..)
 |  | ||||||
| 	// XXX need to be able to either just get data or load/init it too...
 |  | ||||||
| 	// 		i.e. we need two stages/APIs:
 |  | ||||||
| 	// 			- get/set/del key -- via .store(..)
 |  | ||||||
| 	// 			- load/save key -- via system events and specific actions...
 |  | ||||||
| 	// 		e.g. just get the config from store or get it and set it to .config...
 |  | ||||||
| 	// 			- load/save/clear 
 |  | ||||||
| 	// 				-> .loadConfig() / .saveConfig() / .resetConfig()
 |  | ||||||
| 	// 			- get/set/del 
 |  | ||||||
| 	// 				-> .store('*:config') / .store('*:config', value) / .store('*:config', null)
 |  | ||||||
| 	// 		...think initializing should be done by the owner plugin...
 |  | ||||||
| 	// XXX sync or async or both???
 | 	// XXX sync or async or both???
 | ||||||
| 	// 		...should we add an .onStore(query, handler) event/promise???
 | 	// 		...should we add an .onStore(query, handler) event/promise???
 | ||||||
|  | 	// 		one way to do this is to place promises into res where async...
 | ||||||
| 	store: ['- Store/', | 	store: ['- Store/', | ||||||
| 		core.doc` | 		core.doc` | ||||||
| 
 | 
 | ||||||
| @ -222,6 +212,16 @@ var StoreActions = actions.Actions({ | |||||||
| 			.store(query, null) | 			.store(query, null) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | 		Returns: | ||||||
|  | 			{ | ||||||
|  | 				<store>: { | ||||||
|  | 					<key>: <value>, | ||||||
|  | 					... | ||||||
|  | 				}, | ||||||
|  | 				... | ||||||
|  | 			} | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| 		NOTE: for query syntax see .parseStoreQuery(..) | 		NOTE: for query syntax see .parseStoreQuery(..) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -237,87 +237,26 @@ var StoreActions = actions.Actions({ | |||||||
| 				.loadStore(..) | 				.loadStore(..) | ||||||
| 				.saveStore(..) | 				.saveStore(..) | ||||||
| 				.clearStore(..) | 				.clearStore(..) | ||||||
|  | 
 | ||||||
|  | 			NOTE: .prepareStoreToSave(..) is triggered only when no data | ||||||
|  | 				is passed to .saveStore(..)... | ||||||
|  | 			NOTE: .prepareStoreToLoad(..) is called every time .loadStore(..) | ||||||
|  | 				is called... | ||||||
|  | 
 | ||||||
| 		`,
 | 		`,
 | ||||||
| 		function(query, value){ | 		function(query, value){ | ||||||
| 			query = this.parseStoreQuery(query) | 			query = this.parseStoreQuery(query) | ||||||
| 
 |  | ||||||
| 			return ( | 			return ( | ||||||
| 				// get...
 | 				// get...
 | ||||||
| 				// XXX should this call the .prepareStoreToLoad(..) or 
 |  | ||||||
| 				// 		should it be handled in .loadStore(..)???
 |  | ||||||
| 				arguments.length == 1 ? | 				arguments.length == 1 ? | ||||||
| 					//this.loadStore(query)
 | 					this.loadStore(query) | ||||||
| 					this.prepareStoreToLoad( |  | ||||||
| 						query,  |  | ||||||
| 						this.loadStore(query)) |  | ||||||
| 				// delete...
 | 				// delete...
 | ||||||
| 				: (value === undefined && arguments.length == 2) ? | 				: (value === undefined && arguments.length == 2) ? | ||||||
| 					this.clearStore(query) | 					this.clearStore(query) | ||||||
| 				// set...
 | 				// set...
 | ||||||
| 				// XXX should this call the .prepareStoreToSave(..) or 
 | 				: (this.saveStore(query, value) && undefined) ) }], | ||||||
| 				// 		should it be handled in .saveStore(..)???
 |  | ||||||
| 				//: this.saveStore(query, value) ) }],
 |  | ||||||
| 				: this.saveStore( |  | ||||||
| 					query,  |  | ||||||
| 					value || this.prepareStoreToSave(query)) ) }], |  | ||||||
| 
 | 
 | ||||||
| 	// XXX these expect the parsed query...
 | 	// Application API...
 | ||||||
| 	// XXX extend these per store...
 |  | ||||||
| 	// XXX should clients trigger a stored event???
 |  | ||||||
| 	saveStore: ['- Store/', |  | ||||||
| 		core.doc` |  | ||||||
| 
 |  | ||||||
| 			.saveStore(query, data) |  | ||||||
| 
 |  | ||||||
| 		`,
 |  | ||||||
| 		core.notUserCallable(function(query, data){ |  | ||||||
| 			// Extending action must:
 |  | ||||||
| 			// 	- save query/data to it's store...
 |  | ||||||
| 			// XXX should this be called outer???
 |  | ||||||
| 			// XXX how do we handle the case where no data was given???
 |  | ||||||
| 			// XXX how do we pass the results to handlers???
 |  | ||||||
| 			//this.prepareStoreToSave(query, data)
 |  | ||||||
| 		})], |  | ||||||
| 	// XXX should this be sync or async???
 |  | ||||||
| 	// 		one way to do this is to place promises into res where async...
 |  | ||||||
| 	loadStore: ['- Store/', |  | ||||||
| 		core.doc` |  | ||||||
| 		`,
 |  | ||||||
| 		core.notUserCallable(function(query){ |  | ||||||
| 			// Extending action must:
 |  | ||||||
| 			// 	- populate query from it's store...
 |  | ||||||
| 			// 	- trigger .storeDataLoaded(store) event when done...
 |  | ||||||
| 			//
 |  | ||||||
| 			// NOTE: if query.store is a single value then the root object
 |  | ||||||
| 			// 		must be populated, otherwise the appropriate section 
 |  | ||||||
| 			// 		should be used...
 |  | ||||||
| 			// 		e.g.
 |  | ||||||
| 			// 			if(query.store.length == 1){
 |  | ||||||
| 			//				res = data
 |  | ||||||
| 			// 			} else {
 |  | ||||||
| 			// 				res['store-key'] = data
 |  | ||||||
| 			// 			}
 |  | ||||||
| 			var res = {} |  | ||||||
| 			query  |  | ||||||
| 				&& query.store.length >= 1 |  | ||||||
| 				&& query.store.forEach(function(s){ res[s] = {} }) |  | ||||||
| 			// XXX should this be called outer???
 |  | ||||||
| 			//return this.prepareStoreToLoad(query, res)
 |  | ||||||
| 			return res |  | ||||||
| 		})], |  | ||||||
| 	// XXX should clients trigger a stored event???
 |  | ||||||
| 	clearStore: ['- Store/', |  | ||||||
| 		core.doc` |  | ||||||
| 		`,
 |  | ||||||
| 		core.notUserCallable(function(query){ |  | ||||||
| 			// Extending action:
 |  | ||||||
| 			// 	- must clear query from it's store...
 |  | ||||||
| 		})], |  | ||||||
| 
 |  | ||||||
| 	// XXX these should:
 |  | ||||||
| 	// 		- transform data to/from saved state
 |  | ||||||
| 	// XXX these expect the parsed query...
 |  | ||||||
| 	// XXX define these per data set...
 |  | ||||||
| 	prepareStoreToSave: ['- Store/', | 	prepareStoreToSave: ['- Store/', | ||||||
| 		core.doc` | 		core.doc` | ||||||
| 
 | 
 | ||||||
| @ -342,7 +281,6 @@ var StoreActions = actions.Actions({ | |||||||
| 			query = this.parseStoreQuery(query) | 			query = this.parseStoreQuery(query) | ||||||
| 			var stores = query.store || defaults.store | 			var stores = query.store || defaults.store | ||||||
| 
 | 
 | ||||||
| 			// XXX is this needed here???
 |  | ||||||
| 			data = data || {} | 			data = data || {} | ||||||
| 			query.store.forEach(function(s){ data[s] = {} }) | 			query.store.forEach(function(s){ data[s] = {} }) | ||||||
| 
 | 
 | ||||||
| @ -355,8 +293,6 @@ var StoreActions = actions.Actions({ | |||||||
| 				data: data || {}, | 				data: data || {}, | ||||||
| 			}  | 			}  | ||||||
| 		}], | 		}], | ||||||
| 	// XXX use query???
 |  | ||||||
| 	// XXX should this be the same as .prepareStoreToSave(..)???
 |  | ||||||
| 	prepareStoreToLoad: ['- Store/', | 	prepareStoreToLoad: ['- Store/', | ||||||
| 		core.doc` | 		core.doc` | ||||||
| 		 | 		 | ||||||
| @ -365,9 +301,75 @@ var StoreActions = actions.Actions({ | |||||||
| 		function(query, data){  | 		function(query, data){  | ||||||
| 			return data || {} }], | 			return data || {} }], | ||||||
| 
 | 
 | ||||||
|  | 	// Store API...
 | ||||||
|  | 	// XXX BUG: .saveStore('storage:moo', 123) saves this.data
 | ||||||
|  | 	saveStore: ['- Store/', | ||||||
|  | 		core.doc` | ||||||
|  | 
 | ||||||
|  | 			Build and store all/query data... | ||||||
|  | 			.saveStore() | ||||||
|  | 			.saveStore(query) | ||||||
|  | 				-> data | ||||||
|  | 
 | ||||||
|  | 			Store query data... | ||||||
|  | 			.saveStore(query, data) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	// XXX EXPERIMENTAL / LEGACY STUFF...
 | 		NOTE: this only calls .prepareStoreToSave(..) if no data is given... | ||||||
|  | 		NOTE: the returned data is the same format as returned by .store(..) | ||||||
|  | 		`,
 | ||||||
|  | 		core.notUserCallable(function(query, data){ | ||||||
|  | 			// Extending action must:
 | ||||||
|  | 			// 	- save query/data to it's store...
 | ||||||
|  | 			return data == null ?  | ||||||
|  | 				this.prepareStoreToSave(this.parseStoreQuery(query), {}).data | ||||||
|  | 				: undefined | ||||||
|  | 		})], | ||||||
|  | 	loadStore: ['- Store/', | ||||||
|  | 		core.doc` | ||||||
|  | 
 | ||||||
|  | 			.loadStore(query) | ||||||
|  | 				-> data | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 		NOTE: async stores will write promises to .data | ||||||
|  | 		`,
 | ||||||
|  | 		core.notUserCallable(function(query){ | ||||||
|  | 			// Extending action must:
 | ||||||
|  | 			// 	- populate query from it's store...
 | ||||||
|  | 			// 	- trigger .storeDataLoaded(store) event when done...
 | ||||||
|  | 			//
 | ||||||
|  | 			// NOTE: if query.store is a single value then the root object
 | ||||||
|  | 			// 		must be populated, otherwise the appropriate section 
 | ||||||
|  | 			// 		should be used...
 | ||||||
|  | 			// 		e.g.
 | ||||||
|  | 			// 			if(query.store.length == 1){
 | ||||||
|  | 			//				res = data
 | ||||||
|  | 			// 			} else {
 | ||||||
|  | 			// 				res['store-key'] = data
 | ||||||
|  | 			// 			}
 | ||||||
|  | 			var res = {} | ||||||
|  | 			var q = this.parseStoreQuery(query) | ||||||
|  | 			query | ||||||
|  | 				&& q.store.length >= 1 | ||||||
|  | 				&& q.store.forEach(function(s){ res[s] = {} }) | ||||||
|  | 			return this.prepareStoreToLoad(q, res) | ||||||
|  | 		})], | ||||||
|  | 	clearStore: ['- Store/', | ||||||
|  | 		core.doc` | ||||||
|  | 
 | ||||||
|  | 			.clearStore(query) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 		`,
 | ||||||
|  | 		core.notUserCallable(function(query){ | ||||||
|  | 			// Extending action:
 | ||||||
|  | 			// 	- must clear query from it's store...
 | ||||||
|  | 		})], | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	// XXX LEGACY STUFF... (???)
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	// XXX REVISE API
 | 	// XXX REVISE API
 | ||||||
| @ -665,39 +667,49 @@ module.StoreLocalStorage = core.ImageGridFeatures.Feature({ | |||||||
| 		// XXX should we use .localStorageDataHandler(..) here???
 | 		// XXX should we use .localStorageDataHandler(..) here???
 | ||||||
| 		// XXX the following two sections are almost identical...
 | 		// XXX the following two sections are almost identical...
 | ||||||
| 		['saveStore',  | 		['saveStore',  | ||||||
| 			function(_, query, value){ | 			function(res, query, value){ | ||||||
|  | 				var q = this.parseStoreQuery(query) | ||||||
| 				query  | 				query  | ||||||
| 					&& query.key instanceof Array | 					&& q.key instanceof Array | ||||||
| 					&& query.store.indexOf('storage') >= 0 | 					&& q.store.indexOf('storage') >= 0 | ||||||
| 					&& query.key.forEach(function(k){ | 					&& q.key.forEach(function(k){ | ||||||
| 						this.localStorageDataHandler(k, value) }.bind(this)) }], | 						this.localStorageDataHandler( | ||||||
|  | 							k,  | ||||||
|  | 							res !== this ? res.data : value) }.bind(this)) }], | ||||||
| 		['loadStore',  | 		['loadStore',  | ||||||
| 			function(res, query){ | 			function(res, query){ | ||||||
|  | 				query = this.parseStoreQuery(query) | ||||||
| 				res.storage | 				res.storage | ||||||
| 					&& Object.assign(res.storage, this.localStorageDataHandler(query.key)) }], | 					&& Object.assign(res.storage, this.localStorageDataHandler(query.key)) }], | ||||||
| 		['clearStore',  | 		['clearStore',  | ||||||
| 			function(_, query){ | 			function(_, query){ | ||||||
|  | 				var q = this.parseStoreQuery(query) | ||||||
| 				query  | 				query  | ||||||
| 					&& query.store.indexOf('storage') >= 0 | 					&& q.store.indexOf('storage') >= 0 | ||||||
| 					&& this.localStorageDataHandler(query.key, null) }], | 					&& this.localStorageDataHandler(q.key, null) }], | ||||||
| 
 | 
 | ||||||
| 		// sessionStorage...
 | 		// sessionStorage...
 | ||||||
| 		['saveStore',  | 		['saveStore',  | ||||||
| 			function(_, query, value){ | 			function(res, query, value){ | ||||||
|  | 				var q = this.parseStoreQuery(query) | ||||||
| 				query  | 				query  | ||||||
| 					&& query.key instanceof Array | 					&& q.key instanceof Array | ||||||
| 					&& query.store.indexOf('session') >= 0 | 					&& q.store.indexOf('session') >= 0 | ||||||
| 					&& query.key.forEach(function(k){ | 					&& q.key.forEach(function(k){ | ||||||
| 						this.sessionStorageDataHandler(k, value) }.bind(this)) }], | 						this.sessionStorageDataHandler( | ||||||
|  | 							k,  | ||||||
|  | 							res !== this ? res.data : value) }.bind(this)) }], | ||||||
| 		['loadStore',  | 		['loadStore',  | ||||||
| 			function(res, query){ | 			function(res, query){ | ||||||
|  | 				query = this.parseStoreQuery(query) | ||||||
| 				res.session | 				res.session | ||||||
| 					&& Object.assign(res.storage, this.sessionStorageDataHandler(query.key)) }], | 					&& Object.assign(res.storage, this.sessionStorageDataHandler(query.key)) }], | ||||||
| 		['clearStore',  | 		['clearStore',  | ||||||
| 			function(_, query){ | 			function(_, query){ | ||||||
|  | 				var q = this.parseStoreQuery(query) | ||||||
| 				query  | 				query  | ||||||
| 					&& query.store.indexOf('session') >= 0 | 					&& q.store.indexOf('session') >= 0 | ||||||
| 					&& this.sessionStorageDataHandler(query.key, null) }], | 					&& this.sessionStorageDataHandler(q.key, null) }], | ||||||
| 	], | 	], | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user