Skip to content

Commit

Permalink
Refactor lazyGet
Browse files Browse the repository at this point in the history
* Extract `isVolatile` function
* Combine logic flow for when to use `get` vs use the meta cache
  • Loading branch information
mitchlloyd committed Mar 24, 2015
1 parent c4d9011 commit 195943e
Showing 1 changed file with 9 additions and 11 deletions.
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

0 comments on commit 195943e

Please sign in to comment.