Skip to content

Commit 192b93c

Browse files
Merge pull request #45 from Day8/develop
Move to v0.3.1
2 parents 3ff4625 + 769723c commit 192b93c

File tree

10 files changed

+114
-91
lines changed

10 files changed

+114
-91
lines changed

CHANGES.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11

2+
## v0.3.1 (2015-04-18)
3+
4+
Various small improvements and bug fixes:
5+
6+
- log-ex middleware added to core api (it was a mistake that it was missing)
7+
- modest improves to simple example. Better comments, layout, etc.
8+
- the anonymous functions in standard middleware now have meaningful
9+
names, which makes stack traces easier to understand.
10+
- #24 - Fix missing paren in README
11+
- #31 - Fix list formatting in README
12+
- #32 - fix a broken wiki link
13+
- #30 - Fix up the enrich docstring
14+
215

316
## v0.3.0 (2015-04-15)
417

518
### Headline
619

7-
820
- the middleware `after` and `enrich` now call the supplied function `f` with
921
both `db` and `v` (previously just `db`). Because javascript is so forgiving
1022
about function arity, this change is backwards compatible.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ Let's sketch out the situation described above ...
670670
{:name "c" :val 23 :flag "y"}])
671671

672672
(def app-db (reagent/atom {:items L
673-
:sort-by :name}) ;; sorted by the :name attribute
673+
:sort-by :name})) ;; sorted by the :name attribute
674674
```
675675

676676
The subscription-handler might be written:
@@ -897,7 +897,7 @@ Collectively, event handlers provide the control logic in a re-frame application
897897
An event handler is a pure function of two parameters:
898898

899899
1. current value in `app-db`. Note: that's the map **in** `app-db`, not the atom itself.
900-
2 an event (represented as a vector)
900+
2. an event (represented as a vector)
901901

902902
It returns the new value which should be reset! into `app-db`.
903903

examples/simple/example.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ <h1>Reagent example app – see README.md</h1>
1111
</div>
1212
<script src="target/client.js"></script>
1313
<script>
14-
simpleexample.core.run();
14+
window.onload = function () {
15+
simpleexample.core.run();
16+
}
1517
</script>
1618
</body>
1719
</html>

examples/simple/project.clj

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

2-
(defproject simple-re-frame "0.5.0-alpha3"
2+
(defproject simple-re-frame "0.5.0"
33
:dependencies [[org.clojure/clojure "1.6.0"]
44
[org.clojure/clojurescript "0.0-2816"]
5-
[reagent "0.5.0-alpha3"]
6-
[re-frame "0.3.0"]
7-
[figwheel "0.2.3-SNAPSHOT"]]
5+
[reagent "0.5.0"]
6+
[re-frame "0.3.1"]
7+
[figwheel "0.2.6"]]
88

99
:plugins [[lein-cljsbuild "1.0.4"]
1010
[lein-figwheel "0.2.3-SNAPSHOT"]]

examples/simple/src/simpleexample/core.cljs

+63-54
Original file line numberDiff line numberDiff line change
@@ -3,103 +3,112 @@
33
(:require [reagent.core :as reagent :refer [atom]]
44
[re-frame.core :refer [register-handler
55
path
6-
register-sub
7-
dispatch
6+
register-sub
7+
dispatch
8+
dispatch-sync
89
subscribe]]))
910

10-
11+
;; trigger a dispatch every second
1112
(defonce time-updater (js/setInterval
1213
#(dispatch [:timer (js/Date.)]) 1000))
1314

14-
;;; this is the initial state
15-
(defonce initial-state
15+
(def initial-state
1616
{:timer (js/Date.)
1717
:time-color "#f34"})
1818

19-
;; Handlers
20-
;-------------------------------------------------------------
2119

22-
;; This handler sets the initial state
23-
(register-handler
24-
;; the handler is passed a map (not an atom) and must return the new state
25-
;; of the db
26-
:initialize
20+
;; -- Event Handlers ----------------------------------------------------------
21+
22+
23+
(register-handler ;; setup initial state
24+
:initialize ;; usage: (submit [:initialize])
2725
(fn
2826
[db _]
29-
(merge db initial-state)))
27+
(merge db initial-state))) ;; what it returns becomes the new state
28+
3029

31-
;; This handler changes the color of the displayed time
3230
(register-handler
33-
;;; register-handler can take 3 arguments to allow you to insert middleware
34-
;;; see https://github.com/Day8/re-frame/wiki/Handler-Middleware
35-
:time-color
36-
(path [:time-color])
31+
:time-color ;; usage: (submit [:time-color 34562])
32+
(path [:time-color]) ;; this is middleware
3733
(fn
38-
;; the path handler allows you to get directly to items in the database
39-
;; return the value you want assoc'd in
40-
[time-color [_ value]]
34+
[time-color [_ value]] ;; path middleware adjusts the first parameter
4135
value))
4236

43-
;; This handler changes the value of the time
37+
4438
(register-handler
4539
:timer
4640
(fn
4741
;; the first item in the second argument is :timer the second is the
4842
;; new value
4943
[db [_ value]]
50-
(assoc db :timer value)))
44+
(assoc db :timer value))) ;; return the new version of db
45+
46+
47+
;; -- Subscription Handlers ---------------------------------------------------
48+
5149

52-
;; add subscriptions to :timer and :time-color
5350
(register-sub
5451
:timer
5552
(fn
56-
[db _]
57-
;; you need to wrap your subscription code in a reaction
58-
(reaction (:timer @db))))
53+
[db _] ;; db is the app-db atom
54+
(reaction (:timer @db)))) ;; wrap the compitation in a reaction
55+
5956

6057
(register-sub
6158
:time-color
6259
(fn
6360
[db _]
64-
;; you need to wrap your subscription code in a reaction
6561
(reaction (:time-color @db))))
6662

67-
(dispatch [:initialize])
6863

64+
;; -- View Components ---------------------------------------------------------
6965

70-
(defn greeting [message]
66+
(defn greeting
67+
[message]
7168
[:h1 message])
7269

73-
(defn clock []
70+
71+
(defn clock
72+
[]
7473
(let [time-color (subscribe [:time-color])
7574
timer (subscribe [:timer])]
76-
;;; wrap your component in a function to use the suscription
77-
(fn []
78-
;; note that the initialize call will not be dispatched immediately
79-
;; as it is an async call
80-
(when @timer
81-
(let [time-str (-> @timer .toTimeString (clojure.string/split " ") first)]
82-
[:div.example-clock
83-
{:style {:color @time-color}}
84-
time-str])))))
85-
86-
(defn color-input []
75+
76+
(fn clock-render
77+
[]
78+
(let [time-str (-> @timer
79+
.toTimeString
80+
(clojure.string/split " ")
81+
first)
82+
style {:style {:color @time-color}}]
83+
[:div.example-clock style time-str]))))
84+
85+
86+
(defn color-input
87+
[]
8788
(let [time-color (subscribe [:time-color])]
88-
;;; wrap your component in a function to use the suscription
89-
(fn []
90-
[:div.color-input
91-
"Time color: "
92-
[:input {:type "text"
93-
:value @time-color
94-
:on-change #(dispatch
95-
[:time-color (-> % .-target .-value)])}]])))
96-
97-
(defn simple-example []
89+
90+
(fn color-input-render
91+
[]
92+
[:div.color-input
93+
"Time color: "
94+
[:input {:type "text"
95+
:value @time-color
96+
:on-change #(dispatch
97+
[:time-color (-> % .-target .-value)])}]])))
98+
99+
(defn simple-example
100+
[]
98101
[:div
99102
[greeting "Hello world, it is now"]
100103
[clock]
101104
[color-input]])
102105

103-
(defn ^:export run []
106+
107+
;; -- Entry Point -------------------------------------------------------------
108+
109+
110+
(defn ^:export run
111+
[]
112+
(dispatch-sync [:initialize])
104113
(reagent/render [simple-example]
105-
(js/document.getElementById "app")))
114+
(js/document.getElementById "app")))

examples/todomvc/project.clj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
(defproject todomvc-re-frame "0.3.0"
1+
(defproject todomvc-re-frame "0.3.1"
22
:dependencies [[org.clojure/clojure "1.6.0"]
33
[org.clojure/clojurescript "0.0-2816"]
44
[reagent "0.5.0"]
5-
[re-frame "0.3.0"]
5+
[re-frame "0.3.1"]
66
[secretary "1.2.1"]]
77

88
:plugins [[lein-cljsbuild "1.0.4"]]

examples/todomvc/src/todomvc/subs.cljs

+19-19
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,44 @@
77

88

99
(defn filter-fn-for
10-
[showing-kw]
11-
(case showing-kw
12-
:active (complement :done)
13-
:done :done
14-
:all identity))
10+
[showing-kw]
11+
(case showing-kw
12+
:active (complement :done)
13+
:done :done
14+
:all identity))
1515

1616

1717
(defn completed-count
18-
"return the count of todos for which :done is true"
19-
[todos]
20-
(count (filter :done (vals todos))))
18+
"return the count of todos for which :done is true"
19+
[todos]
20+
(count (filter :done (vals todos))))
2121

2222

2323
;; -- Subscription handlers and registration ---------------------------------
2424

2525
(register-sub
2626
:todos ;; usage: (subscribe [:todos])
2727
(fn [db _]
28-
(reaction (vals (:todos @db)))))
28+
(reaction (vals (:todos @db)))))
2929

3030
(register-sub
3131
:visible-todos
3232
(fn [db _]
33-
(reaction (let [filter-fn (filter-fn-for (:showing @db))
34-
todos (vals (:todos @db))]
35-
(filter filter-fn todos)))))
33+
(reaction (let [filter-fn (filter-fn-for (:showing @db))
34+
todos (vals (:todos @db))]
35+
(filter filter-fn todos)))))
3636

3737
(register-sub
3838
:completed-count
3939
(fn [db _]
40-
(reaction (completed-count (:todos @db)))))
40+
(reaction (completed-count (:todos @db)))))
4141

4242
(register-sub
4343
:footer-stats
4444
(fn [db _]
45-
(reaction
46-
(let [todos (:todos @db)
47-
completed-count (completed-count todos)
48-
active-count (- (count todos) completed-count)
49-
showing (:showing @db)]
50-
[active-count completed-count showing])))) ;; tuple
45+
(reaction
46+
(let [todos (:todos @db)
47+
completed-count (completed-count todos)
48+
active-count (- (count todos) completed-count)
49+
showing (:showing @db)]
50+
[active-count completed-count showing])))) ;; tuple

project.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject re-frame "0.3.0"
1+
(defproject re-frame "0.3.1"
22
:description "A Clojurescript MVC-like Framework For Writing SPAs Using Regent."
33
:url "https://github.com/Day8/re-frame.git"
44
:license {:name "MIT"}

src/re_frame/core.cljs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
(def enrich middleware/enrich)
2424
(def trim-v middleware/trim-v)
2525
(def after middleware/after)
26-
; (def log-events middleware/log-events)
26+
(def log-ex middleware/log-ex)
2727

2828

2929

3030
;; -- Convenience API -------
3131

3232
;; Almost 100% of handlers will be pure, so make it easy to
33-
;; register with "pure" middleware in the correct position.
33+
;; register with "pure" middleware in the correct (left-hand-side) position.
3434
(defn register-handler
3535
([id handler]
3636
(handlers/register-base id pure handler))

src/re_frame/middleware.cljs

+5-5
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
....)
8383
"
8484
[handler]
85-
(fn new-handler
85+
(fn trim-v-handler
8686
[db v]
8787
(handler db (vec (rest v)))))
8888

@@ -140,16 +140,16 @@
140140
complete reassesment of duplication errors and warnings. Eg: that edit
141141
update might have introduced a new duplicate or removed one. Same with a
142142
todo removal.
143-
And to perform this enrichment, a function has inspect all the todos,
143+
And to perform this enrichment, a function has to inspect all the todos,
144144
possibly set flags on each, and set some overall list of duplicates.
145-
And this duplicates checking might be just one check amoung a number.
145+
And this duplication check might just be one check amoung many.
146146
\"f\" would need to be both adding and removing the duplicate warnings.
147147
By applying \"f\" in middleware, we keep the handlers simple and yet we
148-
ensure this important step is not missed. "
148+
ensure this important step is not missed."
149149
[f]
150150
(fn middleware
151151
[handler]
152-
(fn validate-handler
152+
(fn enrich-handler
153153
[db v]
154154
(f (handler db v) v))))
155155

0 commit comments

Comments
 (0)