computed.alias gets optional readOnly flag #2284

Merged
merged 1 commit into from Mar 16, 2013

2 participants

@stefanpenner
Ember.js member

Aliasing properties is powerful, to some peoples
surprise they alias in both direction (set and get).
Usually this is the behaviour one wants but sometimes,
as emberjs/data@7b88a92 suggests, this behaviour
is not always wanted.

When the read only flag is flipped on, a set will
throw and Error. Preventing the set, and providing
useful feedback.

@stefanpenner stefanpenner Added readOnly flag to computed.alias.
Aliasing properties is powerful, to some peoples
surprise they alias in both direction (set and get).
Usually this is the behaviour one wants but sometimes,
as
emberjs/data@7b88a92
suggests, this behaviour
is not always wanted.

When the read only flag is flipped on, a set will
throw and Error. Preventing the set, and providing
useful feedback.
bb5d588
@stefanpenner stefanpenner merged commit 202718d into emberjs:master Mar 16, 2013

1 check passed

Details default The Travis build passed
@endash

I've been wanting readOnly on normal computed properties for quite a while and started thinking about it again when I saw a commit the other day adding an error throw on a set operation... which is basically what I usually do.

Any thoughts on a more general readOnly feature?

Also somewhat related to the desire for a reverse oneWay binding.

@stefanpenner
Ember.js member

@endash I think a option to mark a computed property as readOnly is a great idea.

Thoughts on the following API?

Ember.computed(function(){
  ..snip...
}, { readOnly: true});
@endash

I'm a fan of chaining flags a la

Ember.computed(function () {
}).property('blah').readOnly()

But I'm not picky.

@stefanpenner
Ember.js member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment