-
Notifications
You must be signed in to change notification settings - Fork 45.6k
/
React.js
151 lines (131 loc) · 4.66 KB
/
React.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* 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 React
*/
'use strict';
var ReactChildren = require('ReactChildren');
var ReactComponent = require('ReactComponent');
var ReactPureComponent = require('ReactPureComponent');
var ReactClass = require('ReactClass');
var ReactDOMFactories = require('ReactDOMFactories');
var ReactElement = require('ReactElement');
var ReactPropTypes = require('ReactPropTypes');
var ReactVersion = require('ReactVersion');
var onlyChild = require('onlyChild');
var createElement = ReactElement.createElement;
var createFactory = ReactElement.createFactory;
var cloneElement = ReactElement.cloneElement;
if (__DEV__) {
var lowPriorityWarning = require('lowPriorityWarning');
var canDefineProperty = require('canDefineProperty');
var ReactElementValidator = require('ReactElementValidator');
var didWarnPropTypesDeprecated = false;
createElement = ReactElementValidator.createElement;
createFactory = ReactElementValidator.createFactory;
cloneElement = ReactElementValidator.cloneElement;
}
var __spread = Object.assign;
var createMixin = function(mixin) {
return mixin;
};
if (__DEV__) {
var warnedForSpread = false;
var warnedForCreateMixin = false;
__spread = function() {
lowPriorityWarning(
warnedForSpread,
'React.__spread is deprecated and should not be used. Use ' +
'Object.assign directly or another helper function with similar ' +
'semantics. You may be seeing this warning due to your compiler. ' +
'See https://fb.me/react-spread-deprecation for more details.',
);
warnedForSpread = true;
return Object.assign.apply(null, arguments);
};
createMixin = function(mixin) {
lowPriorityWarning(
warnedForCreateMixin,
'React.createMixin is deprecated and should not be used. ' +
'In React v16.0, it will be removed. ' +
'You can use this mixin directly instead. ' +
'See https://fb.me/createmixin-was-never-implemented for more info.',
);
warnedForCreateMixin = true;
return mixin;
};
}
var React = {
// Modern
Children: {
map: ReactChildren.map,
forEach: ReactChildren.forEach,
count: ReactChildren.count,
toArray: ReactChildren.toArray,
only: onlyChild,
},
Component: ReactComponent,
PureComponent: ReactPureComponent,
createElement: createElement,
cloneElement: cloneElement,
isValidElement: ReactElement.isValidElement,
// Classic
PropTypes: ReactPropTypes,
createClass: ReactClass.createClass,
createFactory: createFactory,
createMixin: createMixin,
// This looks DOM specific but these are actually isomorphic helpers
// since they are just generating DOM strings.
DOM: ReactDOMFactories,
version: ReactVersion,
// Deprecated hook for JSX spread, don't use this for anything.
__spread: __spread,
};
// TODO: Fix tests so that this deprecation warning doesn't cause failures.
if (__DEV__) {
if (canDefineProperty) {
Object.defineProperty(React, 'PropTypes', {
get() {
lowPriorityWarning(
didWarnPropTypesDeprecated,
'Accessing PropTypes via the main React package is deprecated,' +
' and will be removed in React v16.0.' +
' Use the prop-types package from npm instead.' +
' Version 15.5.10 provides a drop-in replacement.' +
' For info on usage, compatibility, migration and more, see ' +
'https://fb.me/prop-types-docs',
);
didWarnPropTypesDeprecated = true;
return ReactPropTypes;
},
});
}
// React.DOM factories are deprecated. Wrap these methods so that
// invocations of the React.DOM namespace and alert users to switch
// to the `react-addons-dom-factories` package.
React.DOM = {};
var warnedForFactories = false;
Object.keys(ReactDOMFactories).forEach(function(factory) {
React.DOM[factory] = function(...args) {
if (!warnedForFactories) {
lowPriorityWarning(
false,
'Accessing factories like React.DOM.%s has been deprecated ' +
'and will be removed in v16.0+. Use the ' +
'react-addons-dom-factories package instead. ' +
' Version 1.0 provides a drop-in replacement.' +
' For more info, see https://fb.me/react-addons-dom-factories',
factory,
);
warnedForFactories = true;
}
return ReactDOMFactories[factory](...args);
};
});
}
module.exports = React;