Fork me on GitHub
#re-frame
<
2018-02-03
>
p-himik07:02:13

I have a component like

(defn component [visible?]
  [re-com/modal-panel
   :visible? visible?
   :child [...]])
visible? is a plain ratom set from the parent component. What I notice is that any subscription created and immediately dereferenced in [...] above is not catched by re-frame/trace. Is it because there's no event that leads to this subscription's creation?

mikethompson07:02:43

Q #1: should that be :visible? @visible?

mikethompson07:02:00

I'm just rtying to remember myself

mikethompson07:02:28

Q #2: are you saying there that [...] is something like [:div @(subscription [:blah]) "Hello"]

p-himik07:02:28

1. :visible? is wrapped with re-com.util/deref-or-value inside re-com/modal-panel, and has :type "boolean | atom" spec. 2. Exactly.

mikethompson07:02:20

I find point 2 odd.

mikethompson07:02:25

There's definitely a @ before it, right?

mikethompson07:02:22

Assuming yes, the act of creating the hiccup data structure should cause the subscription to be created and then dereferenced.

Vincent Cantin07:02:33

Are users of re-frame supposed to keep the state, events, subs and views separated from each other, or is that fine if they decide to group them for each of their 'component' ?

mikethompson08:02:48

Watever means that you can easily find what you want. Or, more to the point, whatever means the person after you can easily find the right handlers.

p-himik08:02:11

@mikethompson Yeah, the subscription is definitely created. I just can't see it in the re-frame/trace window.

mikethompson08:02:14

Is it a layer 2 subscription?

mikethompson08:02:25

Perhaps you have that tickbox on top right of subscriptions panel?

mikethompson08:02:09

The tickbox which asks re-frame-trace to filter out unchanged layer 2 subscriptions

p-himik08:02:29

Layer 3. Actually, now I see it, but I have to refresh the page with the trace panel opened. So, I guess it's just misunderstanding on my side - the trace panel doesn't actually trace anything when it's not opened, right?

p-himik08:02:07

I just got used to the old behavior. 🙂 Thanks!

p-himik08:02:42

Are there any plans to also show raw subscriptions?

mikethompson08:02:02

You mean: show subscriptions created via reg-sub-raw?

mikethompson08:02:34

We haven'tgiven it much thought

mikethompson08:02:51

You'll need to create an issue

mikethompson08:02:07

How are you finding re-frame-trace other than that?

mikethompson08:02:19

Apart from reg-sub-raw capture, is there any thing else that you'd like to see?

p-himik08:02:35

It's great! I really like how it evolves.

mikethompson08:02:56

I've got to go off for dinner. But drop any notes in here.

andrewboltachev13:02:18

Hello. Does anyone have problems like Uncaught Error: ["unrecognized request format: " nil]? I'm trying to send AJAX request like this:

(re-frame/reg-event-fx
 :test1
 (fn [{db :db} & _]
   {:http-xhrio {:method :post
                 :uri "/api"
                 :timeout 8000
                 :request-format (transit-request-format {:type :json})
                 :response-format (transit-response-format {:type :json})
                 :on-success [:test1-success]
                 :on-failure [:test1-failure]
                 }}))
where request format functions are imported as follows:
[ajax.transit :refer [transit-request-format
                                       transit-response-format]]

Vincent Cantin13:02:05

Where is the right place to listen to keyboard events on the document in a figwheeled re-frame app ?

Vincent Cantin13:02:17

Should I ask this kind of question here or on Stackoverflow?

andrewboltachev13:02:52

@vincent.cantin 1) You might try to add event listener in core, as document is global object in JS (parent of html element) and it should be always available. And your handler fn should do re-frame.core/dispatch 2) If no one helps here or help is ineffective, ask on SO 🙂

Vincent Cantin13:02:23

Thanks, it make sense and should work.

andrewboltachev13:02:27

@vincent.cantin by core I mean init function

Vincent Cantin13:02:37

I am wondering if in fact that would not be better for the community to post questions on SO directly. - It helps build a searchable knowledge base. - It brings visibility on the language and library.

andrewboltachev13:02:39

when working on app development, you should then be able to change the behaviour of an event handler by changing the re-frame event handler respectively

andrewboltachev13:02:02

@vincent.cantin not sure about the right place, it's rhetorical question 🙂 also, I'm not sure if there're well-defined "correct places" or approaches for every need (though it'd be cool if so)

andrewboltachev13:02:38

i.e. personally I have an impression that you still need to experiment yourself

p-himik13:02:16

I would say that SO is definitely a better place for well-defined questions.

andrewboltachev13:02:38

UPD: I've solved my issue from above by changing :request-format to :format. Need to RTFM more 🙂

lgessler19:02:37

hey, sorry if this is a question asked all the time, but searches didn't really turn up anything. i'm writing an app with a lot of independent widgets: i.e., they have their own parts of the app-db and don't really interact with others, and there are many of them. is there a best practice for organizing code for situations like this? so far i've been keeping all the subs, events, views, etc. for each widget in a single file per component, which seems nice, but i'm wondering if there might be some downsides i'm not aware of yet

joelsanchez21:02:08

been doing that for a while, no downsides yet. though I always use fully qualified keywords and alias the ns from the outside

joelsanchez21:02:25

(ns something.example.slider)
(reg-event-fx ::next...)

(ns something.core
  (:require [something.example.slider :as slider])
(rf/dispatch [::slider/next]...)

mikethompson23:02:41

@joelsanchez remember that you can use synthetic namespaces. The namespace doesn't have to exist for it to be used in a keyword: (rf/dispatch [:i-just-made-this-up/next])

joelsanchez23:02:56

i know, but i want to ensure that the ns is required

joelsanchez23:02:07

i do something which might be controversial from what I've read 🙂 instead of declaring subscriptions everywhere that just get a path from the db, I did an universal subscription and use that instead

(defn- normalize-where [where]
  (if (keyword? where)
    [where]
    where))
(rf/reg-sub
 ::db
 (fn [db [_ where]]
   (get-in db (normalize-where where))))
since no one recommends or even talks about this it might be heresy