This commit is contained in:
Mike Thompson 2017-07-16 19:50:00 +10:00
commit 0901c8ffc4
3 changed files with 22 additions and 23 deletions

View File

@ -1,6 +1,7 @@
(ns simple.core
(:require [reagent.core :as reagent]
[re-frame.core :as rf]))
[re-frame.core :as rf]
[clojure.string :as str]))
;; A detailed walk-through of this source code is provied in the docs:
;; https://github.com/Day8/re-frame/blob/master/docs/CodeWalkthrough.md
@ -13,7 +14,7 @@
(rf/dispatch [:timer now]))) ;; <-- dispatch used
;; Call the dispatching function every second.
;; `defonce` is like `def` but it ensures only instance is ever
;; `defonce` is like `def` but it ensures only one instance is ever
;; created in the face of figwheel hot-reloading of this file.
(defonce do-timer (js/setInterval dispatch-timer-event 1000))
@ -44,8 +45,7 @@
(rf/reg-sub
:time
(fn [db _] ;; db is current app state. 2nd unused param is query vector
(-> db
:time)))
(:time db))) ;; return a query computation over the application state
(rf/reg-sub
:time-color
@ -61,7 +61,7 @@
{:style {:color @(rf/subscribe [:time-color])}}
(-> @(rf/subscribe [:time])
.toTimeString
(clojure.string/split " ")
(str/split " ")
first)])
(defn color-input
@ -86,4 +86,3 @@
(rf/dispatch-sync [:initialize]) ;; puts a value into application state
(reagent/render [ui] ;; mount the application's ui into '<div id="app" />'
(js/document.getElementById "app")))

View File

@ -1,13 +1,14 @@
(ns todomvc.views
(:require [reagent.core :as reagent]
[re-frame.core :refer [subscribe dispatch]]))
[re-frame.core :refer [subscribe dispatch]]
[clojure.string :as str]))
(defn todo-input [{:keys [title on-save on-stop]}]
(let [val (reagent/atom title)
stop #(do (reset! val "")
(when on-stop (on-stop)))
save #(let [v (-> @val str clojure.string/trim)]
save #(let [v (-> @val str str/trim)]
(when (seq v) (on-save v))
(stop))]
(fn [props]

View File

@ -16,7 +16,7 @@
"Create an interceptor from named arguments"
[& {:as m :keys [id before after]}]
(when debug-enabled?
(if-let [unknown-keys (seq (clojure.set/difference
(if-let [unknown-keys (seq (set/difference
(-> m keys set)
mandatory-interceptor-keys))]
(console :error "re-frame: ->interceptor " m " has unknown keys:" unknown-keys)))
@ -195,4 +195,3 @@
(invoke-interceptors :before)
change-direction
(invoke-interceptors :after)))