Fork me on GitHub
James Acklin00:08:27

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

đź‘Ť 4

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

 (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 [] 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?


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]
          [re-frame.core :as rf])


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

đź‘Ť 4

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


@corentinhenry @jahson I wonder if something like Integrant’s load-namespaces would be better, for these kind of “registration requires”:


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


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


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


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


@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


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.