From ad8e3f2ff9a882e9522b3d68379e71a22a8ee3e5 Mon Sep 17 00:00:00 2001 From: Bradley Schaefer Date: Wed, 21 Jan 2015 09:59:48 -0600 Subject: [PATCH] [BUGFIX beta] Make computed.or return more like || Given the recent deprecation of computed.any in favor of computed.or it seems more-appropriate to return the last falsy value to enable these computed properties to potentially be rendered directly in templates without the need to be wrapped in {{#if}} blocks. The behavior of computed.any was to return null, so this brings computed.or more inline with replacing computed.any --- packages/ember-metal/lib/computed_macros.js | 8 +++++--- .../ember-runtime/tests/computed/computed_macros_test.js | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/ember-metal/lib/computed_macros.js b/packages/ember-metal/lib/computed_macros.js index 8075de399cb..ab5a5c94bb4 100644 --- a/packages/ember-metal/lib/computed_macros.js +++ b/packages/ember-metal/lib/computed_macros.js @@ -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; }); /** diff --git a/packages/ember-runtime/tests/computed/computed_macros_test.js b/packages/ember-runtime/tests/computed/computed_macros_test.js index 97b5279fcf7..e187ff64e9b 100644 --- a/packages/ember-runtime/tests/computed/computed_macros_test.js +++ b/packages/ember-runtime/tests/computed/computed_macros_test.js @@ -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');