|
|
|
|
|
by rk06
3423 days ago
|
|
There are two types of two-way binding. 1. Bad Two Binding i.e. Two way binding between components. Vue2 and most of the UI frameworks shun this. 2. Good two way binding i.e. Form model binding.
Because form input can actually come from two sources (user input and javascript). this is naturally two-way and this is why frameworks continue to keep it. |
|
As an example, let's say you have a formatted text input field that can be used to enter a decimal number. If the input contains no decimal separator, the decimal part is implicitly zero. But if you just use naive two-way binding with an actual decimal value this means you'll get in the way of the user trying to manually enter a decimal value (especially if the user tries to delete the decimal part starting with the separator).
As soon as any information is lost during the bind in either direction, you still need to explicitly think about where you want the data to flow into and out of the form field.
The archetypical example of two-way binding is definitely the auto-generated CRUD form that lets you edit a model in place, but IMO this is a tiny niche in practice because it falls apart as soon as you want to do anything non-trivial. It's great for prototypes though.
EDIT: To clarify, I think you're talking about two-way binding a form model to form inputs. But calling that two-way binding from an application developer's POV is kinda redundant because you still need changes from the form model to propagate outside the form in a more controllable and predictable way than two-way binding offers, so the two-way binding of the actual form fields becomes an implementation detail.