| 
									
										
										
										
											2020-08-17 17:23:15 +02:00
										 |  |  | import {UIEventSource} from "../UIEventSource"; | 
					
						
							| 
									
										
										
										
											2020-07-24 17:53:09 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | export class LocalStorageSource { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static Get(key: string, defaultValue: string = undefined): UIEventSource<string> { | 
					
						
							| 
									
										
										
										
											2020-07-31 17:11:44 +02:00
										 |  |  |         try { | 
					
						
							|  |  |  |             const saved = localStorage.getItem(key); | 
					
						
							|  |  |  |             const source = new UIEventSource<string>(saved ?? defaultValue); | 
					
						
							| 
									
										
										
										
											2020-07-24 17:53:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-31 17:11:44 +02:00
										 |  |  |             source.addCallback((data) => { | 
					
						
							|  |  |  |                 localStorage.setItem(key, data); | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |             return source; | 
					
						
							|  |  |  |         } catch (e) { | 
					
						
							|  |  |  |             return new UIEventSource<string>(defaultValue); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-24 17:53:09 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-31 17:11:44 +02:00
										 |  |  | } |