File tree 7 files changed +27
-31
lines changed
7 files changed +27
-31
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 40
40
< li > < a href ="http://matthiasnehlsen.com/blog/2014/07/17/BirdWatch-in-ClojureScript/ " target ="_blank "> Blog</ a > </ li >
41
41
< li > < a href ="https://github.com/matthiasn/BirdWatch " target ="_blank "> Project on GitHub</ a > </ li >
42
42
< li > < a href ="# " onclick ="BirdWatch.legalStuff() "> Legal stuff</ a > </ li >
43
+ < li > < a href ="# "> Connected: < strong id ="users-count "> </ strong > users</ a > </ li >
43
44
</ ul >
44
45
</ li >
45
46
</ ul >
Original file line number Diff line number Diff line change 99
99
(when (contains? matches (get @a/subscriptions uid))
100
100
(chsk-send! uid [:tweet/new t]))))))
101
101
102
+ ; ; loop sending stats about server to all connected clients
103
+ (go
104
+ (while true
105
+ (<! (timeout 2000 ))
106
+ (let [uids (:any @connected-uids)]
107
+ (doseq [uid uids]
108
+ (chsk-send! uid [:stats/users-count (count uids)])))))
109
+
102
110
(defn -main
103
111
[& args]
104
112
(tc/start-twitter-conn! )
Original file line number Diff line number Diff line change 25
25
; ;; Om components for the application are initialized here. Their implementation lives in the ui namespace.
26
26
(om/root ui/tweets-view state/app {:target (. js/document (getElementById " tweet-frame" ))})
27
27
(om/root ui/count-view state/app {:target (. js/document (getElementById " tweet-count" ))})
28
+ (om/root ui/users-count-view state/app {:target (. js/document (getElementById " users-count" ))})
28
29
(om/root ui/search-view state/app {:target (. js/document (getElementById " search" ))})
29
30
(om/root ui/sort-buttons-view state/app {:target (. js/document (getElementById " sort-buttons" ))})
30
31
(om/root ui/pagination-view state/app {:target (. js/document (getElementById " pagination" ))})
Original file line number Diff line number Diff line change 109
109
(defn- event-handler [[id data :as ev] _]
110
110
(match [id data]
111
111
112
- [:some/tweetchunk chunk]
113
- (put! prev-chunks-chan chunk)
114
-
115
112
[:chsk/state {:first-open? true }]
116
113
(do
117
114
(print " Channel socket successfully established!" )
130
127
[:tweet/prev-chunk chunk]
131
128
(do
132
129
(put! prev-chunks-chan chunk)
133
- (load-prev ))))
130
+ (load-prev ))
131
+
132
+ [:stats/users-count uc]
133
+ (swap! state/app assoc :users-count uc) ))
134
134
135
135
:else (print " Unmatched event: %s" ev)))
136
136
Original file line number Diff line number Diff line change 16
16
om/IRender
17
17
(render [this] (dom/span nil (:count app)))))
18
18
19
+ (defn users-count-view [app owner]
20
+ " rendering users counter"
21
+ (reify
22
+ om/IRender
23
+ (render [this] (dom/span nil (:users-count app)))))
24
+
19
25
(def find-tweets {:by-id (util/tweets-by-order :tweets-map :by-id )
20
26
:by-followers (util/tweets-by-order :tweets-map :by-followers )
21
27
:by-retweets (util/tweets-by-order :retweets :by-retweets )
Original file line number Diff line number Diff line change 71
71
72
72
(defn initial-state []
73
73
" function returning fresh application state"
74
- {:count 0 :n 10 :retweets {}
75
- :tweets-map {} :search-text " " :page 1
74
+ {:count 0
75
+ :n 10
76
+ :retweets {}
77
+ :tweets-map {}
78
+ :search-text " "
79
+ :page 1
76
80
:search " *"
81
+ :users-count 0
77
82
:sorted :by-rt-since-startup
78
83
:by-followers (priority-map-by >)
79
84
:by-retweets (priority-map-by >)
You can’t perform that action at this time.
0 commit comments