Skip to content

Commit 7c218e6

Browse files
committed
Reformat code
1 parent 9702dc4 commit 7c218e6

File tree

11 files changed

+462
-411
lines changed

11 files changed

+462
-411
lines changed

project.clj

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@
2121
[honeysql "0.6.1"]]
2222
:plugins [[lein-cljsbuild "1.1.0"]]
2323
:main sample.core
24-
:cljsbuild {:builds [{:id "dev"
24+
:cljsbuild {:builds [{:id "dev"
2525
:source-paths ["src-cljs"]
26-
:compiler {:output-to "resources/public/js/main.js"
27-
:optimizations :whitespace
28-
:foreign-libs
29-
[{:file "https://cdn.anychart.com/releases/v8/js/anychart-bundle.min.js"
30-
:provides ["anychart"]}]
31-
:pretty-print true}}
32-
{:id "prod"
26+
:compiler {:output-to "resources/public/js/main.js"
27+
:optimizations :whitespace
28+
:foreign-libs
29+
[{:file "https://cdn.anychart.com/releases/v8/js/anychart-bundle.min.js"
30+
:provides ["anychart"]}]
31+
:pretty-print true}}
32+
{:id "prod"
3333
:source-paths ["src-cljs"]
34-
:compiler {:output-to "resources/public/js/main.min.js"
35-
:optimizations :advanced
36-
:externs ["src-cljs/externs.js"]
37-
:foreign-libs
38-
[{:file "https://cdn.anychart.com/releases/v8/js/anychart-bundle.min.js"
39-
:provides ["anychart"]}]
40-
:pretty-print false}}]})
34+
:compiler {:output-to "resources/public/js/main.min.js"
35+
:optimizations :advanced
36+
:externs ["src-cljs/externs.js"]
37+
:foreign-libs
38+
[{:file "https://cdn.anychart.com/releases/v8/js/anychart-bundle.min.js"
39+
:provides ["anychart"]}]
40+
:pretty-print false}}]})

resources/public/js/main.min.js

Lines changed: 327 additions & 328 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-cljs/sample/charts.cljs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
(ns sample.charts
22
(:require [anychart]))
33

4+
45
(def ^:private revenue-by-industry (anychart.data.set))
56
(def ^:private revenue-by-sales (anychart.data.set))
67
(def ^:private revenue-by-product (anychart.data.set))
78
(def ^:private revenue-by-quarter (atom nil))
89

10+
911
(defn create
1012
"Setup all charts"
1113
[]
1214
(js/anychart.theme (clj->js {:defaultTooltip {:title {:enabled false}}}))
13-
15+
1416
(doto (anychart.bar revenue-by-industry)
1517
(.container "rev-by-industry")
1618
(.title "Revenue by industry")
@@ -32,6 +34,7 @@
3234
(.title "Revenue by quarter")
3335
(.draw)))
3436

37+
3538
(defn update-charts
3639
"Replace charts data"
3740
[data]

src-cljs/sample/core.cljs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
[reagent.core :as r]
66
[cljs.core.async :as async :refer [chan]])
77
(:require-macros
8-
[cljs.core.async.macros :refer [go]]))
8+
[cljs.core.async.macros :refer [go]]))
9+
910

1011
(def state (r/atom {}))
1112

13+
1214
(defn ^:export init []
13-
15+
1416
(go
1517
(let [res (<! (data/GET "/init"))]
1618
(reset! state res)
@@ -20,6 +22,6 @@
2022
(ui/create state update)
2123
(go (while true
2224
(charts/update-charts
23-
(<! (data/GET (str "/data?" (data/query-string @(<! update)))))))))
24-
25+
(<! (data/GET (str "/data?" (data/query-string @(<! update)))))))))
26+
2527
(charts/create))

src-cljs/sample/data.cljs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,35 @@
55
[goog.structs :as gstruct]
66
[clojure.string])
77
(:require-macros
8-
[cljs.core.async.macros :refer [go]]))
8+
[cljs.core.async.macros :refer [go]]))
9+
910

1011
(defn is-selected [item]
1112
(or (not (contains? item :selected))
1213
(:selected item)))
1314

