MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / accumulateInto

Function accumulateInto

code/controlled-uncontrolled/public/app.js:1519–1543  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

1517 */
1518
1519function accumulateInto(current, next) {
1520 !(next != null) ? invariant(false, 'accumulateInto(...): Accumulated items must not be null or undefined.') : void 0;
1521
1522 if (current == null) {
1523 return next;
1524 }
1525
1526 // Both are not empty. Warning: Never call x.concat(y) when you are not
1527 // certain that x is an Array (x could be a string with concat method).
1528 if (Array.isArray(current)) {
1529 if (Array.isArray(next)) {
1530 current.push.apply(current, next);
1531 return current;
1532 }
1533 current.push(next);
1534 return current;
1535 }
1536
1537 if (Array.isArray(next)) {
1538 // A bit too dangerous to mutate `next`.
1539 return [current].concat(next);
1540 }
1541
1542 return [current, next];
1543}
1544
1545/**
1546 * @param {array} arr an "accumulation" of items which is either an Array or

Callers 4

extractEventsFunction · 0.70
runEventsInBatchFunction · 0.70
accumulateDispatchesFunction · 0.70

Calls 1

invariantFunction · 0.70

Tested by

no test coverage detected