This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-04
Channels
- # aleph (8)
- # aws (14)
- # babashka (37)
- # beginners (30)
- # calva (5)
- # cider (4)
- # clj-kondo (21)
- # cljsrn (4)
- # clojure (234)
- # clojure-denmark (1)
- # clojure-europe (10)
- # clojure-france (10)
- # clojure-italy (4)
- # clojure-nl (17)
- # clojure-sanfrancisco (1)
- # clojure-spec (8)
- # clojure-uk (44)
- # clojurescript (20)
- # cursive (9)
- # datascript (2)
- # datomic (5)
- # emacs (9)
- # fulcro (50)
- # graalvm (32)
- # jackdaw (18)
- # leiningen (1)
- # malli (10)
- # meander (10)
- # nrepl (10)
- # off-topic (15)
- # pathom (20)
- # re-frame (14)
- # reagent (37)
- # reitit (7)
- # ring (1)
- # shadow-cljs (102)
- # test-check (6)
- # tree-sitter (15)
- # vim (4)
- # xtdb (2)
- # yada (1)
Hi all, quick question. What is the impact on the store if reg-event-fx
returns a nil value? I have a reg-event-fx
which uses an if-let
. I noticed with reg-event-db
that my db
value was "niled" if there was an if
which returned nil
.
I think you’ll want to return the unchanged db in your reg-event-fx {:db db}
rather than having it return nil.
same with reg-event-db
, you’ll want to return the existing db rather than a nil value in case of a no-op
forgot if you can omit the db key from reg-event-fx, might want to try that out
yeah just testing it out, reg-event-fx doesn’t need {:db db}, you can just return nil and no side effects get called.
Ok, great. Yea, I noticed that as well and wanted to double check 😄 So, for reg-event-db
we have to return {:db db}
and reg-event-fx
we can return nil
with no issues. Is this in the docs somewhere?
i think the way to look at it is that reg-event-fx takes a map of coeffects to perform
reg-event-db’s job is only to perform the :db coeffect
which swaps the existing db with the one provided
Ahhh ok, that makes sense. This is why we have to provide some value to swap.
To make this common case easy to program, there's a specific registration function, called reg-event-db, which delivers ONLY the coeffect db to the event handler (and event of course).
I found the way reg-fx is used to setup the :db effect handler was useful to show how reg-fx works: https://github.com/day8/re-frame/blob/master/src/re_frame/fx.cljc#L160