| 
									
										
										
										
											2022-08-03 01:35:19 +03:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							|  |  |  | ((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define) | 
					
						
							|  |  |  | (function(require){ var module={} // make module AMD/node compatible...
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var object = require('ig-object') | 
					
						
							|  |  |  | var types = require('ig-types') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-05 18:21:18 +03:00
										 |  |  | var pwpath = require('../path') | 
					
						
							| 
									
										
										
										
											2022-08-03 01:35:19 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-05 18:21:18 +03:00
										 |  |  | var base = require('./base') | 
					
						
							| 
									
										
										
										
											2022-08-03 01:35:19 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //---------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // XXX EXPERIMENTAL, needs testing in browser...
 | 
					
						
							|  |  |  | var localStorageStore = | 
					
						
							|  |  |  | module.localStorageStore = { | 
					
						
							| 
									
										
										
										
											2022-09-01 01:14:34 +03:00
										 |  |  | 	__proto__: base.Store, | 
					
						
							| 
									
										
										
										
											2022-08-03 01:35:19 +03:00
										 |  |  | 	__prefix__: '--pwiki:', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// XXX add caching of unserialized data???
 | 
					
						
							|  |  |  | 	data: | 
					
						
							|  |  |  | 		typeof(localStorage) != 'undefined' ? | 
					
						
							|  |  |  | 			localStorage | 
					
						
							|  |  |  | 			: undefined, | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2022-10-20 17:23:14 +03:00
										 |  |  | 	// XXX INDEX...
 | 
					
						
							| 
									
										
										
										
											2022-08-03 01:35:19 +03:00
										 |  |  | 	__paths__: function(){ | 
					
						
							|  |  |  | 		var that = this | 
					
						
							|  |  |  | 		return Object.keys(this.data) | 
					
						
							|  |  |  | 			.map(function(k){  | 
					
						
							|  |  |  | 				return k.startsWith(that.__prefix__) ? | 
					
						
							|  |  |  | 					k.slice((that.__prefix__ ?? '').length)  | 
					
						
							|  |  |  | 					: [] })  | 
					
						
							|  |  |  | 			.flat() }, | 
					
						
							|  |  |  | 	__exists__: function(path){ | 
					
						
							|  |  |  | 		return ((this.__prefix__ ?? '')+ path) in this.data  | 
					
						
							|  |  |  | 			&& path }, | 
					
						
							|  |  |  | 	__get__: function(path){ | 
					
						
							|  |  |  | 		path = (this.__prefix__ ?? '')+ path | 
					
						
							|  |  |  | 		return path in this.data ? | 
					
						
							|  |  |  | 			JSON.parse(this.data[path])  | 
					
						
							|  |  |  | 			: undefined }, | 
					
						
							|  |  |  | 	__update__: function(path, data={}){ | 
					
						
							|  |  |  | 		this.data[(this.__prefix__ ?? '')+ path] =  | 
					
						
							|  |  |  | 			JSON.stringify(data) }, | 
					
						
							|  |  |  | 	__delete__: function(path){ | 
					
						
							|  |  |  | 		delete this.data[(this.__prefix__ ?? '')+ path] }, | 
					
						
							| 
									
										
										
										
											2022-08-04 14:29:25 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	clear: function(){ | 
					
						
							|  |  |  | 		for(var e in this.data){ | 
					
						
							|  |  |  | 			if(e.startsWith(this.__prefix__)){ | 
					
						
							|  |  |  | 				delete this.data[e] } }  | 
					
						
							|  |  |  | 		return this }, | 
					
						
							| 
									
										
										
										
											2022-08-03 01:35:19 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-04 14:29:25 +03:00
										 |  |  | // XXX
 | 
					
						
							| 
									
										
										
										
											2022-08-03 01:35:19 +03:00
										 |  |  | 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 }) |