re-frame
re-frame copied to clipboard
duplicate work in deref-input-signals
In https://github.com/Day8/re-frame/blob/master/src/re_frame/subs.cljc#L188, the work of traversing & dereferencing is being done twice. It looks like the purpose of the inner cond form is to print a warning if an unexpected argument is passed in. Maybe we could move this check into the :else clause of map-signals, and allow for elision in prod? along the lines of:
(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 (do (when debug-enabled?
(console :error "re-frame: in the reg-sub for" query-id ", the input-signals function returns:" signals))
'())))
Thanks for catching this, it does look like a bug.
In https://github.com/Day8/re-frame/commit/64f858c4e33f68b1da5d6f9532defd8a73345b0b I extracted part of deref-input-signals into map-signals so that I could reuse the same mapping logic when tracing the signals.
There was a bug in that code though, and I fixed it in https://github.com/Day8/re-frame/commit/1e82e55aa083ffac3016f54fac744ffcb417e557. However, that also introduced unnecessary derefs that weren't actually used, except for the side-effects of logging the error. The second set of derefs can be removed, we just need to find the right place and conditions for the logging statement to run.