|
@@ -16,29 +16,69 @@
|
|
(.info js/console "App stopped.")
|
|
(.info js/console "App stopped.")
|
|
component))
|
|
component))
|
|
|
|
|
|
-(defrecord Sente [client-id
|
|
|
|
|
|
+(defprotocol Logger
|
|
|
|
+ (info [c msg args])
|
|
|
|
+ (error [c msg args])
|
|
|
|
+ (debug [c msg args]))
|
|
|
|
+
|
|
|
|
+(defn- send-log! [c event msg args]
|
|
|
|
+ (let [send-fn! (get-in c [:sente-chsk :send-fn])]
|
|
|
|
+ (.info js/console (str event ": " msg))
|
|
|
|
+ (send-fn! [event {:log/msg msg
|
|
|
|
+ :log/args args}])))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+(defrecord PubSub []
|
|
|
|
+ component/Lifecycle
|
|
|
|
+ (start [c]
|
|
|
|
+ (comment let [local-pub (chan)
|
|
|
|
+ local-pubsub {:pub local-pub
|
|
|
|
+ :subs (subs pub)}
|
|
|
|
+ dispatch (comment fn [event]
|
|
|
|
+ (when (remote-dispatch? event))
|
|
|
|
+ )])
|
|
|
|
+ c)
|
|
|
|
+ (stop [c] c))
|
|
|
|
+
|
|
|
|
+(defrecord Sente [env
|
|
sente-chsk]
|
|
sente-chsk]
|
|
component/Lifecycle
|
|
component/Lifecycle
|
|
(start [c]
|
|
(start [c]
|
|
(let [sente-chsk (sente/make-channel-socket! "/chsk" {:type :auto
|
|
(let [sente-chsk (sente/make-channel-socket! "/chsk" {:type :auto
|
|
- :client-id client-id})]
|
|
|
|
|
|
+ :client-id (:client-id env)})
|
|
|
|
+ c (assoc c :sente-chsk sente-chsk)]
|
|
(go (while true
|
|
(go (while true
|
|
(let [event (<! (:ch-recv sente-chsk))]
|
|
(let [event (<! (:ch-recv sente-chsk))]
|
|
(.info js/console (str "Got event! " event)))))
|
|
(.info js/console (str "Got event! " event)))))
|
|
- (.info js/console "Sente started.")
|
|
|
|
|
|
+ (.info js/console "Sente started. client-id=" (:client-id env))
|
|
|
|
|
|
(.setTimeout js/window #((:send-fn sente-chsk) [:client/hi]) 500)
|
|
(.setTimeout js/window #((:send-fn sente-chsk) [:client/hi]) 500)
|
|
|
|
+ (.setTimeout js/window #(info c "HI!!!!!" ["From a timer"]) 500)
|
|
|
|
|
|
- (assoc c :sente-chsk sente-chsk)))
|
|
|
|
|
|
+ c))
|
|
(stop [c]
|
|
(stop [c]
|
|
(when (:sente-chsk c)
|
|
(when (:sente-chsk c)
|
|
(.info js/console "Sente stopped.")
|
|
(.info js/console "Sente stopped.")
|
|
- (dissoc c :sente-chsk))))
|
|
|
|
|
|
+ (dissoc c :sente-chsk)))
|
|
|
|
+
|
|
|
|
+ Logger
|
|
|
|
+ (info [c msg args] (send-log! c ::log.info msg args))
|
|
|
|
+ (error [c msg args] (send-log! c ::log.error msg args))
|
|
|
|
+ (debug [c msg args] (send-log! c ::log.debug msg args)))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+(defrecord Env [client-id])
|
|
|
|
|
|
-(defonce system (atom (component/system-map :sente (map->Sente {:client-id "1234"})
|
|
|
|
|
|
+(defonce system (atom (component/system-map :env (map->Env {:client-id "1234"})
|
|
|
|
+ :sente (component/using
|
|
|
|
+ (map->Sente {})
|
|
|
|
+ [:env])
|
|
|
|
+ :pubsub (map->PubSub {})
|
|
:app (component/using
|
|
:app (component/using
|
|
(map->App {})
|
|
(map->App {})
|
|
- {:sente :sente}))))
|
|
|
|
|
|
+ {:env :env
|
|
|
|
+ :sente :sente
|
|
|
|
+ :pubsub :pubsub}))))
|
|
|
|
|
|
(defn send-message [msg]
|
|
(defn send-message [msg]
|
|
(let [sente-chsk (get-in @system [:sente :sente-chsk])]
|
|
(let [sente-chsk (get-in @system [:sente :sente-chsk])]
|