logoalt Hacker News

mpweiherlast Sunday at 9:08 PM5 repliesview on HN

Not if you actually do MVC, so solved around 50 years ago.

1. The UI tells the model to change.

2. The model does the change and possible related changes.

3. The model notifies the UI that something has changed.

4. The UI updates itself from the model.

Alas almost nobody does MVC, despite calling what they do MVC.


Replies

kikimorayesterday at 4:55 AM

MVC is not bad, but it is not a silver bullet. Calling MVC an ultimate solution to UI is oversimplification. Just looking at the steps you listed I can ask:

How do you collect all notifications on step 2 to fire them on step 3 such that UI does not re-render itself too much? E.g. updating a title of each item in a list of 100 items should not trigger 100 renders. Or 100 layout calculations (which I think is harder to avoid).

How do you deal with situations where on step 4 UI triggers an event that your model happens to listen and the cycle repeats while killing performance?

Because you rely on events how do you avoid “event hell”? That is, a situation when an event handler triggers a change that triggers another event handler that triggers a change and so on. Sometimes it is scrolling or typing, sometimes it is parts of the model subscribed to each other bubbling events to UI.

show 2 replies
wk_endyesterday at 3:53 AM

I see an M and a V in this description, but no C.

Is the UI updating itself automatic or manual? Because if it’s manual, that’s precisely the error-prone part that you’re saying this approach somehow solves - you’ve done the “How to Draw an Owl” meme. If it’s automatic, that doesn’t seem especially different from the React/Redux/Elm/SwiftUI approach (as a sibling points out).

show 1 reply
asa400yesterday at 3:36 AM

Funny, this almost reads like a description of how Elm works.

show 1 reply
LoganDarkyesterday at 3:25 AM

Are you saying the UI always updates its entire self whenever anything changes in the model?

show 1 reply
ardit33yesterday at 7:01 AM

Dude, you didn't describe MVC at all, but MMVC.

MVC, the controller is the intermediary between the services/data models, and the views. That still one of the best / simplest way to build large apps. MMVC is just a variation of it, with the models being able to communicate state to views and bypass controller if needed.

MVC, is still one of those 'fundemental as simple as it gets, and it gets the job done' patterns.

show 1 reply