Skip to content

Commit

Permalink
Merge pull request emberjs#10259 from soulcutter/computed-or-enhancement
Browse files Browse the repository at this point in the history
[BUGFIX beta] Make computed.or return more like ||
  • Loading branch information
rwjblue committed Aug 3, 2015
2 parents adabda5 + ad8e3f2 commit a49c2eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/ember-metal/lib/computed_macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,14 @@ export var and = generateComputedWithProperties(function(properties) {
@public
*/
export var or = generateComputedWithProperties(function(properties) {
var value;
for (var key in properties) {
if (properties.hasOwnProperty(key) && properties[key]) {
return properties[key];
value = properties[key];
if (properties.hasOwnProperty(key) && value) {
return value;
}
}
return false;
return value;
});

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/ember-runtime/tests/computed/computed_macros_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ testBoth('computed.or', function(get, set) {

equal(get(obj, 'oneOrTwo'), false, 'nore one nore two');

set(obj, 'two', null);

equal(get(obj, 'oneOrTwo'), null, 'returns last falsy value as in ||');

set(obj, 'two', true);

equal(get(obj, 'oneOrTwo'), true, 'one or two');
Expand Down

0 comments on commit a49c2eb

Please sign in to comment.