react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / vendor / core / mergeDeep.js
81158 views/**1* Copyright 2013-2014, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under the BSD-style license found in the5* LICENSE file in the root directory of this source tree. An additional grant6* of patent rights can be found in the PATENTS file in the same directory.7*8* @providesModule mergeDeep9*/1011"use strict";1213var mergeHelpers = require('mergeHelpers');14var mergeDeepInto = require('mergeDeepInto');1516var checkArrayStrategy = mergeHelpers.checkArrayStrategy;17var checkMergeObjectArgs = mergeHelpers.checkMergeObjectArgs;18var normalizeMergeArg = mergeHelpers.normalizeMergeArg;1920/**21* @see mergeDeepImpl comments.22*23* @param {!Object} one returned will be an structural extension of this.24* @param {!Object} two values from two take precedence over values in one.25* @param {?Enum=} arrayStrategy One of `arrayStrategies`.26* @return {!Object} the extension of one by two.27*/28var mergeDeep = function(oneParam, twoParam, arrayStrategy) {29var one = normalizeMergeArg(oneParam);30var two = normalizeMergeArg(twoParam);31checkMergeObjectArgs(one, two);32checkArrayStrategy(arrayStrategy);33var newObj = {};34// TODO: This is horribly inefficient. Even when some deep object in `one`35// will be clobbered by another entity in `two`, we perform a clone of that36// entire structure. To make this code more efficient, we'll need to either37// enhance `mergeDeepInto` to accept multiple arguments or mirror that code38// here.39mergeDeepInto(newObj, one, arrayStrategy);40mergeDeepInto(newObj, two, arrayStrategy);41return newObj;42};434445module.exports = mergeDeep;464748