Class ObjectProxy

public
import ObjectProxy from '@ember/object/proxy';

ObjectProxy forwards all properties not defined by the proxy itself to a proxied content object.

import EmberObject from '@ember/object';
import ObjectProxy from '@ember/object/proxy';

let exampleObject = EmberObject.create({
  name: 'Foo'
});

let exampleProxy = ObjectProxy.create({
  content: exampleObject
});

// Access and change existing properties
exampleProxy.get('name');          // 'Foo'
exampleProxy.set('name', 'Bar');
exampleObject.get('name');         // 'Bar'

// Create new 'description' property on `exampleObject`
exampleProxy.set('description', 'Foo is a whizboo baz');
exampleObject.get('description');  // 'Foo is a whizboo baz'

While content is unset, setting a property to be delegated will throw an Error.

import ObjectProxy from '@ember/object/proxy';

let exampleProxy = ObjectProxy.create({
  content: null,
  flag: null
});
exampleProxy.set('flag', true);
exampleProxy.get('flag');         // true
exampleProxy.get('foo');          // undefined
exampleProxy.set('foo', 'data');  // throws Error

Delegated properties can be bound to and will change when content is updated.

Computed properties on the proxy itself can depend on delegated properties.

import { computed } from '@ember/object';
import ObjectProxy from '@ember/object/proxy';

ProxyWithComputedProperty = ObjectProxy.extend({
  fullName: computed('firstName', 'lastName', function() {
    var firstName = this.get('firstName'),
        lastName = this.get('lastName');
    if (firstName && lastName) {
      return firstName + ' ' + lastName;
    }
    return firstName || lastName;
  })
});

let exampleProxy = ProxyWithComputedProperty.create();

exampleProxy.get('fullName');  // undefined
exampleProxy.set('content', {
  firstName: 'Tom', lastName: 'Dale'
}); // triggers property change for fullName on proxy

exampleProxy.get('fullName');  // 'Tom Dale'

Show:

Module: @ember/object

Defines the properties that will be concatenated from the superclass (instead of overridden).

By default, when you extend an Ember class a property defined in the subclass overrides a property with the same name that is defined in the superclass. However, there are some cases where it is preferable to build up a property's value by combining the superclass' property value with the subclass' value. An example of this in use within Ember is the classNames property of Component from @ember/component.

Here is some sample code showing the difference between a concatenated property and a normal one:

import EmberObject from '@ember/object';

const Bar = EmberObject.extend({
  // Configure which properties to concatenate
  concatenatedProperties: ['concatenatedProperty'],

  someNonConcatenatedProperty: ['bar'],
  concatenatedProperty: ['bar']
});

const FooBar = Bar.extend({
  someNonConcatenatedProperty: ['foo'],
  concatenatedProperty: ['foo']
});

let fooBar = FooBar.create();
fooBar.get('someNonConcatenatedProperty'); // ['foo']
fooBar.get('concatenatedProperty'); // ['bar', 'foo']

This behavior extends to object creation as well. Continuing the above example:

let fooBar = FooBar.create({
  someNonConcatenatedProperty: ['baz'],
  concatenatedProperty: ['baz']
})
fooBar.get('someNonConcatenatedProperty'); // ['baz']
fooBar.get('concatenatedProperty'); // ['bar', 'foo', 'baz']

Adding a single property that is not an array will just add it in the array:

let fooBar = FooBar.create({
  concatenatedProperty: 'baz'
})
view.get('concatenatedProperty'); // ['bar', 'foo', 'baz']

Using the concatenatedProperties property, we can tell Ember to mix the content of the properties.

In Component the classNames, classNameBindings and attributeBindings properties are concatenated.

This feature is available for you to use throughout the Ember object model, although typical app developers are likely to use it infrequently. Since it changes expectations about behavior of properties, you should properly document its usage in each individual concatenated property (to not mislead your users to think they can override the property in a subclass).

Module: @ember/object

The object whose properties will be forwarded.

Module: @ember/object

Destroyed object property flag.

if this property is true the observers and bindings were already removed by the effect of calling the destroy() method.

Module: @ember/object

Destruction scheduled flag. The destroy() method has been called.

The object stays intact until the end of the run loop at which point the isDestroyed flag is set.

Module: @ember/object

Defines the properties that will be merged from the superclass (instead of overridden).

By default, when you extend an Ember class a property defined in the subclass overrides a property with the same name that is defined in the superclass. However, there are some cases where it is preferable to build up a property's value by merging the superclass property value with the subclass property's value. An example of this in use within Ember is the queryParams property of routes.

Here is some sample code showing the difference between a merged property and a normal one:

import EmberObject from '@ember/object';

const Bar = EmberObject.extend({
  // Configure which properties are to be merged
  mergedProperties: ['mergedProperty'],

  someNonMergedProperty: {
    nonMerged: 'superclass value of nonMerged'
  },
  mergedProperty: {
    page: { replace: false },
    limit: { replace: true }
  }
});

const FooBar = Bar.extend({
  someNonMergedProperty: {
    completelyNonMerged: 'subclass value of nonMerged'
  },
  mergedProperty: {
    limit: { replace: false }
  }
});

let fooBar = FooBar.create();

fooBar.get('someNonMergedProperty');
// => { completelyNonMerged: 'subclass value of nonMerged' }
//
// Note the entire object, including the nonMerged property of
// the superclass object, has been replaced

fooBar.get('mergedProperty');
// => {
//   page: {replace: false},
//   limit: {replace: false}
// }
//
// Note the page remains from the superclass, and the
// `limit` property's value of `false` has been merged from
// the subclass.

This behavior is not available during object create calls. It is only available at extend time.

In Route the queryParams property is merged.

This feature is available for you to use throughout the Ember object model, although typical app developers are likely to use it infrequently. Since it changes expectations about behavior of properties, you should properly document its usage in each individual merged property (to not mislead your users to think they can override the property in a subclass).