Few.swift – React-Inspired Library for Writing AppKit/UIKit UIs
github.com
github.com
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];
}
}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. 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.
Why we'd we introduce even more basic manual variable change propagation?