Skip to content

Commit 1af559c

Browse files
committed
[bugfix] computed.alias not always equal to aliased property
1 parent 55e862f commit 1af559c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/ember-metal/lib/computed.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ computed.alias = function(dependentKey) {
11821182
return computed(dependentKey, function(key, value) {
11831183
if (arguments.length > 1) {
11841184
set(this, dependentKey, value);
1185-
return value;
1185+
return get(this, dependentKey);
11861186
} else {
11871187
return get(this, dependentKey);
11881188
}

packages/ember-metal/tests/computed_test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,24 @@ testBoth('computed.alias', function(get, set) {
824824
equal(get(obj, 'quz'), null);
825825
});
826826

827+
testBoth('computed.alias set', function(get, set) {
828+
var obj = {};
829+
var constantValue = 'always `a`';
830+
831+
defineProperty(obj, 'original', computed(function(key, value) {
832+
return constantValue;
833+
}));
834+
defineProperty(obj, 'aliased', computed.alias('original'));
835+
836+
equal(get(obj, 'original'), constantValue);
837+
equal(get(obj, 'aliased'), constantValue);
838+
839+
set(obj, 'aliased', 'should not set to this value');
840+
841+
equal(get(obj, 'original'), constantValue);
842+
equal(get(obj, 'aliased'), constantValue);
843+
});
844+
827845
testBoth('computed.defaultTo', function(get, set) {
828846
var obj = { source: 'original source value' };
829847
defineProperty(obj, 'copy', computed.defaultTo('source'));

0 commit comments

Comments
 (0)