Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duplicate work in deref-input-signals #545

Open
mhuebert opened this issue Sep 5, 2019 · 1 comment
Open

duplicate work in deref-input-signals #545

mhuebert opened this issue Sep 5, 2019 · 1 comment
Assignees

Comments

@mhuebert
Copy link

mhuebert commented Sep 5, 2019

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))
              '())))
@danielcompton
Copy link
Contributor

danielcompton commented Sep 29, 2019

Thanks for catching this, it does look like a bug.

In 64f858c 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 1e82e55. 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.

@kimo-k kimo-k self-assigned this Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants