Ember.computed.readOnly()

readOnly (dependentKey) Ember.ComputedPropertypublic

Defined in packages/ember-runtime/lib/computed/computed_macros.js:580
Available since 1.5.0

Where computed.oneWay provides oneWay bindings, computed.readOnly provides a readOnly one way binding. Very often when using computed.oneWay one does not also want changes to propagate back up, as they will replace the value.

This prevents the reverse flow, and also throws an exception when it occurs.

Example

let User = Ember.Object.extend({
  firstName: null,
  lastName: null,
  nickName: Ember.computed.readOnly('firstName')
});

let teddy = User.create({
  firstName: 'Teddy',
  lastName:  'Zeenny'
});

teddy.get('nickName');              // 'Teddy'
teddy.set('nickName', 'TeddyBear'); // throws Exception
// throw new Ember.Error('Cannot Set: nickName on: <User:ember27288>' );`
teddy.get('firstName');             // 'Teddy'

Parameters:

dependentKey String

Returns:

Ember.ComputedProperty
computed property which creates a one way computed property to the original value for property.
doc_EmberJs
2016-11-30 16:51:19
Comments
Leave a Comment

Please login to continue.