This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-02
Channels
- # announcements (3)
- # beginners (28)
- # calva (5)
- # clj-kondo (17)
- # cljsrn (1)
- # clojure (69)
- # clojure-dev (23)
- # clojure-europe (1)
- # clojure-italy (27)
- # clojure-japan (1)
- # clojure-nl (5)
- # clojure-spec (34)
- # clojure-uk (87)
- # cursive (93)
- # datomic (15)
- # duct (6)
- # emacs (3)
- # events (2)
- # garden (1)
- # graalvm (4)
- # jobs (3)
- # malli (1)
- # off-topic (13)
- # onyx (1)
- # pathom (8)
- # pedestal (2)
- # re-frame (13)
- # reitit (5)
- # shadow-cljs (13)
- # sql (13)
- # test-check (5)
- # testing (3)
- # yada (1)
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?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])
It's the way the things are working at the moment. You could just leave a comment to prevent the ns being deleted
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 POST
request. 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”:
https://github.com/weavejester/integrant/blob/master/README.md#loading-namespaces
In the end Integrant is doing (require)
https://github.com/weavejester/integrant/blob/9c69a440ebff697336efef7e286d62df1cd3f49d/src/integrant/core.cljc#L170-L172
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.
In the end Integrant is doing (require)
https://github.com/weavejester/integrant/blob/9c69a440ebff697336efef7e286d62df1cd3f49d/src/integrant/core.cljc#L170-L172