Tuesday, January 1, 2019 [Tweets] [Favorites]

React.js and Cocoa Side by Side

Marcel Weiher:

Fortunately, the React.js team was so kind as to put their basic ideas in writing: React - Basic Theoretical Concepts (also discussed on HN). So I had a look and after a bit of reading decided it would be useful to do a side-by-side comparison with equivalents of those concepts in Cocoa as far as I understand them.

[…]

[React:] Calling the same function over and over again is wasteful if we know that the function is pure. We can create a memoized version of a function that keeps track of the last argument and last result. That way we don’t have to reexecute it if we keep using the same value.

[Cocoa:] First, we did not start with the obviously incorrect premise that the UI is a simple “pure” function of the model. Except for games, UIs are actually very stable, more stable than the model. You have chrome, viewers, tools etc. What is a (somewhat) pure mapping from the model is the data that is displayed in the UI, but not the entire UI.

So if we don’t make the incorrect assumption that UIs are unstable (pure functions of model), then we don’t have to expend additional and fragile effort to re-create that necessary stability.

[…]

Last not least, it’s probably not entirely coincidental that this idea was hatched for Facebook and Instagram feed applications. Similar to games, these sorts of apps have displays that really are determined mostly by their “model”, the stream of data coming from their feed. I am not convinced that feed application generalizes well to application.

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment