From 3d1062b26379b4f31ad6ba41eef6da9d21958dd0 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Thu, 2 Feb 2017 20:24:39 +0000 Subject: [PATCH] Move component base classes into a single file (#8918) --- src/isomorphic/React.js | 5 ++- ...{ReactComponent.js => ReactBaseClasses.js} | 28 ++++++++++++- .../modern/class/ReactPureComponent.js | 40 ------------------- 3 files changed, 29 insertions(+), 44 deletions(-) rename src/isomorphic/modern/class/{ReactComponent.js => ReactBaseClasses.js} (83%) delete mode 100644 src/isomorphic/modern/class/ReactPureComponent.js diff --git a/src/isomorphic/React.js b/src/isomorphic/React.js index f6e78d3b197bf..8203aedd39635 100644 --- a/src/isomorphic/React.js +++ b/src/isomorphic/React.js @@ -11,6 +11,7 @@ 'use strict'; +var ReactBaseClasses = require('ReactBaseClasses'); var ReactChildren = require('ReactChildren'); var ReactComponent = require('ReactComponent'); var ReactPureComponent = require('ReactPureComponent'); @@ -81,8 +82,8 @@ var React = { only: onlyChild, }, - Component: ReactComponent, - PureComponent: ReactPureComponent, + Component: ReactBaseClasses.Component, + PureComponent: ReactBaseClasses.PureComponent, createElement: createElement, cloneElement: cloneElement, diff --git a/src/isomorphic/modern/class/ReactComponent.js b/src/isomorphic/modern/class/ReactBaseClasses.js similarity index 83% rename from src/isomorphic/modern/class/ReactComponent.js rename to src/isomorphic/modern/class/ReactBaseClasses.js index aa03ca82045ce..ed8d31e9bc33e 100644 --- a/src/isomorphic/modern/class/ReactComponent.js +++ b/src/isomorphic/modern/class/ReactBaseClasses.js @@ -6,7 +6,7 @@ * 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. * - * @providesModule ReactComponent + * @providesModule ReactBaseClasses */ 'use strict'; @@ -132,4 +132,28 @@ if (__DEV__) { } } -module.exports = ReactComponent; +/** + * Base class helpers for the updating state of a component. + */ +function ReactPureComponent(props, context, updater) { + // Duplicated from ReactComponent. + this.props = props; + this.context = context; + this.refs = emptyObject; + // We initialize the default updater but the real one gets injected by the + // renderer. + this.updater = updater || ReactNoopUpdateQueue; +} + +function ComponentDummy() {} +ComponentDummy.prototype = ReactComponent.prototype; +ReactPureComponent.prototype = new ComponentDummy(); +ReactPureComponent.prototype.constructor = ReactPureComponent; +// Avoid an extra prototype jump for these methods. +Object.assign(ReactPureComponent.prototype, ReactComponent.prototype); +ReactPureComponent.prototype.isPureReactComponent = true; + +module.exports = { + Component: ReactComponent, + PureComponent: ReactPureComponent, +}; diff --git a/src/isomorphic/modern/class/ReactPureComponent.js b/src/isomorphic/modern/class/ReactPureComponent.js deleted file mode 100644 index b4a808864b9c4..0000000000000 --- a/src/isomorphic/modern/class/ReactPureComponent.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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. - * - * @providesModule ReactPureComponent - */ - -'use strict'; - -var ReactComponent = require('ReactComponent'); -var ReactNoopUpdateQueue = require('ReactNoopUpdateQueue'); - -var emptyObject = require('emptyObject'); - -/** - * Base class helpers for the updating state of a component. - */ -function ReactPureComponent(props, context, updater) { - // Duplicated from ReactComponent. - this.props = props; - this.context = context; - this.refs = emptyObject; - // We initialize the default updater but the real one gets injected by the - // renderer. - this.updater = updater || ReactNoopUpdateQueue; -} - -function ComponentDummy() {} -ComponentDummy.prototype = ReactComponent.prototype; -ReactPureComponent.prototype = new ComponentDummy(); -ReactPureComponent.prototype.constructor = ReactPureComponent; -// Avoid an extra prototype jump for these methods. -Object.assign(ReactPureComponent.prototype, ReactComponent.prototype); -ReactPureComponent.prototype.isPureReactComponent = true; - -module.exports = ReactPureComponent;