forked from MapComplete/MapComplete
		
	Add more checks in the import helper after user testing
This commit is contained in:
		
							parent
							
								
									2dac893bb3
								
							
						
					
					
						commit
						9617dbc34d
					
				
					 15 changed files with 344 additions and 94 deletions
				
			
		|  | @ -8,18 +8,24 @@ import {Utils} from "../../Utils"; | |||
| export class IdbLocalStorage { | ||||
| 
 | ||||
| 
 | ||||
|     public static Get<T>(key: string, options?: { defaultValue?: T, whenLoaded?: (t: T) => void }): UIEventSource<T> { | ||||
|     public static Get<T>(key: string, options?: { defaultValue?: T, whenLoaded?: (t: T | null) => void }): UIEventSource<T> { | ||||
|         const src = new UIEventSource<T>(options?.defaultValue, "idb-local-storage:" + key) | ||||
|         if (Utils.runningFromConsole) { | ||||
|             return src; | ||||
|         } | ||||
|         src.addCallback(v => idb.set(key, v)) | ||||
|          | ||||
|         idb.get(key).then(v => { | ||||
|             src.setData(v ?? options?.defaultValue); | ||||
|             if (options?.whenLoaded !== undefined) { | ||||
|                 options?.whenLoaded(v) | ||||
|             } | ||||
|         }).catch(err => { | ||||
|             console.warn("Loading from local storage failed due to", err) | ||||
|             if (options?.whenLoaded !== undefined) { | ||||
|                 options?.whenLoaded(null) | ||||
|             } | ||||
|         }) | ||||
|         src.addCallback(v => idb.set(key, v)) | ||||
|         return src; | ||||
| 
 | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue