Hacker News new | past | comments | ask | show | jobs | submit login

This misses the point completely. I would love Cocoa to work the way React does, but it doesn’t. At all. The main point of React is not having to manually manage view updates. You just write a pure fuction from app state to view (State → Html) and the runtime figures out how to update the existing views to match. That way you can completely forget that the view has some state, you just manage the app state and provide a bunch of pure functions that map various state fragments to views.



React surely has higher level widgets than Win32 (and Cocoa, and TK, and all those decades old stuff), but it is the same State -> View logic. The desktop widgets that are still getting updated, like QT, have widgets with roughly the same level of abstraction as the web frameworks.


…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.


That's Massive View Controller pattern with widgets.

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-...


I’m sorry, but the terminology around MVC is completely broken, to the point where it’s completely non-obvious what people mean by MVC. So I don’t understand what you mean.


Here's how it's done with qt :

    Label { 
       text: model.updating ? "Updating" : "Idle"
    }
it's not implemented on top of JS but is a proper declarative DSL for reactive programming


>React surely has higher level widgets than Win32 (and Cocoa, and TK, and all those decades old stuff),

Higher level, but much lower quality -- the feature set of GUI widgets as offered by desktop SDKs is unmatched in the HTML/DOM world. It's like actual objects vs play-doh.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: