Change datastore to not need to deserialize LocalStorage for every read
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { fetchLocations } from './api.js';
|
||||
import { DataStore } from './datastore.js';
|
||||
|
||||
let element_locations_search = document.querySelector("#locations-search");
|
||||
let element_query = document.querySelector("#locations-search-query");
|
||||
@@ -9,7 +8,7 @@ export function setupLocationsSearch() {
|
||||
element_query.addEventListener("change", (event) => {
|
||||
element_response.innerText = "Loading…";
|
||||
fetchLocations(event.target.value).then(result => {
|
||||
DataStore.locations.rememberAll(result);
|
||||
window.dataStore.locations.rememberAll(result);
|
||||
element_response.innerText = "";
|
||||
result.forEach(location => {
|
||||
let location_element = createLocationElement(location);
|
||||
@@ -25,7 +24,7 @@ function createLocationElement(location) {
|
||||
location_element.dataset.locationId = location.id;
|
||||
|
||||
location_element.addEventListener("click", event => {
|
||||
DataStore.recent_locations.remember(event.target.dataset.locationId);
|
||||
window.dataStore.recent_locations.remember(event.target.dataset.locationId);
|
||||
element_locations_search.locationSelectedCallback(event.target.innerText, event.target.dataset.locationId);
|
||||
element_locations_search.style.display = "none";
|
||||
});
|
||||
@@ -41,8 +40,8 @@ export function attachLocationsSearch(search_element) {
|
||||
};
|
||||
element_query.value = "";
|
||||
element_response.innerText = "";
|
||||
let locations = DataStore.locations.get();
|
||||
for (let location_id of DataStore.recent_locations.get()) {
|
||||
let locations = window.dataStore.locations.data;
|
||||
for (let location_id of window.dataStore.recent_locations.data) {
|
||||
let location = locations[location_id];
|
||||
let el = createLocationElement(location);
|
||||
element_response.appendChild(el);
|
||||
|
Reference in New Issue
Block a user