Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does the binding required, or API can be updated to only use link and unlink? #28

Open
Maksims opened this issue Oct 21, 2020 · 2 comments

Comments

@Maksims
Copy link
Collaborator

Maksims commented Oct 21, 2020

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 } />
@vkalpias
Copy link
Collaborator

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

@vkalpias
Copy link
Collaborator

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? 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants