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

Function accumulateInto

code/higher-order-components/public/app.js:2189–2213  ·  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

2187 */
2188
2189function accumulateInto(current, next) {
2190 !(next != null) ? invariant(false, 'accumulateInto(...): Accumulated items must not be null or undefined.') : void 0;
2191
2192 if (current == null) {
2193 return next;
2194 }
2195
2196 // Both are not empty. Warning: Never call x.concat(y) when you are not
2197 // certain that x is an Array (x could be a string with concat method).
2198 if (Array.isArray(current)) {
2199 if (Array.isArray(next)) {
2200 current.push.apply(current, next);
2201 return current;
2202 }
2203 current.push(next);
2204 return current;
2205 }
2206
2207 if (Array.isArray(next)) {
2208 // A bit too dangerous to mutate `next`.
2209 return [current].concat(next);
2210 }
2211
2212 return [current, next];
2213}
2214
2215/**
2216 * @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