This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-03
Channels
- # announcements (1)
- # babashka (31)
- # babashka-sci-dev (53)
- # beginners (34)
- # calva (54)
- # cider (15)
- # clj-kondo (9)
- # clojure (115)
- # clojure-dev (19)
- # clojure-europe (21)
- # clojure-nl (1)
- # clojure-norway (78)
- # clojurescript (10)
- # clr (9)
- # community-development (9)
- # core-async (24)
- # cursive (18)
- # datomic (59)
- # emacs (43)
- # figwheel-main (2)
- # fulcro (4)
- # graphql (4)
- # malli (7)
- # meander (12)
- # nbb (14)
- # off-topic (22)
- # polylith (9)
- # re-frame (5)
- # reitit (3)
- # releases (1)
- # shadow-cljs (36)
- # sql (1)
- # tools-build (23)
- # xtdb (13)
What would be a good way to make pages load data from an API when a user navigates to it? I’ve briefly experimented with using Reitit’s controllers but I’ve found it difficult discarding cached data when routes exit, especially if several pages can share the same data. I’ve considered parametrizing my subscriptions so that every page uses “independent” data, but I’m afraid that’d put me in a bigger mess than what I’ve tried before
So using reitit controllers is fine? Do you create special events for the page or just emit events that make API calls?
Originally I tried making controllers that’d dispatch api events (which on success populate the app-db). But I’m not sure of a good way to “clean up” the app-db once the user exits the route.
For an example of the kind of state changes I am dealing with, say a user edits a form in /forms/:id/details
. This route makes an API call to fetch some details of the form with specified id
. But the /forms
route itself makes an API call to fetch some data on all the forms a user has. What I’ve found tricky is being able to invalidate the cached API response in /forms
so that the user can edit things in /form/:id/details
and see their changes when browsing back to /forms
I don't know about reitit, I don't use it.
I create an event per intent.
> clean up the app-db
kee-frame has controllers that have a :stop
method - that's exactly what I'm using for any cleanup that I might need.
I see. I took a quick look at kee-frame’s controllers and they seem close enough in functionality to what reitit’s controllers offer. For now I’m experimenting with dispatching a ::page/set-up
and ::page/tear-down
event with reitit’s controllers. The tricks I saw on https://ingesolvoll.github.io/posts/2018-06-18-kee-frame-controller-tricks/ also apply to reitit controllers.
I don’t know how easy it’d be to retrofit kee-frame into an existing re-frame app that’s already invested heavily in reitit and driving most of the app state with URLs… maybe it’s something I can do in the future though. 😄