Fork me on GitHub
Petrus Theron10:08:17

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

Petrus Theron10:08:10

  (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 simple_smile 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: for even more carefully arranged display.

Tom H.13:08:18

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.


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


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

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


maybe :on-key-press instead ?