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

Refactor lazyGet #10701

Merged
merged 1 commit into from
May 22, 2015
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
20 changes: 9 additions & 11 deletions packages/ember-metal/lib/chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ function isObject(obj) {
return obj && (typeof obj === 'object');
}

function isVolatile(obj) {
return !(isObject(obj) && obj.isDescriptor && obj._cacheable);
}

var pendingQueue = [];

// attempts to add the pendingQueue chains again. If some of them end up
Expand Down Expand Up @@ -119,27 +123,21 @@ function lazyGet(obj, key) {
}

var meta = obj['__ember_meta__'];

// check if object meant only to be a prototype
if (meta && meta.proto === obj) {
return;
}

if (key === "@each") {
// Use `get` if the return value is an EachProxy or an uncacheable value.
if (key === "@each" || isVolatile(obj[key])) {
return get(obj, key);
}

// if a CP only return cached value
var possibleDesc = obj[key];
var desc = (possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor) ? possibleDesc : undefined;
if (desc && desc._cacheable) {
// Otherwise attempt to get the cached value of the computed property
} else {
if (meta.cache && key in meta.cache) {
return meta.cache[key];
} else {
return;
}
}

return get(obj, key);
}

ChainNode.prototype = {
Expand Down