How to use one-way binding


#1

I know it will eventually become the default, but until that happens, I think we need a transitional. I’m writing a lot of new code now and it’s hard to avoid two-way bindings since I can’t really opt-out of it.

A workaround that I started using is to define two properties, one for the public interface and one for internal use. The internal use is a one way binding to the external, while the external one is still using two-way binding. Internally I’ll never set the external one, which means I don’t have to worry about the two-way binding part. I’m just curious if you have better suggestions or your opinion about this hack/workaround.

From the consumer:

{{x-component value=propertyFromController}}

In my x-component

internalValue: Ember.Binding.oneWay('value');

#2

You can do one-way binding, but it is a little bit of a pain.

For example, one way binding in a component (we’ll call it x-bar):

components/x-bar.js:

Ember.Component.extend({
  fooValue: null,
  fooBinding: Ember.Binding.oneWay('fooValue')
});
  {{x-bar fooValue=someObject}}

Now inside x-bar use of the property foo will be bound one way.


#3

Nevermind, didn’t read your whole post. Yeah, the workaround sucks :frowning:. Would be nice to have easy one-way binding right now.


#4

I was trying to find the difference :slight_smile:


#5

Here’s another workaround