This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-15
Channels
- # announcements (2)
- # babashka (137)
- # beginners (96)
- # calva (3)
- # cider (11)
- # clj-kondo (8)
- # cljs-dev (161)
- # cljsrn (21)
- # clojure (78)
- # clojure-europe (47)
- # clojure-france (1)
- # clojure-losangeles (1)
- # clojure-nl (4)
- # clojure-spec (24)
- # clojure-uk (9)
- # clojuredesign-podcast (4)
- # clojurescript (39)
- # conjure (2)
- # core-async (27)
- # cursive (36)
- # datomic (54)
- # emacs (6)
- # figwheel (9)
- # figwheel-main (46)
- # fulcro (25)
- # graalvm (8)
- # helix (30)
- # hoplon (6)
- # hugsql (3)
- # jobs (5)
- # leiningen (7)
- # luminus (12)
- # nrepl (20)
- # off-topic (20)
- # pedestal (16)
- # re-frame (14)
- # reagent (3)
- # reitit (3)
- # remote-jobs (5)
- # rum (25)
- # shadow-cljs (60)
- # spacemacs (10)
- # vim (2)
- # xtdb (36)
I'm trying to simplify the re-frame reg-event-db function, and I have the following macro so far:
(defmacro db-event [event-key params & body]
`(do
(re-frame.core/reg-event-db ~event-key
(fn [~'db [_# ~@params]]
~@body))
(defn ~(symbol event-key) ~params (re-frame.core/dispatch [~event-key ~@params]))))
And it works pretty well, in that I can use it like so:
(db-event :remove-from-cart [product-id]
(assoc-in db [:cart product-id] (-> db :cart (get product-id) dec)))
However, I want to further simply it, and there shouldn't be a need to write assoc-in. So I would like a functionality like this:
(db-event :foo [resp] {:abc {:def resp :efg (more-stuff resp)} :foo1 {:bar1 (stuff resp)}})
instead of :
(db-event :foo [resp]
(->
(assoc-in db [:abc :def] resp)
(assoc-in db [:abc :efg] (more-stuff resp))
(assoc-in [:foo1 :bar1] (stuff resp))))
So basically, I want to give a map which tells which values are to be changed rather than writing a bunch of assoc-ins in succession.
How can I do that?👍 4
Perhaps look up the path
interceptor
It is used in the todomvc sample
https://github.com/day8/re-frame/blob/master/src/re_frame/std_interceptors.cljc#L148-L172
https://github.com/day8/re-frame/blob/master/examples/todomvc/src/todomvc/events.cljs#L71-L80
Best if you read the links
That's EXACTLY what the links do
yeah okay, that's not the point is it? The example shows a single path (path :todos), but what I need is to give a map which contains all the keys and the values that are to be changed. Really more to do with macros than with re-frame.
If you say so
I'm off