This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-14
Channels
- # announcements (3)
- # aws (7)
- # babashka (108)
- # beginners (222)
- # bristol-clojurians (3)
- # calva (8)
- # chlorine-clover (1)
- # cider (14)
- # clj-kondo (4)
- # cljdoc (6)
- # cljs-dev (89)
- # cljsrn (13)
- # clojars (6)
- # clojure (89)
- # clojure-australia (1)
- # clojure-europe (11)
- # clojure-italy (9)
- # clojure-losangeles (11)
- # clojure-nl (6)
- # clojure-spec (2)
- # clojure-sweden (1)
- # clojure-uk (9)
- # clojurescript (47)
- # conjure (18)
- # datomic (7)
- # docker (1)
- # figwheel (43)
- # figwheel-main (2)
- # fulcro (31)
- # kaocha (3)
- # leiningen (7)
- # luminus (2)
- # nrepl (14)
- # off-topic (24)
- # pathom (5)
- # pedestal (5)
- # rdf (4)
- # re-frame (49)
- # reagent (12)
- # reitit (9)
- # rum (21)
- # shadow-cljs (109)
- # tools-deps (35)
- # vim (8)
- # wasm (1)
there’s not really a good way to have a subscription that says, “update only if <some predicate>”
I dunno, say you have an app db like:
{:number 0}
an event like:
(reg-event-db :inc
(fn [db _]
(update db :number inc)))
and a couple subs:
(reg-sub :even
,,,)
(reg-sub :odd
,,,)
is it possible to have :even
only update when :number
is even, and :odd
only update when :number
is odd?https://github.com/day8/re-frame/blob/master/src/re_frame/std_interceptors.cljc#L205-L226
For example, for any event handler that may change the number, add an on-changes
interceptor that will write another piece of state
I’m really not chasing any particular use case for this, rather asking about the capability
there’s definitely ways to get around this by storing the evens and odds in other places
but it sounds like there’s not a way to directly do something where a change occurs and you “skip” it based on some logic
Ok. The closest concept I think of is having a dynamic graph, as explained in this talk (Incr.bind instead of Incr.map): https://www.janestreet.com/tech-talks/seven-implementations-of-incremental/
Have you found that you miss it? I've thought about it but haven't noticed the pain of not having it yet
Would
(reg-sub :even
(fn [db _] (even? (:number db))))
not do what you want? Maybe I misunderstand the initial question. It's unclear what you mean by "have a sub update".@U08JKUHA9 that talk is wonderful
(reg-sub :seven:
;; signal function
(fn [] (subscribe [:number])
;; computation function
(fn [number]
(if even? number (dec number)))
It isn't natural, but its possible.
that relies on the fact that the previous value can be trivially computed from the current
yeah, it relies on being able to compute the value you want from what's in app-db
currently
I think what you want is to have a sequence of arb values
kinda arb
The more re-frame-y way would be to put that sequence in app-db
itself. And to manage it via the logic of event handlers
yeah could do that. that relies on keeping some amount of old values in the app-db and managing that yourself, if you don’t want to store an arbitrarily long seq
Or just storing the current :even` and :odd
maybe
the way I’ve started thinking about it: what if reagent allowed transducers on reactions, similar to channels
That is the reframe way. We want events to be causal We want subs to calcualte a materialsed view
Your materialised view is a bit on the edge
filtering is
But you aren't doing filtering
Or, you are doing filtering, but you are doing it on history
Which is why it works if you store the history in app-db
do you recommend using re-frame-test
or separate the content of the handlers and subscriptions to functions and test those?
I think of those as unit vs "integration", it depends on the specific goal. Testing a complete async-flow
was simpler with re-frame-test
, but straightforward handlers don't really need it.
From a general standpoint, I prefer to unit test the content of the handlers because that's a smaller surface area.