This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-05-09
Channels
- # announcements (12)
- # beginners (159)
- # boot (3)
- # calva (41)
- # cider (48)
- # clara (2)
- # clj-kondo (8)
- # cljdoc (8)
- # clojure (70)
- # clojure-dev (10)
- # clojure-europe (2)
- # clojure-losangeles (1)
- # clojure-nl (12)
- # clojure-spec (7)
- # clojure-uk (63)
- # clojurescript (24)
- # cursive (24)
- # datomic (22)
- # expound (17)
- # figwheel (1)
- # fulcro (176)
- # graphql (23)
- # jobs (9)
- # jobs-discuss (56)
- # kaocha (1)
- # mount (3)
- # nyc (1)
- # off-topic (91)
- # onyx (3)
- # overtone (4)
- # pathom (3)
- # pedestal (1)
- # re-frame (11)
- # reitit (19)
- # ring (8)
- # shadow-cljs (16)
- # test-check (5)
- # testing (2)
- # tools-deps (20)
- # vim (9)
It’s frowned on… https://github.com/Day8/re-frame/blob/master/docs/FAQs/UseASubscriptionInAnEventHandler.md
thanks a lot @manutter51!
@fmnoise @manutter51 Why not just get what you need out of the db?
Not all subscriptions are in the db — you can derive calculated values from other subscriptions, and you may not want to duplicate the code.
That said, it takes a bit of extra effort to get subscription data safely into the event handler, so for simple (non-derived) subscriptions, it’s usually simpler and easier to just pull it out of the app-db.
yep, it's in db, but getting that from db smells a bit, cause if db path changed than we need to update that in 2(or more) places which pushes us to idea of storing and sharing subscription path like [:user :role :admin?]
and using it in reg-sub and some other place to get value when subscribe is not suitable
Ah, I haven't used any subs that don't get their data from the db, so hadn't thought of that use-case.
The way I get around path changes is with helper functions and organized namespaces. So, for example, I’ll have a namespace that deals with manipulating user data, and at the top I’ll have
(defn user-path [& sub-path]
(vec (concat [:user] sub-path)))
and then in a handler I can do (get-in db (user-path :roles :admin?))
, which is still readable and simple. And if I decide to make :user
a sub-key under :globals
, all I have to do is modify user-path
to be (defn user-path [& sub-path]
(vec (concat [:globals :user] sub-path)))
`