4 ms·
> A well done CRUD app should be pretty simple Should it? I'm currently building a "simple" CRUD app as a side-project. My background is in game development a
by golergka 5y ago
> A well done CRUD app should be pretty simple
Should it?
I'm currently building a "simple" CRUD app as a side-project. My background is in game development and backend, and I decided to learn React and React Native in the process. But at one point I realised that I want to app to be functional while the user doesn't have internet and sync afterwards, and now I'm in hell.
Now, I have to make all post requests idempotent, cache them on the client in case there's no internet, serialise and deserialise this cache when app quits and turns back on, display optimistic updates on the client as well but at the same time make it transparent in UI that those updates were not yet synced on the server, and handle request queue in such a way that when I send two requests that modify the same client-server object response to the first request that comes after optimistic update from second request doesn't override it, but a failure of one of the requests cancels all subsequent ones. I think I just got a headache writing that sentence. I also need invalidate local client cache of different server objects based on what mutation did I attempt to do and what result did I get from the server — when you create an object of some kind, different collections of these objects are invalid now, some can be updated optimistically, some need to be refetched. And I also need to invalidate these caches based on different kinds of errors returned from the server: authorisation, authentication, network problems, invalid user input and unknown problems that probably signify errors in my code all need to be handled differently.
May be I'm missing something, but implementing all of that functionality properly still seems like an unsolved problem out of the box. I've already prototyped solutions using useSWR, React Query and Redux, and I'm still not satisfied, as not of all these cases are handled properly. However, now I understand why so many web and mobile apps have so many bugs: based on the state of the tools and libraries, it seems that most developers simply don't care for all these cases and mostly stay on the happy path, cutting their workload by the factor of 10.
- barbarbar 5y agoKeep state on the server. Start with zero javascript.
- golergka 5y agoAnd how would my app work without internet, I that case?
- icedchai 5y agoWhy exactly are you worrying about this case? Start with a simple server-side rendered forms-based web app.
- golergka 5y agoBecause it's a very basic requirement for a mobile app.
- barbarbar 5y agoThen maybe it is a PWA that you are looking for. But this fine site we are using now works 100% without javascript. And it is fast.
- ContentSP321 5y agoThe "P" in Progressive Web App: https://infrequently.org/2015/06/progressive-apps-escaping-tabs-without-losing-our-soul/ https://infrequently.org/2015/06/progressive-apps-escaping-t... Reminds me of the "P" in Progressive Enhancement: https://blog.tomayac.com/2020/01/23/progressive-enhancement-in-the-age-of-fugu-apis/ https://blog.tomayac.com/2020/01/23/progressive-enhancement-... There are many valid reasons to support the full "PWA experience" and have fallbacks that works without JavaScript, and it is attainable. I have personally built PWAs that work offline with JavaScript enabled, as well as with a network connection without JavaScript enabled. It might be better to think of a PWA as a regular high performant "mobile first web application" that took the right vitamins. ;-) The vitamins in this case are usage of service workers and a "Web app manifest." From my perspective, the "Offline First" + "Mobile First" approaches have produced the most progressively enhanced web applications that I've even seen.
- icedchai 5y ago
- collyw 5y agoWell you have automatically gone for a SPA app architecture, without giving any reason why. Looks like your problem is practising resume driven development. CRUD apps do not require SPA architecture. Have a look at the Django tutorial, and see what you can produce with the Admin interface. It is a while lot less pain that what you are doing just now.