Skip to content

Commit

Permalink
Merge pull request #15691 from bekzod/alias-meta
Browse files Browse the repository at this point in the history
reuse meta for `didUnwatch` and `willWatch` in `alias descriptor`
  • Loading branch information
rwjblue authored Oct 5, 2017
2 parents 24c67d2 + 6aab203 commit a20a784
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
8 changes: 4 additions & 4 deletions packages/ember-metal/lib/alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ export class AliasedProperty extends Descriptor {
}
}

willWatch(obj, keyName) {
addDependentKeys(this, obj, keyName, metaFor(obj));
willWatch(obj, keyName, meta) {
addDependentKeys(this, obj, keyName, meta);
}

didUnwatch(obj, keyName) {
removeDependentKeys(this, obj, keyName, metaFor(obj));
didUnwatch(obj, keyName, meta) {
removeDependentKeys(this, obj, keyName, meta);
}

get(obj, keyName) {
Expand Down
19 changes: 9 additions & 10 deletions packages/ember-metal/lib/watch_key.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,33 @@ import {

let handleMandatorySetter;

export function watchKey(obj, keyName, meta) {
export function watchKey(obj, keyName, _meta) {
if (typeof obj !== 'object' || obj === null) { return; }

let m = meta === undefined ? metaFor(obj) : meta;
let count = m.peekWatching(keyName) || 0;
m.writeWatching(keyName, count + 1);
let meta = _meta === undefined ? metaFor(obj) : _meta;
let count = meta.peekWatching(keyName) || 0;
meta.writeWatching(keyName, count + 1);

if (count === 0) { // activate watching first time
let possibleDesc = obj[keyName];
let isDescriptor = possibleDesc !== null &&
typeof possibleDesc === 'object' && possibleDesc.isDescriptor;
if (isDescriptor && possibleDesc.willWatch) { possibleDesc.willWatch(obj, keyName); }
if (isDescriptor && possibleDesc.willWatch) { possibleDesc.willWatch(obj, keyName, meta); }

if ('function' === typeof obj.willWatchProperty) {
if (typeof obj.willWatchProperty === 'function') {
obj.willWatchProperty(keyName);
}

if (MANDATORY_SETTER) {
// NOTE: this is dropped for prod + minified builds
handleMandatorySetter(m, obj, keyName);
handleMandatorySetter(meta, obj, keyName);
}
}
}


if (MANDATORY_SETTER) {
let hasOwnProperty = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);

let propertyIsEnumerable = (obj, key) => Object.prototype.propertyIsEnumerable.call(obj, key);

// Future traveler, although this code looks scary. It merely exists in
Expand Down Expand Up @@ -97,9 +96,9 @@ export function unwatchKey(obj, keyName, _meta) {
let isDescriptor = possibleDesc !== null &&
typeof possibleDesc === 'object' && possibleDesc.isDescriptor;

if (isDescriptor && possibleDesc.didUnwatch) { possibleDesc.didUnwatch(obj, keyName); }
if (isDescriptor && possibleDesc.didUnwatch) { possibleDesc.didUnwatch(obj, keyName, meta); }

if ('function' === typeof obj.didUnwatchProperty) {
if (typeof obj.didUnwatchProperty === 'function') {
obj.didUnwatchProperty(keyName);
}

Expand Down

0 comments on commit a20a784

Please sign in to comment.