15+
1416
(defn- to-query-param [items]
1517
(str "("
1618
(clojure.string/join ","
1719
(map :id
1820
(filter is-selected items)))
1921
")"))
2022

23+
2124
(defn query-string [state]
22-
(-> {:years (to-query-param (:years state))
23-
:quarters (to-query-param (:quarters state))
24-
:products (to-query-param (:products state))
25-
:regions (to-query-param (:regions state))
25+
(-> {:years (to-query-param (:years state))
26+
:quarters (to-query-param (:quarters state))
27+
:products (to-query-param (:products state))
28+
:regions (to-query-param (:regions state))
2629
:industries (to-query-param (:industries state))
2730
:sales-reps (to-query-param (:sales-reps state))}
2831
clj->js
2932
gstruct/Map.
3033
gquery-data/createFromMap
3134
.toString))
3235

36+
3337
(defn GET [url]
3438
(let [ch (chan 1)]
3539
(xhr/send url

src-cljs/sample/ui.cljs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,66 @@
33
[sample.data :as data]
44
[cljs.core.async :refer [put!]]))
55

6+
67
(defn- toggle-item [items item]
78
(map #(if (= % item)
89
(assoc % :selected (not (data/is-selected %)))
910
%)
1011
items))
1112

13+
1214
(defn- group-selector
1315
([label state key is-disabled update-chan]
1416
[:div.form-group
1517
[:label.col-sm-1.control-label label]
1618
[:div
1719
(doall (for [item (get @state key)]
18-
^{:key (:id item)} [:label.checkbox-inline
19-
[:input {:type :checkbox
20-
:checked (and (data/is-selected item)
21-
(not (is-disabled state item)))
22-
:disabled (is-disabled state item)
23-
:value (:id item)
24-
:on-change (fn []
25-
(swap! state assoc key
26-
(toggle-item (get @state key) item))
27-
(put! update-chan state))}
28-
(:name item)]]))]])
20+
^{:key (:id item)} [:label.checkbox-inline
21+
[:input {:type :checkbox
22+
:checked (and (data/is-selected item)
23+
(not (is-disabled state item)))
24+
:disabled (is-disabled state item)
25+
:value (:id item)
26+
:on-change (fn []
27+
(swap! state assoc key
28+
(toggle-item (get @state key) item))
29+
(put! update-chan state))}
30+
(:name item)]]))]])
2931
([label state key update-chan]
3032
(group-selector label state key (fn [_] false) update-chan)))
3133

34+
3235
(defn- years-selector [state update-chan]
3336
[group-selector "Years" state :years update-chan])
3437

38+
3539
(defn- quarters-selector [state update-chan]
3640
[group-selector "Quarters" state :quarters update-chan])
3741

42+
3843
(defn- industries-selector [state update-chan]
3944
[group-selector "Industries" state :industries update-chan])
4045

46+
4147
(defn- product-selector [state update-chan]
4248
[group-selector "Products" state :products
4349
(fn [state item]
4450
(let [industry-id (:industry_id item)]
4551
(-> (filter #(= industry-id (:id %)) (get @state :industries))
46-
first
47-
data/is-selected
48-
not)))
52+
first
53+
data/is-selected
54+
not)))
4955
update-chan])
5056

57+
5158
(defn- regions-selector [state update-chan]
5259
[group-selector "Regions" state :regions update-chan])
5360

61+
5462
(defn- sales-reps-selector [state update-chan]
5563
[group-selector "Sales Reps" state :sales-reps update-chan])
5664

65+
5766
(defn create [state update-chan]
5867
(r/render-component [years-selector state update-chan]
5968
(js/document.getElementById "years-selector"))

src/sample/components/jdbc.clj

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[honeysql.format :as fmt])
66
(:import com.mchange.v2.c3p0.ComboPooledDataSource))
77

