4 ms·
Help me out here. So state management refers to frontend tools like Redux and Vuex, and it sort of represents the "backend of the frontend" in that it defines c
by john-radio 7y ago
Help me out here. So state management refers to frontend tools like Redux and Vuex, and it sort of represents the "backend of the frontend" in that it defines constructs and their behaviors for the frontend to manipulate. Is that a correct understanding? If so then doesn't it result in some bad code duplication between e.g. the Redux layer and the Django models?
- zelly 7y agoYes, that's why a lot of people who do SPAs also run node as the backend so that business logic code can be shared. If you have an e.g. C++ backend, you will have to rewrite your models in JavaScript and keep them in sync. It makes your website have the same development tedium as a mobile app but without any of the prestige or profit potential. Avoid SPAs at all costs. More companies are starting to ditch them and only have websites as advertisements for the native mobile app (CashApp and Venmo off the top of my head).
- mikewhy 7y agoYou deal with the same model interfaces, just as you would in any client / server pattern. But that's usually the extent of it.
- draw_down 7y agoI think it's best to either have some sort of codegen that creates the frontend types from the server-side types, or work in the same language so they can be shared. You're right that that sort of duplication is a risk, it should be addressed with tooling (or, again, doing everything in JS). As with everything else, there should be a single source of truth.
- williamdclt 7y agoThat's pretty much it. The Redux store is a database (up to you to keep it normalized), things like selectors and actions are akeen to controllers (one just reads data, the other just writes). You do have some "concept duplication", more than code duplication. Indeed you'll have to define your interfaces twice (Django models and Typescript definitions for example), but that's always the case if you consume an API (you always hope that what you expect from an API is what is received).
- chrisco255 7y agoNot sure what you mean by "bad code duplication"? If you have a need for a rich front end application you're going to need to implement some state management on the front end. The back end is responsible for running APIs, managing services, interacting with the database, and performing validation on API calls. A good REST API is typically stateless. But a front end can't be stateless. Let's take Facebook for example. The front end needs to track which conversations are open, which users in your friend list are "active" or "away" and render the appropriate icon, threads of conversations need to be woven together on various panes on the screen, visual feedback about whether a post has already been "liked" by the current user needs to be provided, etc. It needs to be able to receive real-time updates and post those to the UI in the proper location. There's a ton of complexity there and you have to place that state in memory on the client somewhere. Managing front end state effectively is crucial for complex applications.