This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-15
Channels
- # announcements (2)
- # babashka (41)
- # beginners (10)
- # calva (62)
- # chlorine-clover (70)
- # cider (19)
- # clara (2)
- # clj-http (1)
- # clj-kondo (1)
- # cljs-dev (3)
- # cljsrn (8)
- # clojure (168)
- # clojure-austin (1)
- # clojure-australia (2)
- # clojure-canada (1)
- # clojure-europe (15)
- # clojure-france (9)
- # clojure-nl (3)
- # clojure-serbia (5)
- # clojure-spec (14)
- # clojure-uk (8)
- # clojurescript (14)
- # community-development (30)
- # core-async (42)
- # core-typed (1)
- # datahike (2)
- # datalog (23)
- # datomic (4)
- # emacs (4)
- # figwheel-main (4)
- # fulcro (60)
- # ghostwheel (4)
- # girouette (1)
- # gorilla (7)
- # graalvm (11)
- # heroku (8)
- # integrant (42)
- # jobs (6)
- # jobs-discuss (47)
- # kaocha (7)
- # lambdaisland (2)
- # leiningen (5)
- # lsp (29)
- # off-topic (1)
- # pathom (9)
- # portal (6)
- # re-frame (5)
- # reagent (11)
- # releases (6)
- # remote-jobs (10)
- # shadow-cljs (112)
- # testing (55)
- # vrac (1)
hey all! i'm trying out integrant in my app and it's going well enough, but i have a question that's not answered by the docs: i want access to the object created by integrant/`init-key` so i can reference it in the rest of my app. is that possible?
if not, should I bind the result to an atom and then (reset! state nil)
in halt-key!
?
oh, this is the returned object from init
, not init-keys
. nevermind, i have figured it out
actually, follow up. my current app has a function connect
which connects to the running mongo instance using an aero config file, and then uses defonce
to create a db
var with the returned mongo db connection
and then in the meat of the app, that db
var is required and used, which assumes that the connection has been made and the var has been defined, etc
what is the more functional approach to write something like that?
i'm sorry, i meant in a function like
(defn superusers []
(mc/find-maps db "users" {$or [{:isadmin true}
{:ismoderator true}
{:tournament-organizer true}]}))
the current codebase is filled with functions like this, that assume the connection exists in the db
var
is it better to pass the integrant system
into all of these calls? or to assign it to a global variable and require it?
but you could make that fn a component itself sort of how handler/greet returns a function at https://github.com/weavejester/integrant#initializing-and-halting
that page doesn't load for me
or you could make a component that returns a reify over a protocol, wrapping your db and exposing all the db-needing functions
hmmmm interesting!
yeah makes sense
i'll have to think about this a bunch, see what makes most sense
the point of integrant is that you build up components that are self-contained enough so that other, dependent components only need to pass in args that are relevant to their usecases
You can eliminate most if not all global state this way as all of it will be inside the system map.
yeah, that's definitely the goal cuz it's a ball of spaghetti right now
23 different namespaces require that db
var, which makes it "easy" but also very messy and means we have to be careful when writing tests or running things individually
by "wraps its functions", do you mean:
(defn example [{db :system/db}]
(defn db-fn1 [arg]
(do-something db arg))
(defn db-fn2 [arg]
(do-something db arg))
...)
(defn example [{db :system/db}]
{:db-fn1 (fn [arg] (do-something db arg))
:db-fn2 (fn [arg] (do-something db arg))})
thanks for the example, that's helpful
that's a neat trick. i realize i'm asking a lot, but do you have any projects/examples of that kind of logic?
I'm afraid I don't have anything I'd be allowed to share. But integrant is a phrase specific enough that a github code search should give you some examples
coolio, thanks so much for the help