This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-07
Channels
- # announcements (35)
- # beginners (80)
- # boot (1)
- # calva (4)
- # cider (33)
- # cljdoc (40)
- # clojars (3)
- # clojure (95)
- # clojure-berlin (2)
- # clojure-europe (4)
- # clojure-italy (28)
- # clojure-nl (2)
- # clojure-seattle (1)
- # clojure-serbia (1)
- # clojure-spec (74)
- # clojure-uk (71)
- # clojurescript (29)
- # core-async (1)
- # cursive (80)
- # data-science (4)
- # datomic (17)
- # duct (75)
- # emacs (4)
- # figwheel-main (5)
- # fulcro (3)
- # jackdaw (1)
- # java (1)
- # jobs-discuss (20)
- # off-topic (32)
- # parinfer (2)
- # pathom (23)
- # re-frame (26)
- # reagent (25)
- # rum (6)
- # shadow-cljs (122)
- # speculative (4)
- # sql (17)
- # testing (7)
- # yada (8)
If your UI is made by pretty much “separate” views, how would the single app-db approach of re-frame work? Would you use namespaced keys to segregate the state of different views, or wipe the state entirely when you transition to a completely separate view?
You could always just use nested keys. Like all state related to page X would be under a :page-x
key within the db, and top-level state is in the top-level of the db or under a :global
key
you could still want to use namespaced keys occasionally, but mostly if you've actually ran out of available key names, which in my experience isn't a big problem if you nest
Right, using nested keys was my first thought too. If that’s a common pattern, I will explore further.
Is there a way to pass a parameter to a subscription that does a computation? The subscription that is used for the computation takes a parameter. See example below
(register-sub
:cart-items
(fn [db [_ category]]
(get-in db [:cart category :item])))
(rf/reg-sub
:cart-count
(fn [_] ; <--- this is where the param would theoretically go
(rf/subscribe [:cart-items]))
(fn [items]
(count items)))
if you want to use already registered subs as parameters to a new sub there's syntax sugar for that
you can include as many subs with :<-
as you want, but note that multiple will be sent back in as a vector
My question is more so how can I pass a parameter to a registered sub used in the computation
(register-sub
:cart-items
(fn [db [_ *category*]] ; <-- parameter passed to subscription
(get-in db [:cart category :item])))
(reg-sub :cart-count
:<- [:cart-items *category*] <-- same parameter
(fn [items]
(count items)))
if category
is something that's selectable from the UI i'd just store it as a key and use that so it's available when :cart-count
gets called
now there'd be no need to pass category on to :cart-count
, it can just take in :cart-items
whenever it's called and not have to worry about it
Hi, I'm struggling to understand why this don't triggers instrumentation.
(defn coco [_])
(cljs.spec.alpha/fdef coco :args
(cljs.spec.alpha/cat :str string?))
(re-frame.core/reg-event-fx :coco coco)
(cljs.spec.test.alpha/instrument `coco)
(dispatch [:coco])
BUT, it works if I put the instrument line before registering the event. :thinking_face:It seems related to re-frame, but I'm not 100% sure@franquito is that ` correct?
I guess it's fine, but seems unusual
I'm not actually sure how instrument works under the covers
Does it modify the actual functions?
If so, then re-frame already has a reference to the unstrumented function