Fork me on GitHub

@eoliphant Can I use them for inspecting re-frame in clojure ? I thought that is only available for browser .


@shakdwipeea What are you trying to do? I have difficulty imagining how re-frame would be useful without a browser and clojurescript.


I am experimenting with re-frame for communication b/w clojure and clojurescript. I have created an effects handler which send the data to my server using web sockets. This data is generally of the form [:some-event data], on the server upon receiving this data I am doing a dispatch for that event. Now I have event handlers defined in clojure which is then triggered, the server can also communicate to client in a similar problem. The works well for a few times, but after some time my event handlers on the server are not being called even after dispatch.


Hi. I'm creating a form 3 component and was wondering, whether it's considered bad practice to trigger side effects in reacts lifecycle hooks. On component-did-mount, I bind a js event handler and call a js function and on component-did-update I trigger a change event on one dom node. Should those be effects or do you think it's fine?

Oliver George10:05:49

There are certainly times when it's unavoidable to get at specific features. In my business apps it's pretty rare I jump to it.

Oliver George10:05:09

Is there a specific example which you have in mind?


mounting scroll handlers on window - better to do in react lifecycles, high-level logic like :user-closed-popup - better in effects.


Yes, avoiding side effects as much as possible is obviously the right way to do it, but here I work with existing code. It's about bootstrap-toggle, an open-sourced thing. I need to initialize it in the beginning so it renders and if the state updated, I need to trigger the change event to make it reflect that change in the UI.

Oliver George13:05:08

Yeah, then you're probably on the right track... except it's always nice to look for a react component to replace old stateful ones.


came to the same conclusion and rewrote the component without jquery. Just reuse the styling 😉


way simpler than making that stateful thing work

Oliver George23:05:44

Yeah, exactly


Hi, whats the idiomatic way to set an option as selected in a html select component? Is it (if (= value (rf/subscribe [:selected-value]) "selected" "")?


i think you just need to set the value property of the select input


@U6AE62UCT Thats exactly what I was looking for, thank you very much.


ah sorry @shakdwipeea, missed the ‘in clojure’ part


@sveri I think that is one reasonable way,but you need to deref the subscription. Also, do you mean to set the :selected property of a <option> element?

(let [selected @(rf/subscribe [:selected-value])]

  [:option (cond-> {} (= value selected) (assoc :selected true)) ...etc...]



@mikerod Thanks, thats the way I did it. I was just wondering if there is a more succinct way


I don’t know of anything. You could perhaps make a custom component that encapsulated that behavior


if you wanted to do it more often in different context for example


I’ve got this type of subscription:

 (fn [db [_ & path]]
   (let [full-path (into [:loading] path)]
     (get-in db full-path))))
and then I’m using it like so
(re-frame/subscribe [::subs/is-loading? :sortable :projects])
and it always returns undefined


I was wondering - can I not pass multiple arguments to the subscription like that?


destructuring should work as typical on a fn


Are you sure that ::subs/is-loading? is resolving to the same qualified keyword as where you are defining the re-frame/reg-sub on ::is-loading?


yes, because when I log out path and full-path in that function, they show up


at the right time


to be more specific, it’s on a button click


if you are seeing the fn called and the args showing, that sounds like it is working


so perhaps the path doesn’t exist in your db?


is @(re-frame/subscribe [::subs/is-loading? :sortable :projects]) returning nil?


so a button click updates db and it does this:

 (fn [{:keys [db]} [_ path new-items]]
   {:db (assoc-in db [:loading :sortable :projects] true)}))


shouldn’t that be creating the path in db?


Looking at that, I’d think so


but it’d be better to inspect your db to be sure


bunch of ways to do that, not sure what tools you may be using


there is the re-frame-10x which I’m still getting around to exploring more. There is re-frisk which lets you look at the db state via a click/expand UI widget. Then you can also just make a subs on the db and do some REPL prodding at it or prns etc


You probably want to double check the db is getting in the state you expect though


something even weirder here:

 (fn [db [_ & path]]
   (let [full-path (into [:loading] path)]
     (js/console.log (get-in db [:loading :sortable :projects]))
     (get-in db full-path))))
that console.log outputs the correct value 😕


but it outputs undefined when I do

(get-in db full-path)


umm.. one question. this is how I subscribe to that:

      (fn [items item-view db-path]
        (let [is-loading? @(re-frame/subscribe [::subs/is-loading? :sortable :projects])]
        (js/console.log is-loading?)
        (if is-loading?
          [:div "Is loading now"]
           (map item-view items)])))


is that a valid way to do it?


or should I have this somewhere at the top?