Preserve ordering of paths by storing as a list, not a set

This commit is contained in:
Daniel Compton 2017-11-15 15:56:39 +13:00
parent 0c42aff532
commit 9391d1c162
2 changed files with 9 additions and 7 deletions

View File

@ -7,7 +7,7 @@
show-panel? (localstorage/get "show-panel" false)
selected-tab (localstorage/get "selected-tab" :traces)
filter-items (localstorage/get "filter-items" [])
app-db-paths (localstorage/get "app-db-paths" #{})]
app-db-paths (localstorage/get "app-db-paths" '())]
(rf/dispatch [:settings/panel-width% panel-width%])
(rf/dispatch [:settings/show-panel? show-panel?])
(rf/dispatch [:settings/selected-tab selected-tab])

View File

@ -152,13 +152,14 @@
(rf/reg-event-db
:app-db/paths
(fn [db [_ paths]]
(localstorage/save! "app-db-paths" paths)
(assoc-in db [:app-db :paths] paths)))
(let [new-paths (into [] paths)] ;; Don't use sets, use vectors
(localstorage/save! "app-db-paths" paths)
(assoc-in db [:app-db :paths] paths))))
(rf/reg-event-db
:app-db/remove-path
(fn [db [_ path]]
(let [new-db (update-in db [:app-db :paths] disj path)]
(let [new-db (update-in db [:app-db :paths] #(remove (fn [p] (= p path)) %))]
(localstorage/save! "app-db-paths" (get-in new-db [:app-db :paths]))
new-db)))
@ -172,9 +173,10 @@
(catch :default e
nil))]
(if (some? path)
(-> db
(update-in [:app-db :paths] conj path)
(assoc-in [:app-db :search-string] ""))
(do (localstorage/save! "app-db-paths" (cons path (get-in db [:app-db :paths])))
(-> db
(update-in [:app-db :paths] #(cons path %))
(assoc-in [:app-db :search-string] "")))
db))))
(rf/reg-event-db