|
|
|
|
|
by zoul
2689 days ago
|
|
…but it is the same State -> View logic. It’s not. I am familiar with Cocoa. When the model updates, the controller or the view notice and manually update the view state to match – update text fields, change colors, push new views, etc. This way the correspondence between model state and view state is hardwired into imperative, mutating code: func updateView(model: Model) {
if (model.updating) {
statusLabel.text = "Updating…"
}
}
In React-like architectures, the view state is never mutated from the programmer’s perspective. The programmer just writes a function that takes the model state and produces the view state: func buildView(model: Model) -> View {
return Label(text: model.updating ? "Updating" : "Idle")
}
So the correspondence between the model state and the view state is declarative, pure code. That’s a huge conceptual difference, because it makes the result much more convenient, error-resistant and testable. |
|
You might want to check out Model View Controller, with things like drawRect:: and "setNeedsDisplay" or "setNeedsDisplayInRect:"
Widgets and Massive View Controller are built on top of the MVC framework, and can be more convenient in cases. However, that doesn't mean the underlying MVC framework has disappeared.
UPDATE: And yes, the terminological confusion is awful.
Concept Shadowing and Capture in MVC and its Successors
https://blog.metaobject.com/2017/03/concept-shadowing-and-ca...
Model Widget Controller (MWC) aka: Apple "MVC" is not MVC
https://blog.metaobject.com/2015/04/model-widget-controller-...