Fork me on GitHub
#re-frame
<
2015-08-26
>
Petrus Theron10:08:17

I'm having a nightmare getting subscription arguments to work 😞

Petrus Theron10:08:10

(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

danielcompton10:08:42

What is reaction returning?

mikethompson11:08:58

@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 simple_smile The handler, as it stands, looks okay.

mikethompson11:08:36

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.

mikethompson11:08:19

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]]

mikethompson12:08:42

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.

Tom H.13:08:18

Putting the print in :pre... So simple! Thanks @mikethompson

dmich15:08:37

@mikethompson: You should also post that tip to the clojurescript mailing list (if you haven't already).

tel16:08:55

@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.

tel17:08:15

It'd be nice to have one of the Flow-like state rendered sported over too

shaun-mahood21:08:22

@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?

mikethompson23:08:02

@shaun-mahood: Off the top of my head ....

[input-text 
  .....
  :attr  {:on-key-down  #(println  "you pressed "  (.-which %))}]

mikethompson23:08:33

maybe :on-key-press instead ?