Skip to content

Commit

Permalink
Trace the reagent-id of the reactive signals, not their dereffed values
Browse files Browse the repository at this point in the history
This code used to get the reagent-id for every derefed value of the
input-signals, which returned all nils. This change traces the reactive
versions of the input signals.

Fixes day8/re-frame-10x#83
  • Loading branch information
danielcompton committed Jan 16, 2018
1 parent 23f7c84 commit 64f858c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/re_frame/interop.clj
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@
(defn reagent-id
"Doesn't make sense in a Clojure context currently."
[reactive-val]
nil)
"rx-clj")
28 changes: 21 additions & 7 deletions src/re_frame/subs.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,30 @@
(map (fn [[k v]] [k (f v)]))
m))

(defn map-signals
"Runs f over signals. Signals may take several
forms, this function handles all of them."
[f signals]
(cond
(sequential? signals) (map f signals)
(map? signals) (map-vals f signals)
(deref? signals) (f signals)
:else nil))

(defn to-seq
"Coerces x to a seq if it isn't one already"
[x]
(if (sequential? x)
x
(list x)))

(defn- deref-input-signals
[signals query-id]
(let [signals (cond
(sequential? signals) (map deref signals)
(map? signals) (map-vals deref signals)
(deref? signals) @signals
:else (console :error "re-frame: in the reg-sub for " query-id ", the input-signals function returns: " signals))]
(trace/merge-trace! {:tags {:input-signals (map reagent-id signals)}})
signals))
(let [dereffed-signals (map-signals deref signals)]
(when (nil? dereffed-signals)
(console :error "re-frame: in the reg-sub for " query-id ", the input-signals function returns: " signals))
(trace/merge-trace! {:tags {:input-signals (doall (to-seq (map-signals reagent-id signals)))}})
dereffed-signals))


(defn reg-sub
Expand Down

0 comments on commit 64f858c

Please sign in to comment.