4 ms·
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 e
by danabramov 12y ago
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.
[1]: http://facebook.github.io/react/docs/two-way-binding-helpers.html http://facebook.github.io/react/docs/two-way-binding-helpers...
- jdmichal 12y agoI 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.
- AdamCraven 12y agoWhat you are linking to is still two-way data binding. Which enforces a one-way flow of data. 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. } }