-
Notifications
You must be signed in to change notification settings - Fork 153
/
core.cljs
49 lines (40 loc) · 1.78 KB
/
core.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(ns birdwatch.core
"This is the main namespace of the client side of BirdWatch. It is written in
ClojureScript and makes use of the systems-toolbox library
(https://github.com/matthiasn/systems-toolbox) for building and wiring
components. Below, a switchboard is created, which is a specialized component
for wiring components together so that messages flow through a system."
(:require [matthiasn.birdwatch-specs.specs]
[birdwatch.charts.cloud-chart :as cloud]
[birdwatch.ui.ui :as ui]
[birdwatch.state.comp :as state]
[matthiasn.systems-toolbox.switchboard :as sb]
[matthiasn.systems-toolbox-sente.client :as sente]
[cljsjs.moment]))
(enable-console-print!)
(defonce switchboard (sb/component :client/switchboard))
(defn make-observable [components]
(let [mapper #(assoc-in % [:opts :msgs-on-firehose] true)]
(set (mapv mapper components))))
(defn init []
(let [ws-cfg {:relay-types #{:cmd/query :cmd/percolate}}
sente-firehose-cfg {:opts {:in-chan [:buffer 100]}}
cmps #{(sente/cmp-map :client/ws-cmp ws-cfg)
(state/cmp-map :client/state-cmp)
(sente/cmp-map :client/ws-firehose sente-firehose-cfg)
(ui/cmp-map :client/ui-cmp)}
cmps (make-observable cmps)]
(sb/send-mult-cmd
switchboard
[[:cmd/init-comp cmps]
[:cmd/route {:from #{:client/state-cmp
:client/ui-cmp}
:to :client/ws-cmp}]
[:cmd/route {:from #{:client/ws-cmp
:client/ui-cmp}
:to :client/state-cmp}]
[:cmd/observe-state
{:from :client/state-cmp
:to #{:client/ui-cmp}}]
[:cmd/attach-to-firehose :client/ws-firehose]])))
(init)