Does the `binding` required, or API can be updated to only use `link` and `unlink`?
Current API design has few helpers for binding in different ways, and then element has link method. So Label to data currently is:
const label = new Label({
binding: new BindingObserverToElement()
});
label.link(data, 'text');
And for bi-directional:
const textInput = new TextInput({
binding: new BindingTwoWay()
});
textInput.link(data, 'text');
Question:
Is this is necessary to provide classes for binding?
Proposal:
Here is example of how it could simplify for users the data binding:
For read-only data:
const label = new Label();
label.link(data, 'text', { write: false });
For bi-directional (by default):
const textInput = new TextInput();
textInput.link(data, 'text');
For write only:
const textInput = new TextInput();
textInput.link(data, 'text', { read: false });
In JSX it will be:
<TextInput link={ data, path: 'text' } />
And to link attribute read and/or write property can be provided:
<TextInput link={ data, path: 'text', read: false } />
The default behavior is that a binding has to be provided. There are not many places in the Editor where we have to repeatedly create bindings as most UIs are data driven and then use a generic inspector to create a default binding.
Some design decisions for this framework are to be verbose and explicit without a lot of assumptions. If we haven't already we might want to expose the attribute inspector control as well which makes creating inspectors just a matter of defining a simple json schema
Moreover the binding class has various properties as well like defining history related behavior, combining behavior etc. we also sometimes create new bindings as subclasses to perform more quirky or complicated tasks.
So while we could add some shortcuts we'd eventually have to expose all of the binding properties as arguments to the link function which would lead to more than one ways of doing something.
Did I mention we wanted one way to do something instead of multiple ways to do the same thing? 😄