4 ms·
I'm not computer theorist. But to me React seems like a perfect implementation of MVC. Model is state. View is virtual-dom chunks. And controller is an actual f
by vbezhenar 4y ago
I'm not computer theorist. But to me React seems like a perfect implementation of MVC. Model is state. View is virtual-dom chunks. And controller is an actual function implementation which maps state to view.
- deleted 4y ago[deleted]
- elanning 4y agoThis is typically a good way to organize React projects, in my experience. A few top-level components which hold state with a useReducer and have a few functions to make backend calls, as needed. You could consider the reducer the model and the top-level component the controller. All components that sit below the top-level are pure view components. Props in, view out. They at most hold a minor amount of UI state. They don’t make API calls or update state themselves, that must be done with a callback to the top-level component. This makes testing simple as you can test the reducer without rendering any UI. The pure view components are also easy to test. Then a few end to end tests to tie everything together. https://www.reactguide.dev/#mc-v-trees https://www.reactguide.dev/#mc-v-trees Has more info on how to scale the pattern for larger apps.
- phailhaus 4y agoReact is an implementation of the Flux architecture model, which is different from MVC. [1] [1] http://fluxxor.com/what-is-flux.html http://fluxxor.com/what-is-flux.html
- mpweiher 4y agoInterestingly, most of what they claim about MVC is false, and the problems they see with what they call MVC are mostly solved by following actual MVC, others by specific implementations of MVC. I had only seen these misunderstandings in talks (particularly the "cascading", which true MVC absolutely prevents), which are difficult to refer to, so thanks for the link! As I wrote elsewhere[1] : "having to say "the problems of MVC are solved by MVC" is less than ideal, because, well, you sound a bit like a lunatic." [1] https://blog.metaobject.com/2017/03/concept-shadowing-and-capture-in-mvc.html https://blog.metaobject.com/2017/03/concept-shadowing-and-ca...
- wruza 4y agoThis is what bugs me most about these talks. I don’t mind when some guys do something their way, unique or not. But when they spread fucking lies about prior tech to very large auditories, it makes me think about either a conspiracy or their complete lack of competence in this area.
- Marazan 4y agoI've yet to find two proponents of "true" MVC who can agree what goes in the model and what goes in the controller.
- mpweiher 4y ago1. https://folk.universitetetioslo.no/trygver/themes/mvc/mvc-index.html https://folk.universitetetioslo.no/trygver/themes/mvc/mvc-in... 2. Controllers, like views and model(s) are roles, not components. These roles can be filled by the same objects. 3. So people not agreeing where things go is perfectly compatible with MVC, and thinking that's a problem is a symptom of not understanding MVC. 4. I personally try to put as much as possible (and a bit more) into the model. Hexagonal for the win! Naked objects are also pretty nice, though I tend not to be quite that radical. ¯\_(ツ)_/¯
- Marazan 4y agoIf the M the V and the C are roles with not fixed functionality or purpose (given that you apparently can put anything you want in them) then what _is_ MVC?
- mpweiher 4y agoThe roles are distinct and have fixed functionality and purpose. They just don't have to correspond to specific and distinct components. This is all explained in detail in the documentation, which is really helpful for understanding MVC.
- FinalBriefing 4y agoYes, and no. Implementing MVC patterns in React requires developers to architect it that way.