diff --git a/examples/todomvc/src/todomvc/db.cljs b/examples/todomvc/src/todomvc/db.cljs index 62ee769..63337c7 100644 --- a/examples/todomvc/src/todomvc/db.cljs +++ b/examples/todomvc/src/todomvc/db.cljs @@ -1,18 +1,23 @@ (ns todomvc.db) -;; -- Default Value ---------------------------------------------------------- +;; -- Default app-db Value --------------------------------------------------- -(def default-value - {:todos (sorted-map) - :showing :all}) +(def default-value ;; what gets put into app-db by default. + {:todos (sorted-map) ;; use the (int) :id as the key + :showing :all}) ;; one of :all :done :completed ;; -- Local Storage ---------------------------------------------------------- -(def lsk "todos-key") ;; local store key +(def lsk "ls-key") ;; local store key -(defn ls->todos ;; read in todos from local storage +(defn ls->todos + "Read in a list of todos from local storage, and process into a + sorted-map, suitable for merging into app-db. + LocalStorage can only keep strings, so we loose keywords on the way in. + Here, on load, we struggle to recreate the lost keywords. But we'll stay + strong, and refuse to to wimp out and go with string keys" [] (some->> (.getItem js/localStorage lsk) (js/JSON.parse) @@ -24,6 +29,6 @@ (defn todos->ls! [todos] - (->> (clj->js (vals todos)) + (->> (clj->js (vals todos)) ;; Write just the todos, not the sorted-map (js/JSON.stringify) (.setItem js/localStorage lsk))) \ No newline at end of file