Skip to content

Commit 3d1062b

Browse files
gaearonflarnie
authored andcommitted
Move component base classes into a single file (#8918)
1 parent 68d3370 commit 3d1062b

File tree

3 files changed

+29
-44
lines changed

3 files changed

+29
-44
lines changed

src/isomorphic/React.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
'use strict';
1313

14+
var ReactBaseClasses = require('ReactBaseClasses');
1415
var ReactChildren = require('ReactChildren');
1516
var ReactComponent = require('ReactComponent');
1617
var ReactPureComponent = require('ReactPureComponent');
@@ -81,8 +82,8 @@ var React = {
8182
only: onlyChild,
8283
},
8384

84-
Component: ReactComponent,
85-
PureComponent: ReactPureComponent,
85+
Component: ReactBaseClasses.Component,
86+
PureComponent: ReactBaseClasses.PureComponent,
8687

8788
createElement: createElement,
8889
cloneElement: cloneElement,

src/isomorphic/modern/class/ReactComponent.js renamed to src/isomorphic/modern/class/ReactBaseClasses.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*
9-
* @providesModule ReactComponent
9+
* @providesModule ReactBaseClasses
1010
*/
1111

1212
'use strict';
@@ -132,4 +132,28 @@ if (__DEV__) {
132132
}
133133
}
134134

135-
module.exports = ReactComponent;
135+
/**
136+
* Base class helpers for the updating state of a component.
137+
*/
138+
function ReactPureComponent(props, context, updater) {
139+
// Duplicated from ReactComponent.
140+
this.props = props;
141+
this.context = context;
142+
this.refs = emptyObject;
143+
// We initialize the default updater but the real one gets injected by the
144+
// renderer.
145+
this.updater = updater || ReactNoopUpdateQueue;
146+
}
147+
148+
function ComponentDummy() {}
149+
ComponentDummy.prototype = ReactComponent.prototype;
150+
ReactPureComponent.prototype = new ComponentDummy();
151+
ReactPureComponent.prototype.constructor = ReactPureComponent;
152+
// Avoid an extra prototype jump for these methods.
153+
Object.assign(ReactPureComponent.prototype, ReactComponent.prototype);
154+
ReactPureComponent.prototype.isPureReactComponent = true;
155+
156+
module.exports = {
157+
Component: ReactComponent,
158+
PureComponent: ReactPureComponent,
159+
};

src/isomorphic/modern/class/ReactPureComponent.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)