43 lines
872 B
JavaScript
43 lines
872 B
JavaScript
|
import Log from "./Log.js";
|
||
|
|
||
|
export default class LocationStorage {
|
||
|
|
||
|
static KEY = 'midefos-idealista-location-storage';
|
||
|
|
||
|
static get storage() {
|
||
|
return window.localStorage;
|
||
|
}
|
||
|
|
||
|
static get data() {
|
||
|
if (!this._data) {
|
||
|
this._init();
|
||
|
}
|
||
|
return JSON.parse(this._data);
|
||
|
}
|
||
|
|
||
|
static get _data() {
|
||
|
return this.storage.getItem(this.key);
|
||
|
}
|
||
|
|
||
|
static get(name) {
|
||
|
const locations = this.data;
|
||
|
return locations[name];
|
||
|
}
|
||
|
|
||
|
static save(location) {
|
||
|
const locations = this.data;
|
||
|
locations[location.name] = location;
|
||
|
this._save(locations);
|
||
|
}
|
||
|
|
||
|
static _init() {
|
||
|
Log.debug(`Init location storage`);
|
||
|
this._save({});
|
||
|
}
|
||
|
|
||
|
static _save(data) {
|
||
|
const json = JSON.stringify(data);
|
||
|
this.storage.setItem(this.key, json);
|
||
|
}
|
||
|
|
||
|
}
|