🐛 Add filter to remove groups without content in all files

This commit is contained in:
Andrés Moya 2021-05-07 16:17:38 +02:00 committed by Andrey Antukh
parent b50ffa087d
commit 42072f2584
7 changed files with 170 additions and 31 deletions

View file

@ -8,6 +8,7 @@
(:require
[app.util.transit :as t]
[app.util.timers :as tm]
[app.util.globals :as g]
[app.common.exceptions :as ex]))
(defn- ^boolean is-worker?
@ -36,17 +37,18 @@
(defn- load
[storage]
(let [len (.-length ^js storage)]
(reduce (fn [res index]
(let [key (.key ^js storage index)
val (.getItem ^js storage key)]
(try
(assoc res (t/decode key) (t/decode val))
(catch :default e
res))))
{}
(range len))))
(when storage
(let [len (.-length ^js storage)]
(reduce (fn [res index]
(let [key (.key ^js storage index)
val (.getItem ^js storage key)]
(try
(assoc res (t/decode key) (t/decode val))
(catch :default e
res))))
{}
(range len)))))
(defonce storage (atom (load js/localStorage)))
(defonce storage (atom (load (unchecked-get g/global "localStorage"))))
(add-watch storage :persistence #(persist js/localStorage %3 %4))