Add comments to todomvc

This commit is contained in:
mike-thompson-day8 2015-03-07 18:10:17 +11:00
parent 46b8848f3b
commit 030e57135f
1 changed files with 12 additions and 7 deletions

View File

@ -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)))