-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.cljs
59 lines (46 loc) · 1.38 KB
/
controller.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
(ns tape.guis7.app.guis.temperature-converter.controller
(:require [reitit.coercion.spec :as rcs]
[re-frame.core :as rf]
[tape.mvc :as mvc :include-macros true]
[tape.guis7.app.guis.temperature-converter.model
:as temperature-converter.m]))
;;; Routes
(def ^{::mvc/reg ::mvc/routes} routes
["/temperature-converter" {:coercion rcs/coercion}
["" ::index]])
;;; Handlers
(defn index
{::mvc/reg ::mvc/event-db}
[_ _] {})
(def coerce-float
(rf/->interceptor
:id ::coerce-float
:before (fn unwrap-before [context]
(update-in context [:coeffects :event 1]
temperature-converter.m/coerce-float))))
(defn from-celsius
{::mvc/reg ::mvc/event-db
::mvc/interceptors [coerce-float (rf/path [::scope])]}
[_ [_ celsius]]
(when celsius
(temperature-converter.m/from-celsius celsius)))
(defn from-fahrenheit
{::mvc/reg ::mvc/event-db
::mvc/interceptors [coerce-float (rf/path [::scope])]}
[_ [_ fahrenheit]]
(when fahrenheit
(temperature-converter.m/from-fahrenheit fahrenheit)))
;;; Sub
(defn scope
{::mvc/reg ::mvc/sub}
[db _] (::scope db))
(defn celsius
{::mvc/reg ::mvc/sub
::mvc/signals [:<- [::scope]]}
[scope _] (:celsius scope))
(defn fahrenheit
{::mvc/reg ::mvc/sub
::mvc/signals [:<- [::scope]]}
[scope _] (:fahrenheit scope))
;;; Module
(mvc/defm ::module)