File tree 4 files changed +45
-18
lines changed
4 files changed +45
-18
lines changed Original file line number Diff line number Diff line change 1
1
## RenoJS ClojureScript Intro
2
2
This is a short introduction to ClojureScript for the RenoJS programming group.
3
+
4
+ Version 1.3.0 is based on David Nolen's excellent [ ClojureScript 101] ( http://swannodette.github.io/2013/11/07/clojurescript-101/ ) .
Original file line number Diff line number Diff line change 1
- (defproject cljs-intro " 1.2 .0"
1
+ (defproject cljs-intro " 1.3 .0"
2
2
:description " RenoJS ClojureScript Intro"
3
3
:url " http://github.com/seberius/cljs-intro"
4
4
Original file line number Diff line number Diff line change 1
1
(ns cljs-intro.core
2
- (:require [dommy.core :as dom]
3
- [cljs.core.async :refer [<! >! put! chan]])
4
- (:require-macros [dommy.macros :refer [sel1]]
5
- [cljs.core.async.macros :refer [go alt!]]))
2
+ (:require [cljs.core.async :refer [<! >! put! chan]]
3
+ [dommy.core :as dom])
4
+ (:require-macros [cljs.core.async.macros :refer [go alt!]]
5
+ [dommy.macros :refer [sel1 node]])
6
+ (:import [goog.net Jsonp]
7
+ [goog Uri]))
6
8
7
- (def click-chan (chan ))
9
+ (def search-chan (chan ))
10
+ (def result-chan (chan ))
11
+ (def search-url
12
+ " http://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=" )
8
13
9
- (defn square []
14
+ (defn user-query []
15
+ (dom/value (sel1 :#query )))
16
+
17
+ (defn query-url [q]
18
+ (str search-url q))
19
+
20
+ (defn jsonp [uri]
21
+ (Jsonp. (Uri. uri)))
22
+
23
+ (defn render-query [res]
24
+ (node
25
+ [:ul
26
+ (for [result res]
27
+ [:li result])]))
28
+
29
+ (defn query-serv []
30
+ (go (while true
31
+ (<! search-chan)
32
+ (let [uri (query-url (user-query ))
33
+ req (jsonp uri)]
34
+ (.send req nil (fn [res] (put! result-chan res)))))))
35
+
36
+ (defn render-serv []
10
37
(go (while true
11
- (<! click-chan)
12
- (let [base (dom/value (sel1 :#num-base ))
13
- expo (dom/value (sel1 :#num-expo ))]
14
- (dom/set-value! (sel1 :#num-base ) (.pow js/Math base expo))))))
38
+ (let [[_ res] (<! result-chan)]
39
+ (dom/replace-contents! (sel1 :#results ) (render-query res))))))
15
40
16
41
(defn ^:export init []
17
- (square )
18
- (dom/listen! (sel1 :#submit ) " click" (fn [e] (put! click-chan e))))
42
+ (query-serv )
43
+ (render-serv )
44
+ (dom/listen! (sel1 :#submit ) " click" (fn [e] (put! search-chan e))))
19
45
20
46
(set! (.-onload js/window) init)
Original file line number Diff line number Diff line change 1
1
< html >
2
2
< body >
3
- < script src ="/{{build}}/js/cljs_intro.js " type ="text/javascript "> </ script >
4
- < div id ="main " >
5
- Base: < input id ="num-base " value =1 >
6
- Exponent: < input id ="num-expo " value =1 >
7
- < button id ="submit " > Submit</ button >
3
+ < script src ="/{{build}}/js/cljs_intro.js " type ="text/javascript " > </ script >
4
+ < div id ="search " >
5
+ Search: < input id ="query " > < button id ="submit " > Submit</ button >
8
6
</ div >
7
+ < div id ="results " > </ div >
9
8
10
9
</ body >
11
10
</ html >
You can’t perform that action at this time.
0 commit comments