Skip to content

Commit

Permalink
#26 Subscribe to specific signals
Browse files Browse the repository at this point in the history
  • Loading branch information
eidekrist committed Jan 4, 2019
1 parent cbf2e8f commit 08c549d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/cse_client/controller.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[kee-frame.websocket :as websocket]
[cse-client.config :refer [socket-url]]
[re-frame.loggers :as re-frame-log]
[cljs.spec.alpha :as s]))
[cljs.spec.alpha :as s]
[clojure.string :as str]))

;; Prevent handler overwriting warnings during cljs reload.
(re-frame-log/set-loggers!
Expand Down Expand Up @@ -51,18 +52,33 @@
(fn [_ _]
(socket-command ["get-module-data"])))

(defn encode-variable [{:keys [name causality type value-reference]}]
(str/join "," [name causality type value-reference]))

(defn make-signals [db module causality]
(->> db
:state
:module-data
:fmus
(filter #(= module (:name %)))
first
:variables
(filter #(= causality (:causality %)))
(map encode-variable)))

(k/reg-event-fx ::module-enter
(fn [{:keys [db]} [{:keys [module causality]}]]
(merge
{:db (assoc db :current-module module
:active-causality causality)}
(socket-command ["module" module]))))
;{:dispatch [::websocket/send socket-url {:signals (make-signals db module causality)}]}
(socket-command (concat ["signals" module] (make-signals db module causality))))))

(k/reg-event-fx ::module-leave
(fn [{:keys [db]} _]
(merge
{:db (dissoc db :current-module)}
(socket-command ["module" nil]))))
(socket-command ["signals"]))))

(k/reg-event-fx ::load
(fn [_ [folder log-folder]]
Expand Down

0 comments on commit 08c549d

Please sign in to comment.