This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-12
Channels
- # aleph (10)
- # beginners (62)
- # boot (12)
- # cider (97)
- # cljs-dev (171)
- # clojars (1)
- # clojure (224)
- # clojure-italy (4)
- # clojure-nl (2)
- # clojure-russia (1)
- # clojure-spec (41)
- # clojure-uk (68)
- # clojured (7)
- # clojurescript (115)
- # community-development (4)
- # cursive (2)
- # data-science (1)
- # datomic (18)
- # duct (40)
- # emacs (1)
- # events (1)
- # fulcro (148)
- # funcool (2)
- # graphql (2)
- # immutant (3)
- # jobs (3)
- # keechma (1)
- # luminus (2)
- # numerical-computing (1)
- # off-topic (19)
- # om (6)
- # parinfer (10)
- # pedestal (15)
- # precept (86)
- # reagent (12)
- # ring (3)
- # ring-swagger (2)
- # shadow-cljs (42)
- # spacemacs (19)
- # specter (17)
- # sql (11)
- # tools-deps (78)
- # unrepl (62)
- # vim (28)
I’m writing a defbefore
that uses a component, what’s the best way to pass the component inside?
@nooga Something I usually end up doing is write an interceptor to attach the whole system map to the context.
(defn attach-system [system-map] {:enter (fn [context] (assoc context :system system-map))})
As an example with non-component systems, I’ve adopted the following pattern using Integrant:
(defmethod ig/init-key ::inject-bus [_ {:keys [bus]}]
{:name ::inject-bus
:enter (fn [ctx] (assoc ctx :bypass.events/bus bus))})
then I can pass that interceptor around the system map as neededso the bus
component is closed over in the interceptor creator, which will inject the component into the context map when entered
the other would be to capture the component (defn my-before [component] (helper/before (fn [context] ... component ...))
Basically the same idea. You can decide how much to close over when creating the interceptor.