forked from MapComplete/MapComplete
First version which caches changesets if not uploaded
This commit is contained in:
parent
d72dbc21df
commit
6732c12a0c
7 changed files with 84 additions and 41 deletions
|
@ -4,6 +4,22 @@ import {UIEventSource} from "../UIEventSource";
|
|||
* UIEventsource-wrapper around localStorage
|
||||
*/
|
||||
export class LocalStorageSource {
|
||||
|
||||
static GetParsed(key: string, defaultValue : any){
|
||||
return LocalStorageSource.Get(key).map(
|
||||
str => {
|
||||
if(str === undefined){
|
||||
return defaultValue
|
||||
}
|
||||
try{
|
||||
return JSON.parse(str)
|
||||
}catch{
|
||||
return defaultValue
|
||||
}
|
||||
}, [],
|
||||
value => JSON.stringify(value)
|
||||
)
|
||||
}
|
||||
|
||||
static Get(key: string, defaultValue: string = undefined): UIEventSource<string> {
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue