This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-19
Channels
- # announcements (6)
- # aws (10)
- # beginners (73)
- # bristol-clojurians (2)
- # calva (9)
- # cider (25)
- # clj-kondo (7)
- # clojure (160)
- # clojure-dev (2)
- # clojure-europe (63)
- # clojure-italy (7)
- # clojure-nl (10)
- # clojure-uk (76)
- # clojuredesign-podcast (6)
- # clojurescript (63)
- # cursive (6)
- # data-science (3)
- # datomic (26)
- # duct (59)
- # emacs (1)
- # fulcro (12)
- # graalvm (17)
- # hoplon (23)
- # jobs-discuss (2)
- # kaocha (6)
- # meander (7)
- # off-topic (3)
- # pathom (2)
- # rdf (68)
- # re-frame (12)
- # reagent (20)
- # reitit (5)
- # ring (3)
- # ring-swagger (1)
- # shadow-cljs (14)
- # spacemacs (10)
- # sql (3)
- # tools-deps (30)
- # yada (9)
@superstructor I see that the new lein-git-inject / github actions flow makes version numbers like v0.2.0
... these seem to confuse xsc/version-clj underlying olical/depot and lein-ancient:
| Dependency | Current | Latest |
|-----------------------------+----------------+---------|
| day8.re-frame/http-fx | v0.2.0 | 0.1.6 |
Hi. A question about performance and best practice. Is it OK / decent style to write a general reg-sub like this? Or is there something wrong with this?
(defn db-get [db [_ & [k & [not-found & _]]]]
(if (vector? k)
(get-in db k not-found)
(get db k not-found)))
(reg-sub :db db-get)
(comment
@(rf/subscribe [:db :datastores/loading?])) ; example usage
Here's what the authors of re-frame have to say: https://github.com/day8/re-frame/blob/master/docs/SubscriptionsCleanup.md#a-final-faq
Thanks @U2FRKM4TW I'm not sure I agree that sprinkling many reg-subs will help this problem. Perhaps for a bigger code base than mine.
I will think about it a little more though.
Another question. Is there a difference between these two functions:?
(defn view-1
[]
(let [a (rf/subscribe :a)
b (rf/subscribe :b)]
(fn []
[render-view @a @b])))
(defn view-2
[]
(let [a @(rf/subscribe :a)
b @(rf/subscribe :b)]
[render-view a b]))
Is one style to be preferred?In this particular case, there's no perceptible difference. I prefer the second style as the more explicit and terse one.
Thanks again. When would there be a difference?
When you call subscribe
but don't deref
the result in some circumstances. You must always deref
the subs, and with view-1
it's possible to make the mistake of not doing that, but it's not possible to do that with view-2
.
Another difference, albeit quite a bit exotic, is when you pass some arguments to view-1
where the top level function uses one set of the arguments and the returned function uses some other set of the arguments. Most of the time, it's an error that results in components not being updated when the data changes.