Permalink
Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up
Fetching contributors…
Cannot retrieve contributors at this time.
Cannot retrieve contributors at this time
| import EmberObject from "ember-runtime/system/object"; | |
| import _ProxyMixin from "ember-runtime/mixins/-proxy"; | |
| /** | |
| `Ember.ObjectProxy` forwards all properties not defined by the proxy itself | |
| to a proxied `content` object. | |
| ```javascript | |
| 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. | |
| ```javascript | |
| 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. | |
| ```javascript | |
| 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' | |
| ``` | |
| @class ObjectProxy | |
| @namespace Ember | |
| @extends Ember.Object | |
| @extends Ember._ProxyMixin | |
| @private | |
| */ | |
| export default EmberObject.extend(_ProxyMixin); |