Fork me on GitHub

I've an app that needs to make a websocket connection for fetching data. I'm using re-frame-async-flow-fx with great success to orchestrate my initial app boot. Reitit is my router. Now, I have to handle cold-start on nested routes like /app/a-thing/1/a/nested/thing/42. The reitit controller functions dispatch "get my data" events when the route is loaded, but this happens in parallel to the boot flow, so often the boot isn't complete by the time the controller event fires, resulting in a failure to get data. Any tips on how to resolve this?


For now I've been re-queuing the controller event in the failure handler with dispatch-later 😕


Make reitit start the boot flow?


Hmm, but then the boot flow would be triggered by the user just navigating in the app even in non-cold start scenarios


You can use a flag of sorts to check if it's a cold start or not.


Also I can't miss this opportunity to mention kee-frame. :) Maybe it'll be useful to you as well.


A first-boot flag would work I suppose, but the more I think about it I think this can be solved by solving the general case of retry-handling when the ws connection fails. I'm using sente, so auto reconnecting is built in, but when events fail due to a bad socket, I need a way to retry them once th connection is back up. Hm but you probably don't want to retry every request.

Grant Isom15:08:32

On a page refresh I am losing certain items from the app-db causing my page to blow up, are there any best practices around persisting things? I am also confused why somethings stick around and others vanish.


Nothing should stick around in app-db by itself. Something somehow loads that data into app-db from somewhere. With that being said, the usual place to persist things client-side is Local Storage.

Grant Isom15:08:03

Essentially I have a list of tasks, when you select a task it opens a page that is subscribed to a task object in the app-db and the event sets the selected task to that. If I want refresh to not, blow up should I also be putting the task into local storage as well so if it is not already in app-db, I can pull it in?


If you're writing an SPA, why do you refresh the page? Why not just load data via XHR/WebSocket and use it while also updating the URL in the browser address bar?

Grant Isom16:08:48

That is what I am doing, but during development I am refreshing the page to see my changes and was wondering what to do if the user refreshes the page during some workflow?


> I am refreshing the page to see my changes You should change your development setup so that the page is re-rendered (not refreshed!) automatically when you make a change. Figwheel and Shadow-cljs support this. > was wondering what to do if the user refreshes the page during some workflow It depends on the workflow. Take what you want to achieve, find a conceptually similar platform that's used by actual users, and see what they've done. For example, GMail doesn't save anything but drafts. So a draft is part of its persistent state, but e.g. current email filter or even current app section (like inbox or settings) are not.

Grant Isom16:08:38

Okay sweet, will check that out and sounds good will think that through! Thanks!


NP, good luck.