This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-30
Channels
- # announcements (15)
- # beginners (143)
- # boot (2)
- # calva (48)
- # cider (93)
- # cljsrn (2)
- # clojure (127)
- # clojure-europe (3)
- # clojure-italy (8)
- # clojure-losangeles (8)
- # clojure-nl (10)
- # clojure-spec (67)
- # clojure-uk (51)
- # clojurescript (20)
- # cursive (9)
- # data-science (2)
- # datomic (10)
- # duct (13)
- # figwheel-main (1)
- # fulcro (74)
- # instaparse (10)
- # jobs (3)
- # joker (8)
- # juxt (4)
- # lumo (1)
- # malli (11)
- # nrepl (3)
- # off-topic (4)
- # pathom (5)
- # pedestal (6)
- # planck (5)
- # re-frame (18)
- # reagent (5)
- # reitit (17)
- # shadow-cljs (165)
- # sql (30)
- # vim (12)
- # xtdb (6)
@vikeri a while back we talked about one of the things you liked about your cljsrn setup. I think it was reagent.core/track but I'm not 100% sure. I'm looking at ways to trigger dispatching (to load data) when app state changes. Here's what I came up with as a r/trigger based approach. Is that the sort of thing you were talking about?
(defn load-species-args [db]
(let [region-pk (get-in db [:spot/state :region :pk])
category-id (get-in db [:spot/state :category :id])]
(when (and region-pk category-id)
[region-pk category-id])))
(reg-event-fx
:app/load-species
(fn [_ [_ args]]
{:sqlite/execute-sql {:query (str " SELECT * FROM SPECIES WHERE REGION_ID=? AND CATEGORY_ID=? ORDER BY COMMON_NAME")
:args args
:resp-v [:app/load-species.resp]}}))
(def *load-species-args
(r/track #(load-species-args @re-frame.db/app-db)))
(def *load-species-args-dispatch
(r/track! #(when-let [args @*load-species-args]
(rf/dispatch [:app/load-species args]))))
The value here being that the dispatch happens no matter how the associated state is updated - as my UI gets more interesting I'm not left trying to find all the possible event handlers which might need to dispatch.