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

:<- macro does not work across namespaces #207

Closed
joshkh opened this issue Aug 24, 2016 · 6 comments
Closed

:<- macro does not work across namespaces #207

joshkh opened this issue Aug 24, 2016 · 6 comments

Comments

@joshkh
Copy link

joshkh commented Aug 24, 2016

In the following example, using the :<- macro in the myapp.components.events namespace causes re-frame to throw an exception stating that the :main/some-items subscription handler cannot be found

(ns myapp.core
  (:require [myapp.events]
            [myapp.component.events]))
(ns myapp.events
  (:require [re-frame.core :refer [reg-sub]]))

(reg-sub
  :main/some-items
  (fn [db]
    (:all-items db)))
(ns myapp.component.events
  (:require [re-frame.core :refer [reg-sub]]))

(reg-sub
  :components/filtered-items
  :<- [:main/some-items]
  (fn [items]
    (filter odd? items)))

re-frame: no subscription handler registered for: " cljs.core.Keyword_hash: 1803312489cljs$lang$protocol_mask$partition0$: 2153775105cljs$lang$protocol_mask$partition1$: 4096fqn: "main/some-items"name: "some-items"ns: "main"proto: Object ". Returning a nil subscription.cljs.core.apply.cljs$core$IFn$_invoke$arity$2 @ core.cljs:3679
subs.cljc?rel=1472037082624:64Uncaught TypeError: Cannot read property 'call' of null

@stumitchell
Copy link
Contributor

I would make sure that myapp.events is loaded before myapp.component.events to do this change the require in myapp.component.events to the following.

(ns myapp.component.events
  (:require [re-frame.core :refer [reg-sub]]
            [myapp.events]))

Let us know if that fixes it.

@mike-thompson-day8
Copy link
Contributor

@joshkh Given the error message you posted, you really, really need to be using clj-devtools https://github.com/binaryage/cljs-devtools.

@mike-thompson-day8
Copy link
Contributor

I'm about 100% sure Stu has answered your question. So I'm going to close this. Will reopen as necessary, but please direct support questions to clojurians.

@jamesnvc
Copy link

jamesnvc commented Nov 7, 2016

Something I'd like to add to this issue is that reg-sub is inconsistent as to when this will and will not work: Specifically, as in the example above, with one pair it fails, but if you have multiple pairs of :<- [:sub] it does work (since the implementation uses map in the multiple-sub cases, so the value isn't realized until later). It is very confusing to have something work and then stop working when removing subs - I submit it would be better if it either worked (preferable) or didn't consistently.

@danielcompton
Copy link
Contributor

@jamesnvc that behaviour is fixed in #259, the behaviour of the single pair now matches the multiple pairs.

@jamesnvc
Copy link

jamesnvc commented Nov 8, 2016

@danielcompton perfect, thank you so much for the prompt reply!

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

5 participants