/**1* Copyright 2013-2015, 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 ReactContext9*/1011'use strict';1213var assign = require("./Object.assign");14var emptyObject = require("./emptyObject");15var warning = require("./warning");1617var didWarn = false;1819/**20* Keeps track of the current context.21*22* The context is automatically passed down the component ownership hierarchy23* and is accessible via `this.context` on ReactCompositeComponents.24*/25var ReactContext = {2627/**28* @internal29* @type {object}30*/31current: emptyObject,3233/**34* Temporarily extends the current context while executing scopedCallback.35*36* A typical use case might look like37*38* render: function() {39* var children = ReactContext.withContext({foo: 'foo'}, () => (40*41* ));42* return <div>{children}</div>;43* }44*45* @param {object} newContext New context to merge into the existing context46* @param {function} scopedCallback Callback to run with the new context47* @return {ReactComponent|array<ReactComponent>}48*/49withContext: function(newContext, scopedCallback) {50if ("production" !== process.env.NODE_ENV) {51("production" !== process.env.NODE_ENV ? warning(52didWarn,53'withContext is deprecated and will be removed in a future version. ' +54'Use a wrapper component with getChildContext instead.'55) : null);5657didWarn = true;58}5960var result;61var previousContext = ReactContext.current;62ReactContext.current = assign({}, previousContext, newContext);63try {64result = scopedCallback();65} finally {66ReactContext.current = previousContext;67}68return result;69}7071};7273module.exports = ReactContext;747576