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

Function accumulateInto

code/event-handlers/public/app.js:1525–1549  ·  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

1523 */
1524
1525function accumulateInto(current, next) {
1526 !(next != null) ? invariant(false, 'accumulateInto(...): Accumulated items must not be null or undefined.') : void 0;
1527
1528 if (current == null) {
1529 return next;
1530 }
1531
1532 // Both are not empty. Warning: Never call x.concat(y) when you are not
1533 // certain that x is an Array (x could be a string with concat method).
1534 if (Array.isArray(current)) {
1535 if (Array.isArray(next)) {
1536 current.push.apply(current, next);
1537 return current;
1538 }
1539 current.push(next);
1540 return current;
1541 }
1542
1543 if (Array.isArray(next)) {
1544 // A bit too dangerous to mutate `next`.
1545 return [current].concat(next);
1546 }
1547
1548 return [current, next];
1549}
1550
1551/**
1552 * @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