Skip to content
Closed
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
4 changes: 2 additions & 2 deletions packages/ember-metal/lib/chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ function lazyGet(obj, key) {
// Otherwise attempt to get the cached value of the computed property
} else {
let cache = meta.readableCache();
if (cache && key in cache) {
return cache[key];
if (cache && cache.has(key)) {
return cache.get(key);
}
}
}
Expand Down
38 changes: 20 additions & 18 deletions packages/ember-metal/lib/computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ ComputedPropertyPrototype.didChange = function(obj, keyName) {
}

let cache = meta.readableCache();
if (cache && cache[keyName] !== undefined) {
cache[keyName] = undefined;
if (cache && cache.get(keyName) !== undefined) {
cache.set(keyName, undefined);
removeDependentKeys(this, obj, keyName, meta);
}
};
Expand All @@ -329,8 +329,8 @@ ComputedPropertyPrototype.get = function(obj, keyName) {

let meta = metaFor(obj);
let cache = meta.writableCache();
let result = cache.get(keyName);

let result = cache[keyName];
if (result === UNDEFINED) {
return undefined;
} else if (result !== undefined) {
Expand All @@ -339,9 +339,9 @@ ComputedPropertyPrototype.get = function(obj, keyName) {

let ret = this._getter.call(obj, keyName);
if (ret === undefined) {
cache[keyName] = UNDEFINED;
cache.set(keyName, UNDEFINED);
} else {
cache[keyName] = ret;
cache.set(keyName, ret);
}

let chainWatchers = meta.readableChainWatchers();
Expand Down Expand Up @@ -400,10 +400,12 @@ ComputedPropertyPrototype._set = function computedPropertySet(obj, keyName, valu
// either there is a writable cache or we need one to update
let cache = meta.writableCache();
let hadCachedValue = false;
let rawCachedValue = cache.get(keyName);
let cachedValue;
if (cache[keyName] !== undefined) {
if (cache[keyName] !== UNDEFINED) {
cachedValue = cache[keyName];

if (rawCachedValue !== undefined) {
if (rawCachedValue !== UNDEFINED) {
cachedValue = rawCachedValue;
}
hadCachedValue = true;
}
Expand All @@ -418,17 +420,17 @@ ComputedPropertyPrototype._set = function computedPropertySet(obj, keyName, valu
propertyWillChange(obj, keyName);

if (hadCachedValue) {
cache[keyName] = undefined;
cache.set(keyName, undefined);
}

if (!hadCachedValue) {
addDependentKeys(this, obj, keyName, meta);
}

if (ret === undefined) {
cache[keyName] = UNDEFINED;
cache.set(keyName, UNDEFINED);
} else {
cache[keyName] = ret;
cache.set(keyName, ret);
}

propertyDidChange(obj, keyName);
Expand All @@ -443,9 +445,9 @@ ComputedPropertyPrototype.teardown = function(obj, keyName) {
}
let meta = metaFor(obj);
let cache = meta.readableCache();
if (cache && cache[keyName] !== undefined) {
if (cache && cache.get(keyName) !== undefined) {
removeDependentKeys(this, obj, keyName, meta);
cache[keyName] = undefined;
cache.set(keyName, undefined);
}
};

Expand Down Expand Up @@ -568,7 +570,7 @@ export default function computed(func) {
function cacheFor(obj, key) {
let meta = peekMeta(obj);
let cache = meta && meta.source === obj && meta.readableCache();
let ret = cache && cache[key];
let ret = cache && cache.get(key);

if (ret === UNDEFINED) {
return undefined;
Expand All @@ -578,22 +580,22 @@ function cacheFor(obj, key) {

cacheFor.set = function(cache, key, value) {
if (value === undefined) {
cache[key] = UNDEFINED;
cache.set(key, UNDEFINED);
} else {
cache[key] = value;
cache.set(key, value);
}
};

cacheFor.get = function(cache, key) {
let ret = cache[key];
let ret = cache.get(key);
if (ret === UNDEFINED) {
return undefined;
}
return ret;
};

cacheFor.remove = function(cache, key) {
cache[key] = undefined;
cache.set(key, undefined);
};

export {
Expand Down
Loading