
Few.swift – React-Inspired Library for Writing AppKit/UIKit UIs - dgellow
https://github.com/joshaber/Few.swift
======
21echoes
> Few.swift lets us express UIs as stateless, composable, immutable-ish values
> of their state. When their state changes, Few.swift calls a function to
> render the UI for that state, and then intelligently applies any changes.

arent most Objective-C and Swift views written like this already?

in the .h:

    
    
        @property Klass *model;
    
    

in the .m:

    
    
        - (void)setModel:(Klass *)model {
          if (![model isEqual:_model) {
            _model = model;
            // ... stuff like self.text = model.value ...;
            [self setNeedsLayout];
          }
        }

------
EGreg
I like the proliferation of ideas around React and the various new attempts at
cool stuff.

Question, though: why is the idea of glorified two-way bindings with dirty-
checking constantly popping up? It may make your code slightly prettier, but
at the expense of efficiency. Instead, what's wrong with this:

    
    
      component.state.x = 5;
      component.state.y = "blah";
      component.stateChanged("x","y");
    

And in the view:

    
    
      component.onStateChanged("x").set(function() {
        component.someExactElement.innerHTML = x; // or whatever
      });
    

No need to do dirty checking, and it's explicitly clear what the bindings do.

~~~
Someone
Because it automates away bookkeeping. Consider

    
    
      component.state.x = 5;
      component.state.y = "blah";
      component.state.z = "bug!";
      component.stateChanged("x","y");
    

That one line addition should have included a change to the last line.

Also, I don't know whether it is done, but with a relatively slow/relatively
large overhead network between the bound objects, software can bunch up the
synchronization of changes to independent objects.

------
zserge
If one is looking for something similar for Android - you might like Anvil:
[https://github.com/zserge/anvil](https://github.com/zserge/anvil)

