Last active
May 16, 2017 02:40
-
-
Save cmcfarlen/c68b5050a14e8e910ff1001f5fc1eeb2 to your computer and use it in GitHub Desktop.
Wrap default merge migrate to default to compassus route queries
This file contains 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
(defn my-merge | |
[routes] | |
(fn | |
[reconciler state res query] | |
(om/default-merge reconciler state res (or query | |
(om/get-query (get routes (:compassus.core/route state))))))) | |
;; also pass the wrapper component for the compassus app | |
(defn my-migrate | |
[routes wrapper] | |
(fn [app-state-pure query tempids id-key] | |
(let [query (if (= :compassus.core/route (first query)) ; assume a full query here means om substituted the root query for a nil query | |
(om/get-query (get routes (:compassus.core/route app-state-pure))) | |
query) | |
;; If tempids is not empty, om/default-migrate does a (om/tree->db (om/db->tree)) to update all of the tempid refs. | |
;; This will remove any state not in the query. Combine the wrapper query with the route query to prevent this undesireable feature | |
query (if (and wrapper (not (empty? tempids))) | |
(apply vector (concat (om/get-query wrapper) query)) | |
query)] | |
(om/default-migrate app-state-pure query tempids id-key)))) | |
;; This is given to the reconciler as (partial sender websocket-options) | |
(defn sender | |
[send-options {:keys [remote] :as q} cb] | |
(when remote | |
(let [{:keys [query rewrite]} (om/process-roots remote) | |
cb' (fn [result] | |
(if (some #(symbol? (first %)) result) | |
(cb result nil) ;; we default to the current route's query in merge/migrate | |
(cb (rewrite result) remote)))] | |
(websocket/send [:parser/remote query] | |
#(if (= % :chsk/timeout) | |
(cb {'app/timeout {:fail-message "Timeout waiting for response"}} [:fail-message]) | |
(cb' %)) | |
send-options)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We set compassus/parser :route-dispatch to false