This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-08-26
Channels
- # admin-announcements (33)
- # beginners (41)
- # boot (97)
- # clojure (220)
- # clojure-berlin (3)
- # clojure-russia (31)
- # clojure-sg (3)
- # clojurebridge (2)
- # clojurescript (137)
- # clojutre (13)
- # core-matrix (10)
- # core-typed (1)
- # cursive (18)
- # datascript (1)
- # datomic (93)
- # devops (6)
- # editors (18)
- # emacs (1)
- # funcool (43)
- # hoplon (4)
- # immutant (6)
- # instaparse (3)
- # jobs (25)
- # ldnclj (14)
- # ldnproclodo (4)
- # off-topic (20)
- # om (21)
- # rdf (79)
- # re-frame (14)
- # reagent (12)
- # ring-swagger (18)
- # yada (52)
I'm having a nightmare getting subscription arguments to work 😞
(register-sub
:entities/sub
(fn [db args]
(let [[_ tbl id] args]
(timbre/debug "args" args) ; this works
(timbre/debug "tbl id" tbl id "entity" (get-in @db [:entities-cache tbl id])) ; I can see entity here
(reaction (get-in @db [:entities-cache tbl id])))))) ; but this won't work
What is reaction returning?
@petrus: for us to help, you'll have to put some effort into explaining the problem clearly. "This won't work" is not enough to go on The handler, as it stands, looks okay.
My guess is that the "problem" is to be found in the view using this subscription. But with so little to work on, that's a wild guess. In the view, did you remember to put a @
in front of the subscription var when you want to use the value? That's a baffling rookie mistake which gets us all.
Here is a useful debuggin tip I picked up from @escherize ...
When you are debugging a reagent view ... or a subscription delivered value to a view ...
... add something like this to the hiccup in your view ...
[:pre (with-out-str (pprint @some-atom))]
;; assuming that @some-atom
is the value you want to observe (note the @
in front)
You don't even have to use pprint, you could just do this:
[:pre (pr-str @some-atom)]
If you do use pprint
then you'll need to require it in at the top of your view.cljs
:
[cljs.pprint :refer [pprint]]
Further note: the advanced version of this technique is to not use pr-str
or pprint
but instead to use @yogthos' excellent json-html library: https://github.com/yogthos/json-html for even more carefully arranged display.
Putting the print in :pre... So simple! Thanks @mikethompson
@mikethompson: You should also post that tip to the clojurescript mailing list (if you haven't already).
@mikethompson: been doing this for a while with my Re-Frame workflow; showing the whole app state with pre and pprint at the bottom of the page.
@mikethompson: I'm using re-com with re-frame, and was wondering how to go about detecting a specific keypress in an input-text component. Is there an easy way?
@shaun-mahood: Off the top of my head ....
[input-text
.....
:attr {:on-key-down #(println "you pressed " (.-which %))}]
maybe :on-key-press
instead ?