Class ComputedProperty

public
Defined in: packages/@ember/-internals/metal/lib/computed.ts:57
Module: @ember/object

meta (meta) public

Module: @ember/object
meta
Object

In some cases, you may want to annotate computed properties with additional metadata about how they function or what values they operate on. For example, computed property functions may close over variables that are then no longer available for introspection. You can pass a hash of these values to a computed property.

Example:

import { computed } from '@ember/object';
import Person from 'my-app/utils/person';

class Store {
  @computed().meta({ type: Person })
  get person() {
    let personId = this.personId;
    return Person.create({ id: personId });
  }
}

Classic Class Example:

import { computed } from '@ember/object';
import Person from 'my-app/utils/person';

const Store = EmberObject.extend({
  person: computed(function() {
    let personId = this.get('personId');
    return Person.create({ id: personId });
  }).meta({ type: Person })
});

The hash that you pass to the meta() function will be saved on the computed property descriptor under the _meta key. Ember runtime exposes a public API for retrieving these values from classes, via the metaForProperty() function.

readOnly ComputedProperty public

Module: @ember/object
returns
ComputedProperty
this

Call on a computed property to set it into read-only mode. When in this mode the computed property will throw an error when set.

Example:

import { computed, set } from '@ember/object';

class Person {
  @computed().readOnly()
  get guid() {
    return 'guid-guid-guid';
  }
}

let person = new Person();
set(person, 'guid', 'new-guid'); // will throw an exception

Classic Class Example:

import EmberObject, { computed } from '@ember/object';

let Person = EmberObject.extend({
  guid: computed(function() {
    return 'guid-guid-guid';
  }).readOnly()
});

let person = Person.create();
person.set('guid', 'new-guid'); // will throw an exception

© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/classes/ComputedProperty/methods