Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reuse meta for didUnwatch and willWatch in alias descriptor #15691

Merged
merged 1 commit into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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