Skip to content

Commit d60fa61

Browse files
authored
Merge pull request #1 from ClojureBA/tutorial
Tutorial
2 parents d7529a8 + c9c6caf commit d60fa61

File tree

4 files changed

+44
-32
lines changed

4 files changed

+44
-32
lines changed

demo/reagentdemo/common.cljs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,32 @@
22
(:require [reagent.core :as r]
33
[reagent.debug :refer-macros [dbg println]]))
44

5-
(defn demo-component [{:keys [comp src complete no-heading]}]
6-
(r/with-let [showing (r/atom true)]
5+
(defn demo-component [{:keys [expected comp src complete no-heading]}]
6+
(r/with-let [showing (r/atom false)]
77
[:div
8-
(when comp
8+
(when expected
99
[:div.demo-example.clearfix
10+
(when-not no-heading
11+
[:h3.demo-heading "Expected output "])
12+
(if-not complete
13+
[:div.simple-demo [expected]]
14+
[expected])
15+
(when comp
16+
[:div
17+
(when-not no-heading
18+
[:h3.demo-heading "Actual output "])
19+
(if-not complete
20+
[:div.simple-demo [comp]]
21+
[comp])])])
22+
23+
(if src
24+
[:div.demo-source.clearfix
1025
[:a.demo-example-hide {:on-click (fn [e]
1126
(.preventDefault e)
1227
(swap! showing not)
1328
nil)}
1429
(if @showing "hide" "show")]
1530
(when-not no-heading
16-
[:h3.demo-heading "Example "])
17-
(when @showing
18-
(if-not complete
19-
[:div.simple-demo [comp]]
20-
[comp]))])
21-
(if @showing
22-
(if src
23-
[:div.demo-source.clearfix
24-
(when-not no-heading
25-
[:h3.demo-heading "Source"])
26-
src]
27-
[:div.clearfix]))]))
31+
[:h3.demo-heading "Solution"])
32+
(when @showing src)]
33+
[:div.clearfix])]))

demo/reagentdemo/dev.cljs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
(ns reagentdemo.dev
22
"Initializes the demo app, and runs the tests."
3-
(:require [reagentdemo.core :as core]
4-
[reagenttest.runtests :as tests]))
3+
(:require [reagentdemo.core :as core]))
54

65
(defn init! []
7-
(core/init! (tests/init!)))
6+
(core/init!))
87

98
(init!)

demo/reagentdemo/intro.cljs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[reagentdemo.syntax :as s]
66
[sitetools.core :refer [link]]
77
[reagentdemo.common :as common :refer [demo-component]]
8+
[reagentdemo.solutions :as solutions]
89
[simpleexample.core :as simple]
910
[todomvc.core :as todo]))
1011

@@ -110,18 +111,18 @@
110111

111112

112113
(defn intro []
113-
(let [github {:href "https://github.com/reagent-project/reagent"}
114-
clojurescript {:href "https://github.com/clojure/clojurescript"}
115-
react {:href "http://facebook.github.io/react/"}
116-
hiccup {:href "https://github.com/weavejester/hiccup"}
114+
(let [github {:href "https://github.com/reagent-project/reagent"}
115+
clojurescript {:href "https://github.com/clojure/clojurescript"}
116+
react {:href "http://facebook.github.io/react/"}
117+
hiccup {:href "https://github.com/weavejester/hiccup"}
117118
dynamic-children {:href "http://facebook.github.io/react/docs/multiple-components.html#dynamic-children"}]
118119
[:div.demo-text
119120

120121
[:h2 "Introduction to Reagent"]
121122

122123
[:p [:a github "Reagent"] " provides a minimalistic interface
123-
between " [:a clojurescript "ClojureScript"] " and " [:a
124-
react "React"] ". It allows you to define efficient React
124+
between " [:a clojurescript "ClojureScript"] " and "
125+
[:a react "React"] ". It allows you to define efficient React
125126
components using nothing but plain ClojureScript functions and
126127
data, that describe your UI using a " [:a hiccup "Hiccup"] "-like
127128
syntax."]
@@ -132,19 +133,20 @@
132133
about performance."]
133134

134135
[:p "A very basic Reagent component may look something like this: "]
135-
[demo-component {:comp simple-component
136-
:src (s/src-of [:simple-component])}]
136+
[demo-component {:expected simple-component
137+
:comp solutions/simple-component
138+
:src (s/src-of [:simple-component])}]
137139

138140
[:p "You can build new components using other components as
139141
building blocks. Like this:"]
140142
[demo-component {:comp simple-parent
141-
:src (s/src-of [:simple-parent])}]
143+
:src (s/src-of [:simple-parent])}]
142144

143145
[:p "Data is passed to child components using plain old Clojure
144146
data types. Like this:"]
145147

146148
[demo-component {:comp say-hello
147-
:src (s/src-of [:hello-component :say-hello])}]
149+
:src (s/src-of [:hello-component :say-hello])}]
148150

149151
[:p [:strong "Note: "]
150152
"In the example above, " [:code "hello-component"] " might just
@@ -156,18 +158,18 @@
156158
be called with square brackets."]
157159

158160
[:p "Here is another example that shows items in a "
159-
[:code "seq"] ":" ]
161+
[:code "seq"] ":" ]
160162

161163
[demo-component {:comp lister-user
162-
:src (s/src-of [:lister :lister-user])}]
164+
:src (s/src-of [:lister :lister-user])}]
163165

164166
[:p [:strong "Note: "]
165-
"The " [:code "^{:key item}"] " part above isn’t really necessary
167+
"The " [:code "^{:key item}"] " part above isn’t really necessary
166168
in this simple example, but attaching a unique key to every item
167169
in a dynamically generated list of components is good practice,
168170
and helps React to improve performance for large lists. The key
169171
can be given either (as in this example) as meta-data, or as a "
170-
[:code ":key"] " item in the first argument to a component (if it
172+
[:code ":key"] " item in the first argument to a component (if it
171173
is a map). See React’s " [:a dynamic-children "documentation"] "
172174
for more info."]]))
173175

demo/reagentdemo/solutions.cljs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(ns reagentdemo.solutions
2+
"Solutions for the tutorial examples. Your code goes here.")
3+
4+
(defn simple-component []
5+
[:div "Hello!"])

0 commit comments

Comments
 (0)