diff options
Diffstat (limited to 'node_modules/react-dom/lib/accumulate.js')
-rw-r--r-- | node_modules/react-dom/lib/accumulate.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/node_modules/react-dom/lib/accumulate.js b/node_modules/react-dom/lib/accumulate.js new file mode 100644 index 000000000..a4c763fe4 --- /dev/null +++ b/node_modules/react-dom/lib/accumulate.js @@ -0,0 +1,45 @@ +/** + * Copyright 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * + */ + +'use strict'; + +var _prodInvariant = require('./reactProdInvariant'); + +var invariant = require('fbjs/lib/invariant'); + +/** + * Accumulates items that must not be null or undefined. + * + * This is used to conserve memory by avoiding array allocations. + * + * @return {*|array<*>} An accumulation of items. + */ +function accumulate(current, next) { + !(next != null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'accumulate(...): Accumulated items must be not be null or undefined.') : _prodInvariant('29') : void 0; + + if (current == null) { + return next; + } + + // Both are not empty. Warning: Never call x.concat(y) when you are not + // certain that x is an Array (x could be a string with concat method). + if (Array.isArray(current)) { + return current.concat(next); + } + + if (Array.isArray(next)) { + return [current].concat(next); + } + + return [current, next]; +} + +module.exports = accumulate;
\ No newline at end of file |