* Accumulates items that must not be null or undefined into the first one. This * is used to conserve memory by avoiding array allocations, and thus sacrifices * API cleanness. Since `current` can be null before being passed in and not * null after this function, make sure to assign it back to `c
(current, next)
| 1554 | */ |
| 1555 | |
| 1556 | function accumulateInto(current, next) { |
| 1557 | !(next != null) ? invariant(false, 'accumulateInto(...): Accumulated items must not be null or undefined.') : void 0; |
| 1558 | |
| 1559 | if (current == null) { |
| 1560 | return next; |
| 1561 | } |
| 1562 | |
| 1563 | // Both are not empty. Warning: Never call x.concat(y) when you are not |
| 1564 | // certain that x is an Array (x could be a string with concat method). |
| 1565 | if (Array.isArray(current)) { |
| 1566 | if (Array.isArray(next)) { |
| 1567 | current.push.apply(current, next); |
| 1568 | return current; |
| 1569 | } |
| 1570 | current.push(next); |
| 1571 | return current; |
| 1572 | } |
| 1573 | |
| 1574 | if (Array.isArray(next)) { |
| 1575 | // A bit too dangerous to mutate `next`. |
| 1576 | return [current].concat(next); |
| 1577 | } |
| 1578 | |
| 1579 | return [current, next]; |
| 1580 | } |
| 1581 | |
| 1582 | /** |
| 1583 | * @param {array} arr an "accumulation" of items which is either an Array or |
no test coverage detected