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

[BUGFIX beta] Extracts computed property set into a separate function #5547

Merged
merged 1 commit into from
Sep 17, 2014
Merged
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
108 changes: 59 additions & 49 deletions packages/ember-metal/lib/computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,75 +398,85 @@ ComputedPropertyPrototype.get = function(obj, keyName) {
@param {String} oldValue The old value being replaced.
@return {Object} The return value of the function backing the CP.
*/
ComputedPropertyPrototype.set = function(obj, keyName, value) {
var cacheable = this._cacheable;
var func = this.func;
var meta = metaFor(obj, cacheable);
ComputedPropertyPrototype.set = function computedPropertySetWithSuspend(obj, keyName, value) {
var oldSuspended = this._suspended;

this._suspended = obj;

try {
this._set(obj, keyName, value);
} finally {
this._suspended = oldSuspended;
}
};

ComputedPropertyPrototype._set = function computedPropertySet(obj, keyName, value) {
var cacheable = this._cacheable;
var func = this.func;
var meta = metaFor(obj, cacheable);
var cache = meta.cache;
var hadCachedValue = false;
var cache = meta.cache;

var funcArgLength, cachedValue, ret;

if (this._readOnly) {
throw new EmberError('Cannot set read-only property "' + keyName + '" on object: ' + inspect(obj));
}

this._suspended = obj;

try {
if (cacheable && cache[keyName] !== undefined) {
if(cache[keyName] !== UNDEFINED) {
cachedValue = cache[keyName];
}

if (cacheable && cache[keyName] !== undefined) {
if(cache[keyName] !== UNDEFINED) {
cachedValue = cache[keyName];
}
hadCachedValue = true;
}

hadCachedValue = true;
}
// Check if the CP has been wrapped. If it has, use the
// length from the wrapped function.

// Check if the CP has been wrapped. If it has, use the
// length from the wrapped function.
funcArgLength = func.wrappedFunction ? func.wrappedFunction.__ember_arity__ : func.__ember_arity__;

funcArgLength = func.wrappedFunction ? func.wrappedFunction.__ember_arity__ : func.__ember_arity__;
// For backwards-compatibility with computed properties
// that check for arguments.length === 2 to determine if
// they are being get or set, only pass the old cached
// value if the computed property opts into a third
// argument.
if (funcArgLength === 3) {
ret = func.call(obj, keyName, value, cachedValue);
} else if (funcArgLength === 2) {
ret = func.call(obj, keyName, value);
} else {
defineProperty(obj, keyName, null, cachedValue);
set(obj, keyName, value);
return;
}

// For backwards-compatibility with computed properties
// that check for arguments.length === 2 to determine if
// they are being get or set, only pass the old cached
// value if the computed property opts into a third
// argument.
if (funcArgLength === 3) {
ret = func.call(obj, keyName, value, cachedValue);
} else if (funcArgLength === 2) {
ret = func.call(obj, keyName, value);
} else {
defineProperty(obj, keyName, null, cachedValue);
set(obj, keyName, value);
return;
}
if (hadCachedValue && cachedValue === ret) { return; }

if (hadCachedValue && cachedValue === ret) { return; }
var watched = meta.watching[keyName];
if (watched) {
propertyWillChange(obj, keyName);
}

var watched = meta.watching[keyName];
if (watched) { propertyWillChange(obj, keyName); }
if (hadCachedValue) {
cache[keyName] = undefined;
}

if (hadCachedValue) {
cache[keyName] = undefined;
if (cacheable) {
if (!hadCachedValue) {
addDependentKeys(this, obj, keyName, meta);
}

if (cacheable) {
if (!hadCachedValue) {
addDependentKeys(this, obj, keyName, meta);
}
if (ret === undefined) {
cache[keyName] = UNDEFINED;
} else {
cache[keyName] = ret;
}
if (ret === undefined) {
cache[keyName] = UNDEFINED;
} else {
cache[keyName] = ret;
}
}

if (watched) { propertyDidChange(obj, keyName); }
} finally {
this._suspended = oldSuspended;
if (watched) {
propertyDidChange(obj, keyName);
}

return ret;
};

Expand Down