Created
March 20, 2018 17:55
-
-
Save gabrielnau/6817c938754a182a796366c572f7607d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(re-frame/reg-fx | |
::send-several-ws | |
(fn [[websocket payloads]] | |
(doseq [p payloads] | |
(.send websocket (js/JSON.stringify (clj->js p)))))) | |
(re-frame/reg-event-fx | |
::subscribe | |
(fn [{:keys [db]} [_ subscription-id query variables callback-event initial-payload :as event]] | |
;; ... | |
(cond | |
;; ... | |
(get-in db [:re-graph :websocket :ready?]) | |
{:db (assoc-in db [:re-graph :subscriptions (name subscription-id)] {:callback callback-event | |
:event event | |
:active? true}) | |
::send-several-ws [(get-in db [:re-graph :websocket :connection]) | |
[{:id (name subscription-id) | |
:type "connection_init" | |
:payload initial-payload} | |
{:id (name subscription-id) | |
:type "start" | |
:payload {:query (str "subscription " (string/replace query #"^subscription\s?" "")) | |
:variables variables}}]]}))) | |
;; ...))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment