{"id":23825,"date":"2019-01-01T15:41:24","date_gmt":"2019-01-01T20:41:24","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=23825"},"modified":"2019-01-01T15:42:44","modified_gmt":"2019-01-01T20:42:44","slug":"react-js-and-cocoa-side-by-side","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2019\/01\/01\/react-js-and-cocoa-side-by-side\/","title":{"rendered":"React.js and Cocoa Side by Side"},"content":{"rendered":"<p><a href=\"https:\/\/blog.metaobject.com\/2018\/12\/uis-are-not-pure-functions-of-model.html\">Marcel Weiher<\/a>:<\/p>\n<blockquote cite=\"https:\/\/blog.metaobject.com\/2018\/12\/uis-are-not-pure-functions-of-model.html\"><p>Fortunately, the React.js team was so kind as to put their basic ideas in writing:  <a href=\"https:\/\/github.com\/reactjs\/react-basic\">React - Basic Theoretical Concepts<\/a> (also <a href=\"https:\/\/news.ycombinator.com\/item?id=16769193\">discussed<\/a> 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.<\/p><p>[&#8230;]<\/p><p>[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&rsquo;t have to reexecute it if we keep using the same value.<\/p><p>[Cocoa:] First, we did not start with the obviously incorrect premise that the UI is a \nsimple &ldquo;pure&rdquo; function of the model.  Except for games, UIs are actually very\nstable, more stable than the model.  You have chrome, viewers, tools etc.  What <em>is<\/em> a (somewhat) pure mapping from the model is the data that is displayed <em>in<\/em> the UI,\nbut not the entire UI.<\/p><p>So if we don&rsquo;t make the incorrect assumption that UIs are unstable (pure functions of model), then we don&rsquo;t have to expend additional and fragile effort to re-create that necessary stability.<\/p><p>[&#8230;]<\/p><p>Last not least, it&rsquo;s probably not entirely coincidental that this idea was <a href=\"https:\/\/en.wikipedia.org\/wiki\/React_(JavaScript_library)#History\">hatched<\/a> for Facebook and Instagram feed applications.  Similar to games,\nthese sorts of apps have displays that really <em>are<\/em> determined mostly by their &ldquo;model&rdquo;, the stream of data\ncoming from their feed.  I am not convinced that <em>feed application<\/em> generalizes well to <em>application<\/em>.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2019-01-01T20:41:26Z","apple_news_api_id":"a1bb8a12-6def-4434-848d-4d68200b0fd2","apple_news_api_modified_at":"2019-01-01T20:42:47Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/AobuKEm3vRDSEjU1oIAsP0g","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[69,31,1610,346,30,1609,374,71,1249],"class_list":["post-23825","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-ios","tag-ios-12","tag-javascript","tag-mac","tag-macos-10-14","tag-mvc","tag-programming","tag-react-native"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/23825","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=23825"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/23825\/revisions"}],"predecessor-version":[{"id":23826,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/23825\/revisions\/23826"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=23825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=23825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=23825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}