From 2ee24e149401b3907ea96513a88d1b8516f8835e Mon Sep 17 00:00:00 2001 From: Devin Weaver Date: Tue, 6 Aug 2019 11:40:54 -0400 Subject: [PATCH] Update documentation for EmberArray.any Prior to this change, the wording was inaccurate. It was describing filtering not the short circuit behaviour of `any()`. This change attempts to fix that discrepancy and expand on the example to include both context option and arrow function use. Issue #18228 --- .../-internals/runtime/lib/mixins/array.js | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/@ember/-internals/runtime/lib/mixins/array.js b/packages/@ember/-internals/runtime/lib/mixins/array.js index 2d6089c4c2c..2059915274d 100644 --- a/packages/@ember/-internals/runtime/lib/mixins/array.js +++ b/packages/@ember/-internals/runtime/lib/mixins/array.js @@ -860,11 +860,10 @@ const ArrayMixin = Mixin.create(Enumerable, { }, /** - Returns `true` if the passed function returns true for any item in the - enumeration. - - The callback method you provide should have the following signature (all - parameters are optional): + The any() method executes the callback function once for each element + present in the array until it finds the one where callback returns a truthy + value (i.e. `true`). If such an element is found, any() immediately returns + true. Otherwise, any() returns false. ```javascript function(item, index, array); @@ -874,18 +873,21 @@ const ArrayMixin = Mixin.create(Enumerable, { - `index` is the current index in the iteration. - `array` is the array object itself. - It must return a truthy value (i.e. `true`) to include an item in the - results. Any non-truthy return value will discard the item from the - results. - Note that in addition to a callback, you can also pass an optional target - object that will be set as `this` on the context. This is a good way - to give your iterator function access to the current object. + object that will be set as `this` on the context. It can be a good way + to give your iterator function access to an object in cases where an ES6 + arrow function would not be appropriate. Usage Example: ```javascript - if (people.any(isManager)) { + let includesManager = people.any(this.findPersonInManagersList, this); + + let includesStockHolder = people.any(person => { + return this.findPersonInStockHoldersList(person) + }); + + if (includesManager || includesStockHolder) { Paychecks.addBiggerBonus(); } ```