This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-16
Channels
- # 100-days-of-code (1)
- # announcements (1)
- # beginners (93)
- # boot (46)
- # cider (40)
- # cljdoc (4)
- # cljs-dev (7)
- # clojure (78)
- # clojure-conj (12)
- # clojure-dev (17)
- # clojure-italy (5)
- # clojure-nl (10)
- # clojure-spec (34)
- # clojure-uk (36)
- # clojurescript (56)
- # code-reviews (6)
- # core-async (31)
- # cursive (12)
- # datascript (9)
- # datomic (19)
- # devops (2)
- # editors (3)
- # emacs (6)
- # events (2)
- # figwheel (1)
- # figwheel-main (11)
- # fulcro (59)
- # graphql (10)
- # hyperfiddle (3)
- # keechma (5)
- # leiningen (26)
- # luminus (1)
- # nrepl (5)
- # re-frame (5)
- # reitit (10)
- # shadow-cljs (64)
- # spacemacs (29)
- # tools-deps (6)
- # uncomplicate (8)
- # vim (2)
- # yada (4)
Are there any drawbacks of making the resolvers look into their context for any component they need (e.g. a database) instead of (as the tutorial suggests) getting passed that dependency via a closure?
It's situational and/or personal choice. The FieldResolver protocol was a later addition. Generally, if a field resolver is stand-alone (no dependencies, just a pure function), I prefer it to be a simple function; if it has component dependencies, I prefer it to be a component implementing FieldResolver. But at the same time, the application context exists specifically so that the outer application (typically, your Pedestal interceptor chain) can provide values that will be needed by field resolvers (or to allow outer field resolvers to provide data to inner field resolvers).
I’d like (during development) to be able to re-eval a single resolver and have it have immediate effect, without actually having to re-eval some other things as well (e.g. my system).
I do that by changing the resolver reference to #'my-resolver
before starting my system. Then I can re-evaluate it.
That works when the resolver is just a function, but not when it is constructed by closing over some stateful component, right?
Np :) that var trick is quite cool - and unless I misunderstand it, it’s a Clojure thing.