What is two-way binding to a method? Can you give me an example? I can only think of this[1] but despite being similar to two-way binding, this is one-way and explicit.
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 believe the intention is basically "bind to a setter method, not a field." I'm guessing for much the same reasons the same is used in Java: You can change methods. You can add sanity checks, new behavior, etc.
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: