Skip to content

Instantly share code, notes, and snippets.

@gabrielnau
Created March 20, 2018 17:55
Show Gist options
  • Save gabrielnau/6817c938754a182a796366c572f7607d to your computer and use it in GitHub Desktop.
Save gabrielnau/6817c938754a182a796366c572f7607d to your computer and use it in GitHub Desktop.
(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