Ember.ObjectProxy Class packages/ember-runtime/lib/system/object_proxy.js:4
PUBLIC
Extends: Ember._ProxyMixin
Defined in: packages/ember-runtime/lib/system/object_proxy.js:4
Module: ember
Ember.ObjectProxy forwards all properties not defined by the proxy itself
to a proxied content object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
object = Ember.Object.create({
name: 'Foo'
});
proxy = Ember.ObjectProxy.create({
content: object
});
// Access and change existing properties
proxy.get('name') // 'Foo'
proxy.set('name', 'Bar');
object.get('name') // 'Bar'
// Create new 'description' property on `object`
proxy.set('description', 'Foo is a whizboo baz');
object.get('description') // 'Foo is a whizboo baz'
|
While content is unset, setting a property to be delegated will throw an
Error.
1 2 3 4 5 6 7 8 |
proxy = Ember.ObjectProxy.create({
content: null,
flag: null
});
proxy.set('flag', true);
proxy.get('flag'); // true
proxy.get('foo'); // undefined
proxy.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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
ProxyWithComputedProperty = Ember.ObjectProxy.extend({
fullName: function() {
var firstName = this.get('firstName'),
lastName = this.get('lastName');
if (firstName && lastName) {
return firstName + ' ' + lastName;
}
return firstName || lastName;
}.property('firstName', 'lastName')
});
proxy = ProxyWithComputedProperty.create();
proxy.get('fullName'); // undefined
proxy.set('content', {
firstName: 'Tom', lastName: 'Dale'
}); // triggers property change for fullName on proxy
proxy.get('fullName'); // 'Tom Dale'
|