News for hackers. Stuff that matters.

vanvoorden

One of the legacies of bringing IG to FB was ReactJS.

Prior to the IG acquisition ReactJS was used internally across product surfaces inside the FB apps… but was not an open source library. IG was acquired as a mobile app but did not ship a first-class WWW product for browsing posts and profiles. I believe it might have been Pete Hunt that wanted to build the IG WWW product surface on ReactJS. This meant decoupling ReactJS from hardcoded dependencies and assumptions that were specific to the FB products.

Once ReactJS was decoupled from those FB specific details it was ready to ship as a legit standalone infra in 2013.

Would ReactJS have shipped as standalone infra without IG? Maybe… eventually. The FB philosophy in those days was generally not to build infra just for the sake of building infra. Infra was supposed to solve for real-world problems and measurable product impact. If the only front-end products inside FB were on FB and there was no impact to be earned from decoupling those dependencies… it's possible that engineers might not have been incentivized to ship it open source as soon as they did.

Re:Flux, Redux, and SwiftUI on Wednesday March 19, 2025 @02:53PM (#43415949)
This is the first chapter of our "ImmutableData Programming Guide" book for product engineers building SwiftUI apps. Over the course of our Programming Guide we build an infra and multiple sample application products demonstrating how the ideas and philosophies from Flux and Redux can be built for product engineers building on Swift and SwiftUI.

The first chapter is mostly "conceptual". Before we write some code we discuss the history and evolution of two ecosystems: React and SwiftUI. We discuss how the React ecosystem shipped Flux (and later Redux) as the dominant choice for a unidirectional data flow and why migrating away from MVC style patterns led to code that was easier to reason about and easier to maintain.

Many engineers in the SwiftUI community are evangelizing one of the "flavors" of an MVC style pattern: MVVM or MV. The ImmutableData Programming Guide brings the ideas and philosophies from Flux and Redux to defend against the problems from trying to scale MVVM to large teams and large products.

The ImmutableData Programming Guide and the ImmutableData repos are free and open source. There is no subscription and no paywall. The code and documentation is free. The sample application products are free.

Re:MVVM in SwiftUI for a Better Architecture on Wednesday March 19, 2025 @02:28PM (#43415632)
> I believe Redux-like architectural patterns […] are a terrible choice. They impose functional programming paradigms onto a language and a framework that are not functional but heavily reliant on imperative code and state.

Ehh… Redux shipped on JS… which was less functional than Swift is. Redux state ships on JS objects and has to work around mutable JS collection objects to preserve "immutable" value semantics. And after all that trouble it was still a better choice for managing global mutable state.

First class value types and immutable semantics in Swift make the language a solid choice for a Redux style architecture.

> The primary issue with this approach is that it concentrates the entire application state within a single monolithic structure, resulting in tightly coupled code.

Ehh… not really. One big goal of Flux and Redux was to decouple state from views. Because transformations on state are dispatched using declarative action values on user events views no longer need to know the structure and organization of state to perform imperative logic.

> Moreover, any change to the data in such a structure can trigger view updates across the entire view hierarchy, even in views unrelated to the updated state components.

This is just an implementation detail and an optimization to ship. A "hello world" Redux style SwiftUI application might lead to everything recomputing `body`. A production quality Redux solution for SwiftUI would probably leverage Selectors to "scope" slices of state similar to ReduxJS. That would mean that view components then only listen for updates from their slice… not the complete state tree.

The Redux community shipped this optimization almost ten years ago… there's nothing stopping engineers in the Swift community from shipping a Redux solution with a similar optimization.

> Another problem arises from reducers, which introduce substantial boilerplate code typically implemented using numerous Swift switches. This code blatantly violates the Open-closed principle.

Ehh… I'm not sure I see why structuring state transformations as pure functions is a net negative. Go ahead and critique the idea of pure function state reducers… but then we also go back and discuss the critiques for the idea of modeling state as mutable object references. It's a tradeoff… and engineers that ship Redux in their products see why this is the correct tradeoff for them.