by AdamCraven · 11y ago · 0 comments
Two-way data binding to properties is generally not good. It increases likelihood of problems as updates to one value have to be observed to adjust other values. It is easy for bugs to slip in and hard to reason about the code.
Two-way data binding to methods is better. Methods that aren't focused on setting one value. In effect not direct data binding. It creates easy to reason about explicit code paths for changing of values. Observation of the change of properties is no longer required.
It is a useful tool and should continue to be seen as such.
[1]: http://facebook.github.io/react/docs/two-way-binding-helpers...
Two-way binding: Read & Write. Read & Write happens through getter/setter methods.
One-way binding: Read only. Writes happen by external event listeners.
Both can be used to enforce one way flow of data. Just as one way binding can be used to have a uni-directional flow of data.
A pseudo code example with two-way data binding with one-way flow of data:
<input type="text" value=getOrSetValue() />
function getOrSetValue(newValue) {
if (newValue) {
// Send an event to a dispatcher with updated value.
} else {
return value // can be single value from model or derived value, such as calculation of multiple values.
}
}I don't even know how the second option is better to be honest. I may research it further.
:-)