From 08c549d6757788e3e7e9ea4e85f75f8595db51b8 Mon Sep 17 00:00:00 2001 From: eidekrist Date: Fri, 4 Jan 2019 17:10:12 +0100 Subject: [PATCH] #26 Subscribe to specific signals --- src/cse_client/controller.cljs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/cse_client/controller.cljs b/src/cse_client/controller.cljs index 20fa153..9a756bc 100644 --- a/src/cse_client/controller.cljs +++ b/src/cse_client/controller.cljs @@ -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! @@ -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]]