Skip to content

Commit

Permalink
[BUGFIX release] [PERF] Cleanup Proxy
Browse files Browse the repository at this point in the history
* remove `on(‘init`, just use the existing `init`
* remove double meta lookups
* remove observer (use existing proxy trap, and detect `key === ‘content’`
* remove double `tag` lookups
* misc cleanup
  • Loading branch information
stefanpenner committed Apr 17, 2017
1 parent 32da960 commit f0ecedc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
8 changes: 8 additions & 0 deletions packages/ember-metal/lib/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ export class Meta {
return this.proto !== obj;
}

setTag(tag) {
this._tag = tag;
}

getTag(tag) {
return this._tag;
}

destroy() {
if (this.isMetaDestroyed()) { return; }

Expand Down
25 changes: 12 additions & 13 deletions packages/ember-runtime/lib/mixins/-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,13 @@ export default Mixin.create({

init() {
this._super(...arguments);
meta(this).setProxy();
let m = meta(this);
m.setProxy();
m.setTag(new ProxyTag(this));
},

_initializeTag: on('init', function() {
meta(this)._tag = new ProxyTag(this);
}),

_contentDidChange: observer('content', function() {
assert('Can\'t set Proxy\'s content to itself', get(this, 'content') !== this);
tagFor(this).contentDidChange();
}),

isTruthy: bool('content'),

_debugContainerKey: null,

willWatchProperty(key) {
let contentKey = `content.${key}`;
_addBeforeObserver(this, contentKey, null, contentPropertyWillChange);
Expand All @@ -126,6 +117,9 @@ export default Mixin.create({

setUnknownProperty(key, value) {
let m = meta(this);

assert('Can\'t set Proxy\'s content to itself', value !== this);

if (m.proto === this) {
// if marked as prototype then just defineProperty
// rather than delegate
Expand All @@ -141,6 +135,11 @@ export default Mixin.create({
!this.isController,
{ id: 'ember-runtime.controller-proxy', until: '3.0.0' }
);
return set(content, key, value);

let ret = set(content, key, value);
if (key === 'content') {
m.getTag().contentDidChange();
}
return ret;
}
});

0 comments on commit f0ecedc

Please sign in to comment.