Note that there are some explanatory texts on larger screens.

plurals
  1. POTemporarily breaking/pausing an Ember.Binding
    text
    copied!<p>I'm trying to figure out how to write <code>pauseBinding()</code> and <code>resumeBinding()</code>, so that I can interrupt bindings between application layers, e.g. if a validation fails on user input into an Ember.TextField.</p> <pre><code>var source = Ember.Object.create({ value: 10 }); var target = Ember.Object.extend({ source: source, valueBinding: 'source.value' }); console.log(source.get('value'), target.get('value')); // 10, 10 target.set('value', 20); console.log(source.get('value'), target.get('value')); // 20, 20 // Stop synchronizing between target.value and source.value pauseBinding(target.get('valueBinding')); // Only update target.value target.set('value', 40); console.log(source.get('value'), target.get('value')); // 20, 40 // Resume synchronizing, target.value is overwritten resumeBinding(target.get('valueBinding')); console.log(source.get('value'), target.get('value')); // 20, 20 </code></pre> <p>Or, asking this more generally: <strong>what is the most proper idiom for creating conditional bindings</strong>, bindings that flow only-one-way, only-the-other-one-way, both-ways, or no-ways depending on a condition (another property) ?</p> <p>A condition might be a validation (if validation fails, don't spread the invalid value further), or a condition might be in response to UI state such as focus (if the control is focused, don't programmatically update its value, as this will confuse the UI).</p> <p>For example, when an Ember.TextField with a valueBinding is focused (as in, active user input), I don't want it being updated, even if the to() side of the binding updates. But this seems like a oneWay() binding that's the <em>opposite</em> direction (oneWay from -> to, instead of oneWay to -> from).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload