/**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 ReactComponent9*/1011'use strict';1213var ReactUpdateQueue = require("./ReactUpdateQueue");1415var invariant = require("./invariant");16var warning = require("./warning");1718/**19* Base class helpers for the updating state of a component.20*/21function ReactComponent(props, context) {22this.props = props;23this.context = context;24}2526/**27* Sets a subset of the state. Always use this to mutate28* state. You should treat `this.state` as immutable.29*30* There is no guarantee that `this.state` will be immediately updated, so31* accessing `this.state` after calling this method may return the old value.32*33* There is no guarantee that calls to `setState` will run synchronously,34* as they may eventually be batched together. You can provide an optional35* callback that will be executed when the call to setState is actually36* completed.37*38* When a function is provided to setState, it will be called at some point in39* the future (not synchronously). It will be called with the up to date40* component arguments (state, props, context). These values can be different41* from this.* because your function may be called after receiveProps but before42* shouldComponentUpdate, and this new state, props, and context will not yet be43* assigned to this.44*45* @param {object|function} partialState Next partial state or function to46* produce next partial state to be merged with current state.47* @param {?function} callback Called after state is updated.48* @final49* @protected50*/51ReactComponent.prototype.setState = function(partialState, callback) {52("production" !== process.env.NODE_ENV ? invariant(53typeof partialState === 'object' ||54typeof partialState === 'function' ||55partialState == null,56'setState(...): takes an object of state variables to update or a ' +57'function which returns an object of state variables.'58) : invariant(typeof partialState === 'object' ||59typeof partialState === 'function' ||60partialState == null));61if ("production" !== process.env.NODE_ENV) {62("production" !== process.env.NODE_ENV ? warning(63partialState != null,64'setState(...): You passed an undefined or null state object; ' +65'instead, use forceUpdate().'66) : null);67}68ReactUpdateQueue.enqueueSetState(this, partialState);69if (callback) {70ReactUpdateQueue.enqueueCallback(this, callback);71}72};7374/**75* Forces an update. This should only be invoked when it is known with76* certainty that we are **not** in a DOM transaction.77*78* You may want to call this when you know that some deeper aspect of the79* component's state has changed but `setState` was not called.80*81* This will not invoke `shouldComponentUpdate`, but it will invoke82* `componentWillUpdate` and `componentDidUpdate`.83*84* @param {?function} callback Called after update is complete.85* @final86* @protected87*/88ReactComponent.prototype.forceUpdate = function(callback) {89ReactUpdateQueue.enqueueForceUpdate(this);90if (callback) {91ReactUpdateQueue.enqueueCallback(this, callback);92}93};9495/**96* Deprecated APIs. These APIs used to exist on classic React classes but since97* we would like to deprecate them, we're not going to move them over to this98* modern base class. Instead, we define a getter that warns if it's accessed.99*/100if ("production" !== process.env.NODE_ENV) {101var deprecatedAPIs = {102getDOMNode: [103'getDOMNode',104'Use React.findDOMNode(component) instead.'105],106isMounted: [107'isMounted',108'Instead, make sure to clean up subscriptions and pending requests in ' +109'componentWillUnmount to prevent memory leaks.'110],111replaceProps: [112'replaceProps',113'Instead, call React.render again at the top level.'114],115replaceState: [116'replaceState',117'Refactor your code to use setState instead (see ' +118'https://github.com/facebook/react/issues/3236).'119],120setProps: [121'setProps',122'Instead, call React.render again at the top level.'123]124};125var defineDeprecationWarning = function(methodName, info) {126try {127Object.defineProperty(ReactComponent.prototype, methodName, {128get: function() {129("production" !== process.env.NODE_ENV ? warning(130false,131'%s(...) is deprecated in plain JavaScript React classes. %s',132info[0],133info[1]134) : null);135return undefined;136}137});138} catch (x) {139// IE will fail on defineProperty (es5-shim/sham too)140}141};142for (var fnName in deprecatedAPIs) {143if (deprecatedAPIs.hasOwnProperty(fnName)) {144defineDeprecationWarning(fnName, deprecatedAPIs[fnName]);145}146}147}148149module.exports = ReactComponent;150151152