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

[BUGFIX beta] Make computed.or return more like || #10259

Merged
merged 1 commit into from
Aug 3, 2015
Merged
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
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