8+
89
(defn- connection-pool
910
"Create a connection pool for the given database spec."
1011
[{:keys [subprotocol subname classname user password
@@ -14,14 +15,14 @@
1415
test-connection-on-checkin
1516
test-connection-on-checkout
1617
stringtype]
17-
:or {excess-timeout (* 30 60)
18-
idle-timeout (* 3 60 60)
19-
minimum-pool-size 3
20-
maximum-pool-size 15
21-
test-connection-query nil
22-
idle-connection-test-period 0
23-
test-connection-on-checkin false
24-
test-connection-on-checkout false}}]
18+
:or {excess-timeout (* 30 60)
19+
idle-timeout (* 3 60 60)
20+
minimum-pool-size 3
21+
maximum-pool-size 15
22+
test-connection-query nil
23+
idle-connection-test-period 0
24+
test-connection-on-checkin false
25+
test-connection-on-checkout false}}]
2526
{:datasource (doto (ComboPooledDataSource.)
2627
(.setDriverClass classname)
2728
(.setJdbcUrl (str "jdbc:" subprotocol ":" subname "?stringtype=unspecified"))
@@ -36,6 +37,7 @@
3637
(.setTestConnectionOnCheckout test-connection-on-checkout)
3738
(.setPreferredTestQuery test-connection-query))})
3839

40+
3941
(defrecord JDBC [config conn]
4042
component/Lifecycle
4143
(start [this]
@@ -48,24 +50,29 @@
4850
(do (-> conn :datasource (.close))
4951
this))))
5052

53+
5154
(defn new-jdbc [config]
5255
(map->JDBC {:config config}))
5356

57+
5458
(defn sql
5559
"Convert honeysql to JDBC query"
5660
[q]
5761
(sql/format q :quoting :ansi))
5862

63+
5964
(defn query
6065
"Run query and return result rows"
6166
[jdbc q]
6267
(clj-jdbc/query (:conn jdbc) (sql q)))
6368

69+
6470
(defn one
6571
"Run query and return first row"
6672
[jdbc q]
6773
(first (query jdbc q)))
6874

75+
6976
(defn exec
7077
"Run insert/update query"
7178
[jdbc q]

src/sample/components/web.clj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
[taoensso.timbre :as timbre :refer [info]]
66
[sample.web.routes :as routes :refer [app]]))
77

8+
89
(defn- component-middleware
910
"Middleware for adding component to request"
1011
[component app]
1112
(fn [request]
1213
(app (assoc request :component component))))
1314

15+
1416
(defn- create-web-app [component]
1517
(component-middleware component #'app))
1618

19+
1720
(defrecord Web [config web-server jdbc redis api]
1821
component/Lifecycle
1922

@@ -25,5 +28,6 @@
2528
(web-server :timeout 100))
2629
(assoc this :web-server nil)))
2730

31+
2832
(defn new-web [config]
2933
(map->Web {:config config}))

src/sample/core.clj

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,41 @@
44
[com.stuartsierra.component :as component])
55
(:gen-class :main :true))
66

7-
(def base-config {:web {:port 9197 :debug true}
7+
8+
(def base-config {:web {:port 9197 :debug true}
89
:jdbc {:subprotocol "postgresql"
9-
:subname "//localhost:5432/anychart_sample"
10-
:classname "org.postgresql.Driver"
11-
:user "anychart_user"
12-
:password "anychart_pass"}})
10+
:subname "//localhost:5432/anychart_sample"
11+
:classname "org.postgresql.Driver"
12+
:user "anychart_user"
13+
:password "anychart_pass"}})
14+
1315

1416
(def prod-config (assoc-in base-config [:web :debug] false))
1517

18+
1619
(defn app-system
1720
"App system with jdbc and http-kit web server"
1821
[config]
1922
(component/system-map
20-
:jdbc (jdbc/new-jdbc (:jdbc config))
21-
:web (component/using (web/new-web (:web config)) [:jdbc])))
23+
:jdbc (jdbc/new-jdbc (:jdbc config))
24+
:web (component/using (web/new-web (:web config)) [:jdbc])))
25+
2226

2327
(def dev (app-system base-config))
2428

29+
2530
(defn start
2631
"Start dev system"
2732
[]
2833
(alter-var-root #'dev component/start))
2934

35+
3036
(defn stop
3137
"Stop dev system"
3238
[]
3339
(alter-var-root #'dev component/stop))
3440

41+
3542
(defn -main
3643
"Start prod system"
3744
[]

0 commit comments

Comments
 (0)