Fork me on GitHub
#re-frame
<
2019-08-02
>
James Acklin00:08:27

Yes! Exactly what I'm looking for. Thank you.

👍 4
little-dude09:08:15

Hello. I sometimes require namespaces that I don't use. For instance, I have the following file:

(ns myapp.authentication.utils
  (:require [re-frame.core :as rf]))

(rf/reg-cofx
 :authorization-header
 (fn [cofx]
   (let [token (get-in cofx [:db :user :token])
         header {"authorization" (str "Token " token)}]
   (assoc cofx :authorization-header header))))
If I want my cofx to be registered, I have to require that namespace somewhere. But I don't feel very comfortable requiring something I'm not using: - someone may not understand why it's there, remove it and break things - my linter warns against it - it feels like a hack Note that it's the same for re-frame-http-fx: if have to :require [day8.re-frame.http-fx] to register the http-xhrio cofx, although I'm not directly using anything from that namespace. So my question: is it ok to do that, is it a common pattern when working with re-frame?

timgilbert21:08:33

One convention I've adopted with this is to require the relevant namespaces without brackets to make them stand out a little more, eg:

(:require [clojure.string :as str]
          my.little.util
          [re-frame.core :as rf])

jahson13:08:52

It's the way the things are working at the moment. You could just leave a comment to prevent the ns being deleted

👍 4
romain14:08:41

I have a button which perform a POST request, but I would like to display a modal to confirm the action. The modal is generic and I instantiate it for another POSTrequest. What would be the good strategy? I was thinking about using interceptor, and use dispatch in it to show/hide the modal

rgm14:08:08

@corentinhenry @jahson I wonder if something like Integrant’s load-namespaces would be better, for these kind of “registration requires”: https://github.com/weavejester/integrant/blob/master/README.md#loading-namespaces

rgm18:08:29

true… it’s just harder to trip over in one of my periodic kill-all-linter-warnings cleanup binges.

rgm14:08:28

It’s a pain to keep telling eg. Joker to ignore the unused require and this seems more explicit about what’s going on.

rgm14:08:38

No functional difference but it assigns meaning. I’ve also used a (require ,,,) after the ns declaration to keep these stylistically separate.

manutter5114:08:58

@romain I typically think about it like, "This button on my form displays a modal, and the Confirm button on the modal performs the POST." Makes it a bit simpler.

romain14:08:43

@manutter51 I do this. But modal is a generic reagent component. When I click on form button, I dispatch to set the informations and confirm button function to :active-modal. But I need to show/hide too, that's why I thought about interceptors

manutter5115:08:33

The way I do it is to pass in an argument to the modal with the dispatch vector to dispatch when the user clicks the button.

8