▲ 29 points
back
7 comments
> 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];
}
}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.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.
At least in JavaFX/XAML models you can do some clever bindings between components without writing a single line of code, besides the ones to create the components that is.
QML (part of Qt) did this right. Unfortunately, it did a bunch of other shit wrong. In particular, if you could just apply the QML object model to the web, you'd get nicer code.
Because we moved away from manual memory management.
Why we'd we introduce even more basic manual variable change propagation?
If one is looking for something similar for Android - you might like Anvil: https://github.com/zserge/anvil