Skip to content

Commit

Permalink
Update documentation for EmberArray.any
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sukima committed Aug 8, 2019
1 parent e8a6420 commit 2ee24e1
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions packages/@ember/-internals/runtime/lib/mixins/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
```
Expand Down

0 comments on commit 2ee24e1

Please sign in to comment.