From c4b3e0f8f86cfaf217792159242c4ffddf62f358 Mon Sep 17 00:00:00 2001 From: mike-thompson-day8 Date: Thu, 5 Mar 2015 10:41:20 +1100 Subject: [PATCH] Try to add localstorage middleware. Failed because keywords are turned into strings. Duh! --- examples/todomvc/src/todomvc/handlers.cljs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/todomvc/src/todomvc/handlers.cljs b/examples/todomvc/src/todomvc/handlers.cljs index 3025bf1..1cce456 100644 --- a/examples/todomvc/src/todomvc/handlers.cljs +++ b/examples/todomvc/src/todomvc/handlers.cljs @@ -1,10 +1,10 @@ (ns todomvc.handlers (:require - [todomvc.db :refer [default-value valid-schema? get-local-storage]] + [todomvc.db :refer [default-value valid-schema? + get-local-storage set-local-storage!]] [re-frame.core :refer [register-pure-handler path after - trim-v - debug validate]])) + trim-v debug]])) ;; -- Middleware -------------------------------------------------------------- @@ -12,6 +12,8 @@ ;; checks that the structure in app-db matches the schema (def check-schema (after valid-schema?)) +(def write-ls (after set-local-storage!)) + ;; middleware for any handler which manipulates todos. (def todo-middleware [check-schema (path [:todos]) debug trim-v]) @@ -22,7 +24,7 @@ [todos] (if (empty? todos) 0 - (inc (apply max (keys todos))))) ;; hillariously inefficient, but yeah + (inc (last (keys todos))))) ;; -- Handlers ---------------------------------------------------------------- @@ -37,7 +39,7 @@ (register-pure-handler ;; handlers changes the footer filter :set-showing ;; event-id - [check-schema debug trim-v] ;; middleware (wraps the handler) + [write-ls check-schema debug trim-v] ;; middleware (wraps the handler) (fn ;; handler [db [filter-kw]] (assoc db :showing filter-kw)))