react 0.13.3 → 0.14.0-beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/README.md +5 -2
  2. package/addons.js +7 -0
  3. package/dist/JSXTransformer.js +4101 -2432
  4. package/dist/react-with-addons.js +4389 -6277
  5. package/dist/react-with-addons.min.js +6 -8
  6. package/dist/react.js +4028 -5697
  7. package/dist/react.min.js +5 -6
  8. package/lib/{AutoFocusMixin.js → AutoFocusUtils.js} +16 -5
  9. package/lib/BeforeInputEventPlugin.js +30 -118
  10. package/lib/CSSCore.js +12 -23
  11. package/lib/CSSProperty.js +4 -3
  12. package/lib/CSSPropertyOperations.js +14 -30
  13. package/lib/CallbackQueue.js +7 -10
  14. package/lib/ChangeEventPlugin.js +26 -88
  15. package/lib/ClientReactRootIndex.js +2 -2
  16. package/lib/DOMChildrenOperations.js +13 -33
  17. package/lib/DOMProperty.js +86 -147
  18. package/lib/DOMPropertyOperations.js +91 -67
  19. package/lib/Danger.js +19 -62
  20. package/lib/DefaultEventPluginOrder.js +2 -12
  21. package/lib/EnterLeaveEventPlugin.js +11 -33
  22. package/lib/EventConstants.js +2 -2
  23. package/lib/EventListener.js +11 -13
  24. package/lib/EventPluginHub.js +44 -47
  25. package/lib/EventPluginRegistry.js +18 -74
  26. package/lib/EventPluginUtils.js +33 -44
  27. package/lib/EventPropagators.js +23 -26
  28. package/lib/ExecutionEnvironment.js +4 -8
  29. package/lib/FallbackCompositionState.js +3 -3
  30. package/lib/HTMLDOMPropertyConfig.js +15 -20
  31. package/lib/LinkedStateMixin.js +3 -6
  32. package/lib/LinkedValueUtils.js +71 -89
  33. package/lib/Object.assign.js +1 -1
  34. package/lib/PooledClass.js +20 -11
  35. package/lib/React.js +9 -129
  36. package/lib/ReactBrowserComponentMixin.js +9 -2
  37. package/lib/ReactBrowserEventEmitter.js +26 -82
  38. package/lib/ReactCSSTransitionGroup.js +13 -24
  39. package/lib/ReactCSSTransitionGroupChild.js +26 -28
  40. package/lib/ReactChildReconciler.js +11 -19
  41. package/lib/ReactChildren.js +24 -31
  42. package/lib/ReactClass.js +96 -267
  43. package/lib/ReactComponent.js +28 -57
  44. package/lib/ReactComponentBrowserEnvironment.js +4 -8
  45. package/lib/ReactComponentEnvironment.js +6 -12
  46. package/lib/ReactComponentWithPureRenderMixin.js +6 -7
  47. package/lib/ReactCompositeComponent.js +115 -381
  48. package/lib/ReactCurrentOwner.js +1 -3
  49. package/lib/ReactDOM.js +4 -2
  50. package/lib/ReactDOMButton.js +16 -28
  51. package/lib/ReactDOMClient.js +90 -0
  52. package/lib/ReactDOMComponent.js +468 -156
  53. package/lib/ReactDOMIDOperations.js +25 -22
  54. package/lib/ReactDOMInput.js +79 -108
  55. package/lib/ReactDOMOption.js +58 -20
  56. package/lib/ReactDOMSelect.js +95 -83
  57. package/lib/ReactDOMSelection.js +5 -20
  58. package/lib/ReactDOMServer.js +24 -0
  59. package/lib/ReactDOMTextComponent.js +17 -18
  60. package/lib/ReactDOMTextarea.js +44 -69
  61. package/lib/ReactDefaultBatchingStrategy.js +9 -13
  62. package/lib/ReactDefaultInjection.js +20 -76
  63. package/lib/ReactDefaultPerf.js +36 -69
  64. package/lib/ReactDefaultPerfAnalysis.js +8 -14
  65. package/lib/ReactElement.js +26 -120
  66. package/lib/ReactElementValidator.js +56 -192
  67. package/lib/ReactEmptyComponent.js +7 -11
  68. package/lib/ReactErrorUtils.js +3 -3
  69. package/lib/ReactEventEmitterMixin.js +3 -13
  70. package/lib/ReactEventListener.js +58 -40
  71. package/lib/ReactFragment.js +33 -59
  72. package/lib/ReactInjection.js +1 -1
  73. package/lib/ReactInputSelection.js +14 -23
  74. package/lib/ReactInstanceHandles.js +29 -58
  75. package/lib/ReactInstanceMap.js +5 -5
  76. package/lib/ReactIsomorphic.js +70 -0
  77. package/lib/ReactLink.js +2 -4
  78. package/lib/ReactMarkupChecksum.js +5 -10
  79. package/lib/ReactMount.js +142 -285
  80. package/lib/ReactMultiChild.js +19 -45
  81. package/lib/ReactMultiChildUpdateTypes.js +1 -1
  82. package/lib/ReactNativeComponent.js +6 -15
  83. package/lib/ReactNoopUpdateQueue.js +118 -0
  84. package/lib/ReactOwner.js +7 -24
  85. package/lib/ReactPerf.js +8 -12
  86. package/lib/ReactPropTransferer.js +4 -4
  87. package/lib/ReactPropTypeLocationNames.js +2 -2
  88. package/lib/ReactPropTypeLocations.js +1 -1
  89. package/lib/ReactPropTypes.js +41 -61
  90. package/lib/ReactReconcileTransaction.js +11 -36
  91. package/lib/ReactReconciler.js +14 -26
  92. package/lib/ReactRef.js +5 -8
  93. package/lib/ReactRootIndex.js +2 -2
  94. package/lib/ReactServerBatchingStrategy.js +23 -0
  95. package/lib/ReactServerRendering.js +20 -15
  96. package/lib/ReactServerRenderingTransaction.js +9 -34
  97. package/lib/ReactStateSetters.js +6 -6
  98. package/lib/ReactTestUtils.js +137 -190
  99. package/lib/ReactTransitionChildMapping.js +5 -7
  100. package/lib/ReactTransitionEvents.js +5 -5
  101. package/lib/ReactTransitionGroup.js +30 -52
  102. package/lib/ReactUpdateQueue.js +69 -107
  103. package/lib/ReactUpdates.js +26 -81
  104. package/lib/ReactWithAddons.js +5 -6
  105. package/lib/SVGDOMPropertyConfig.js +39 -4
  106. package/lib/SelectEventPlugin.js +31 -33
  107. package/lib/ServerReactRootIndex.js +2 -2
  108. package/lib/SimpleEventPlugin.js +138 -130
  109. package/lib/SyntheticClipboardEvent.js +5 -9
  110. package/lib/SyntheticCompositionEvent.js +4 -10
  111. package/lib/SyntheticDragEvent.js +3 -3
  112. package/lib/SyntheticEvent.js +14 -15
  113. package/lib/SyntheticFocusEvent.js +3 -3
  114. package/lib/SyntheticInputEvent.js +4 -10
  115. package/lib/SyntheticKeyboardEvent.js +6 -6
  116. package/lib/SyntheticMouseEvent.js +10 -16
  117. package/lib/SyntheticTouchEvent.js +3 -3
  118. package/lib/SyntheticUIEvent.js +5 -5
  119. package/lib/SyntheticWheelEvent.js +13 -17
  120. package/lib/Transaction.js +22 -28
  121. package/lib/ViewportMetrics.js +2 -2
  122. package/lib/accumulateInto.js +2 -5
  123. package/lib/adler32.js +2 -4
  124. package/lib/camelize.js +4 -2
  125. package/lib/camelizeStyleName.js +2 -2
  126. package/lib/cloneWithProps.js +6 -12
  127. package/lib/containsNode.js +29 -16
  128. package/lib/createArrayFromMixed.js +17 -16
  129. package/lib/createNodesFromMarkup.js +6 -8
  130. package/lib/dangerousStyleValue.js +2 -3
  131. package/lib/deprecated.js +47 -0
  132. package/lib/emptyFunction.js +10 -4
  133. package/lib/emptyObject.js +1 -1
  134. package/lib/escapeTextContentForBrowser.js +1 -1
  135. package/lib/findDOMNode.js +7 -27
  136. package/lib/flattenChildren.js +4 -10
  137. package/lib/focusNode.js +2 -3
  138. package/lib/forEachAccumulated.js +3 -3
  139. package/lib/getActiveElement.js +4 -2
  140. package/lib/getEventCharCode.js +2 -2
  141. package/lib/getEventKey.js +1 -1
  142. package/lib/getEventModifierState.js +1 -2
  143. package/lib/getEventTarget.js +1 -1
  144. package/lib/getIteratorFn.js +2 -4
  145. package/lib/getMarkupWrap.js +18 -40
  146. package/lib/getNodeForCharacterOffset.js +1 -1
  147. package/lib/getTextContentAccessor.js +2 -4
  148. package/lib/getUnboundedScrollPosition.js +1 -1
  149. package/lib/hyphenate.js +3 -1
  150. package/lib/hyphenateStyleName.js +2 -2
  151. package/lib/instantiateReactComponent.js +23 -43
  152. package/lib/invariant.js +8 -12
  153. package/lib/isEventSupported.js +7 -10
  154. package/lib/isNode.js +4 -6
  155. package/lib/isTextInputElement.js +3 -4
  156. package/lib/isTextNode.js +3 -1
  157. package/lib/joinClasses.js +3 -3
  158. package/lib/keyMirror.js +3 -6
  159. package/lib/keyOf.js +4 -3
  160. package/lib/mapObject.js +1 -1
  161. package/lib/memoizeStringOnly.js +2 -2
  162. package/lib/onlyChild.js +2 -5
  163. package/lib/performance.js +2 -5
  164. package/lib/performanceNow.js +3 -1
  165. package/lib/quoteAttributeValueForBrowser.js +1 -1
  166. package/lib/renderSubtreeIntoContainer.js +16 -0
  167. package/lib/setInnerHTML.js +11 -8
  168. package/lib/setTextContent.js +3 -3
  169. package/lib/shallowCompare.js +24 -0
  170. package/lib/shallowEqual.js +17 -11
  171. package/lib/shouldUpdateReactComponent.js +3 -64
  172. package/lib/toArray.js +8 -19
  173. package/lib/traverseAllChildren.js +23 -90
  174. package/lib/update.js +25 -85
  175. package/lib/validateDOMNesting.js +363 -0
  176. package/lib/warning.js +15 -17
  177. package/package.json +3 -3
  178. package/react.js +53 -1
  179. package/lib/LocalEventTrapMixin.js +0 -53
  180. package/lib/MobileSafariClickEventPlugin.js +0 -56
  181. package/lib/ReactContext.js +0 -74
  182. package/lib/ReactDOMForm.js +0 -47
  183. package/lib/ReactDOMIframe.js +0 -43
  184. package/lib/ReactDOMImg.js +0 -44
  185. package/lib/ReactLifeCycle.js +0 -35
  186. package/lib/ReactPutListenerQueue.js +0 -54
  187. package/lib/createFullPageComponent.js +0 -58
  188. package/lib/cx.js +0 -52
  189. package/lib/getReactRootElementInContainer.js +0 -33
@@ -32,7 +32,7 @@ var ReactDefaultPerf = {
32
32
  _mountStack: [0],
33
33
  _injected: false,
34
34
 
35
- start: function() {
35
+ start: function () {
36
36
  if (!ReactDefaultPerf._injected) {
37
37
  ReactPerf.injection.injectMeasure(ReactDefaultPerf.measure);
38
38
  }
@@ -41,18 +41,18 @@ var ReactDefaultPerf = {
41
41
  ReactPerf.enableMeasure = true;
42
42
  },
43
43
 
44
- stop: function() {
44
+ stop: function () {
45
45
  ReactPerf.enableMeasure = false;
46
46
  },
47
47
 
48
- getLastMeasurements: function() {
48
+ getLastMeasurements: function () {
49
49
  return ReactDefaultPerf._allMeasurements;
50
50
  },
51
51
 
52
- printExclusive: function(measurements) {
52
+ printExclusive: function (measurements) {
53
53
  measurements = measurements || ReactDefaultPerf._allMeasurements;
54
54
  var summary = ReactDefaultPerfAnalysis.getExclusiveSummary(measurements);
55
- console.table(summary.map(function(item) {
55
+ console.table(summary.map(function (item) {
56
56
  return {
57
57
  'Component class name': item.componentName,
58
58
  'Total inclusive time (ms)': roundFloat(item.inclusive),
@@ -67,28 +67,22 @@ var ReactDefaultPerf = {
67
67
  // number.
68
68
  },
69
69
 
70
- printInclusive: function(measurements) {
70
+ printInclusive: function (measurements) {
71
71
  measurements = measurements || ReactDefaultPerf._allMeasurements;
72
72
  var summary = ReactDefaultPerfAnalysis.getInclusiveSummary(measurements);
73
- console.table(summary.map(function(item) {
73
+ console.table(summary.map(function (item) {
74
74
  return {
75
75
  'Owner > component': item.componentName,
76
76
  'Inclusive time (ms)': roundFloat(item.time),
77
77
  'Instances': item.count
78
78
  };
79
79
  }));
80
- console.log(
81
- 'Total time:',
82
- ReactDefaultPerfAnalysis.getTotalTime(measurements).toFixed(2) + ' ms'
83
- );
80
+ console.log('Total time:', ReactDefaultPerfAnalysis.getTotalTime(measurements).toFixed(2) + ' ms');
84
81
  },
85
82
 
86
- getMeasurementsSummaryMap: function(measurements) {
87
- var summary = ReactDefaultPerfAnalysis.getInclusiveSummary(
88
- measurements,
89
- true
90
- );
91
- return summary.map(function(item) {
83
+ getMeasurementsSummaryMap: function (measurements) {
84
+ var summary = ReactDefaultPerfAnalysis.getInclusiveSummary(measurements, true);
85
+ return summary.map(function (item) {
92
86
  return {
93
87
  'Owner > component': item.componentName,
94
88
  'Wasted time (ms)': item.time,
@@ -97,37 +91,28 @@ var ReactDefaultPerf = {
97
91
  });
98
92
  },
99
93
 
100
- printWasted: function(measurements) {
94
+ printWasted: function (measurements) {
101
95
  measurements = measurements || ReactDefaultPerf._allMeasurements;
102
96
  console.table(ReactDefaultPerf.getMeasurementsSummaryMap(measurements));
103
- console.log(
104
- 'Total time:',
105
- ReactDefaultPerfAnalysis.getTotalTime(measurements).toFixed(2) + ' ms'
106
- );
97
+ console.log('Total time:', ReactDefaultPerfAnalysis.getTotalTime(measurements).toFixed(2) + ' ms');
107
98
  },
108
99
 
109
- printDOM: function(measurements) {
100
+ printDOM: function (measurements) {
110
101
  measurements = measurements || ReactDefaultPerf._allMeasurements;
111
102
  var summary = ReactDefaultPerfAnalysis.getDOMSummary(measurements);
112
- console.table(summary.map(function(item) {
103
+ console.table(summary.map(function (item) {
113
104
  var result = {};
114
105
  result[DOMProperty.ID_ATTRIBUTE_NAME] = item.id;
115
106
  result['type'] = item.type;
116
107
  result['args'] = JSON.stringify(item.args);
117
108
  return result;
118
109
  }));
119
- console.log(
120
- 'Total time:',
121
- ReactDefaultPerfAnalysis.getTotalTime(measurements).toFixed(2) + ' ms'
122
- );
110
+ console.log('Total time:', ReactDefaultPerfAnalysis.getTotalTime(measurements).toFixed(2) + ' ms');
123
111
  },
124
112
 
125
- _recordWrite: function(id, fnName, totalTime, args) {
113
+ _recordWrite: function (id, fnName, totalTime, args) {
126
114
  // TODO: totalTime isn't that useful since it doesn't count paints/reflows
127
- var writes =
128
- ReactDefaultPerf
129
- ._allMeasurements[ReactDefaultPerf._allMeasurements.length - 1]
130
- .writes;
115
+ var writes = ReactDefaultPerf._allMeasurements[ReactDefaultPerf._allMeasurements.length - 1].writes;
131
116
  writes[id] = writes[id] || [];
132
117
  writes[id].push({
133
118
  type: fnName,
@@ -136,14 +121,17 @@ var ReactDefaultPerf = {
136
121
  });
137
122
  },
138
123
 
139
- measure: function(moduleName, fnName, func) {
140
- return function() {for (var args=[],$__0=0,$__1=arguments.length;$__0<$__1;$__0++) args.push(arguments[$__0]);
124
+ measure: function (moduleName, fnName, func) {
125
+ return function () {
126
+ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
127
+ args[_key] = arguments[_key];
128
+ }
129
+
141
130
  var totalTime;
142
131
  var rv;
143
132
  var start;
144
133
 
145
- if (fnName === '_renderNewRootComponent' ||
146
- fnName === 'flushBatchedUpdates') {
134
+ if (fnName === '_renderNewRootComponent' || fnName === 'flushBatchedUpdates') {
147
135
  // A "measurement" is a set of metrics recorded for each flush. We want
148
136
  // to group the metrics for a given flush together so we can look at the
149
137
  // components that rendered and the DOM operations that actually
@@ -159,12 +147,9 @@ var ReactDefaultPerf = {
159
147
  });
160
148
  start = performanceNow();
161
149
  rv = func.apply(this, args);
162
- ReactDefaultPerf._allMeasurements[
163
- ReactDefaultPerf._allMeasurements.length - 1
164
- ].totalTime = performanceNow() - start;
150
+ ReactDefaultPerf._allMeasurements[ReactDefaultPerf._allMeasurements.length - 1].totalTime = performanceNow() - start;
165
151
  return rv;
166
- } else if (fnName === '_mountImageIntoNode' ||
167
- moduleName === 'ReactDOMIDOperations') {
152
+ } else if (fnName === '_mountImageIntoNode' || moduleName === 'ReactDOMIDOperations') {
168
153
  start = performanceNow();
169
154
  rv = func.apply(this, args);
170
155
  totalTime = performanceNow() - start;
@@ -174,7 +159,7 @@ var ReactDefaultPerf = {
174
159
  ReactDefaultPerf._recordWrite(mountID, fnName, totalTime, args[0]);
175
160
  } else if (fnName === 'dangerouslyProcessChildrenUpdates') {
176
161
  // special format
177
- args[0].forEach(function(update) {
162
+ args[0].forEach(function (update) {
178
163
  var writeArgs = {};
179
164
  if (update.fromIndex !== null) {
180
165
  writeArgs.fromIndex = update.fromIndex;
@@ -188,42 +173,26 @@ var ReactDefaultPerf = {
188
173
  if (update.markupIndex !== null) {
189
174
  writeArgs.markup = args[1][update.markupIndex];
190
175
  }
191
- ReactDefaultPerf._recordWrite(
192
- update.parentID,
193
- update.type,
194
- totalTime,
195
- writeArgs
196
- );
176
+ ReactDefaultPerf._recordWrite(update.parentID, update.type, totalTime, writeArgs);
197
177
  });
198
178
  } else {
199
179
  // basic format
200
- ReactDefaultPerf._recordWrite(
201
- args[0],
202
- fnName,
203
- totalTime,
204
- Array.prototype.slice.call(args, 1)
205
- );
180
+ ReactDefaultPerf._recordWrite(args[0], fnName, totalTime, Array.prototype.slice.call(args, 1));
206
181
  }
207
182
  return rv;
208
- } else if (moduleName === 'ReactCompositeComponent' && (
209
- (// TODO: receiveComponent()?
210
- (fnName === 'mountComponent' ||
211
- fnName === 'updateComponent' || fnName === '_renderValidatedComponent')))) {
183
+ } else if (moduleName === 'ReactCompositeComponent' && (fnName === 'mountComponent' || fnName === 'updateComponent' || // TODO: receiveComponent()?
184
+ fnName === '_renderValidatedComponent')) {
212
185
 
213
186
  if (typeof this._currentElement.type === 'string') {
214
187
  return func.apply(this, args);
215
188
  }
216
189
 
217
- var rootNodeID = fnName === 'mountComponent' ?
218
- args[0] :
219
- this._rootNodeID;
190
+ var rootNodeID = fnName === 'mountComponent' ? args[0] : this._rootNodeID;
220
191
  var isRender = fnName === '_renderValidatedComponent';
221
192
  var isMount = fnName === 'mountComponent';
222
193
 
223
194
  var mountStack = ReactDefaultPerf._mountStack;
224
- var entry = ReactDefaultPerf._allMeasurements[
225
- ReactDefaultPerf._allMeasurements.length - 1
226
- ];
195
+ var entry = ReactDefaultPerf._allMeasurements[ReactDefaultPerf._allMeasurements.length - 1];
227
196
 
228
197
  if (isRender) {
229
198
  addValue(entry.counts, rootNodeID, 1);
@@ -248,9 +217,7 @@ var ReactDefaultPerf = {
248
217
 
249
218
  entry.displayNames[rootNodeID] = {
250
219
  current: this.getName(),
251
- owner: this._currentElement._owner ?
252
- this._currentElement._owner.getName() :
253
- '<root>'
220
+ owner: this._currentElement._owner ? this._currentElement._owner.getName() : '<root>'
254
221
  };
255
222
 
256
223
  return rv;
@@ -261,4 +228,4 @@ var ReactDefaultPerf = {
261
228
  }
262
229
  };
263
230
 
264
- module.exports = ReactDefaultPerf;
231
+ module.exports = ReactDefaultPerf;
@@ -9,6 +9,8 @@
9
9
  * @providesModule ReactDefaultPerfAnalysis
10
10
  */
11
11
 
12
+ 'use strict';
13
+
12
14
  var assign = require("./Object.assign");
13
15
 
14
16
  // Don't try to save users less than 1.2ms (a number I made up)
@@ -46,7 +48,7 @@ function getDOMSummary(measurements) {
46
48
  var id;
47
49
 
48
50
  for (id in measurement.writes) {
49
- measurement.writes[id].forEach(function(write) {
51
+ measurement.writes[id].forEach(function (write) {
50
52
  items.push({
51
53
  id: id,
52
54
  type: DOM_OPERATION_TYPES[write.type] || write.type,
@@ -64,11 +66,7 @@ function getExclusiveSummary(measurements) {
64
66
 
65
67
  for (var i = 0; i < measurements.length; i++) {
66
68
  var measurement = measurements[i];
67
- var allIDs = assign(
68
- {},
69
- measurement.exclusive,
70
- measurement.inclusive
71
- );
69
+ var allIDs = assign({}, measurement.exclusive, measurement.inclusive);
72
70
 
73
71
  for (var id in allIDs) {
74
72
  displayName = measurement.displayNames[id].current;
@@ -103,7 +101,7 @@ function getExclusiveSummary(measurements) {
103
101
  }
104
102
  }
105
103
 
106
- arr.sort(function(a, b) {
104
+ arr.sort(function (a, b) {
107
105
  return b.exclusive - a.exclusive;
108
106
  });
109
107
 
@@ -116,11 +114,7 @@ function getInclusiveSummary(measurements, onlyClean) {
116
114
 
117
115
  for (var i = 0; i < measurements.length; i++) {
118
116
  var measurement = measurements[i];
119
- var allIDs = assign(
120
- {},
121
- measurement.exclusive,
122
- measurement.inclusive
123
- );
117
+ var allIDs = assign({}, measurement.exclusive, measurement.inclusive);
124
118
  var cleanComponents;
125
119
 
126
120
  if (onlyClean) {
@@ -162,7 +156,7 @@ function getInclusiveSummary(measurements, onlyClean) {
162
156
  }
163
157
  }
164
158
 
165
- arr.sort(function(a, b) {
159
+ arr.sort(function (a, b) {
166
160
  return b.time - a.time;
167
161
  });
168
162
 
@@ -201,4 +195,4 @@ var ReactDefaultPerfAnalysis = {
201
195
  getTotalTime: getTotalTime
202
196
  };
203
197
 
204
- module.exports = ReactDefaultPerfAnalysis;
198
+ module.exports = ReactDefaultPerfAnalysis;
@@ -11,86 +11,27 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- var ReactContext = require("./ReactContext");
15
14
  var ReactCurrentOwner = require("./ReactCurrentOwner");
16
15
 
17
16
  var assign = require("./Object.assign");
18
- var warning = require("./warning");
19
17
 
20
18
  var RESERVED_PROPS = {
21
19
  key: true,
22
20
  ref: true
23
21
  };
24
22
 
25
- /**
26
- * Warn for mutations.
27
- *
28
- * @internal
29
- * @param {object} object
30
- * @param {string} key
31
- */
32
- function defineWarningProperty(object, key) {
33
- Object.defineProperty(object, key, {
34
-
35
- configurable: false,
36
- enumerable: true,
37
-
38
- get: function() {
39
- if (!this._store) {
40
- return null;
41
- }
42
- return this._store[key];
43
- },
44
-
45
- set: function(value) {
46
- ("production" !== process.env.NODE_ENV ? warning(
47
- false,
48
- 'Don\'t set the %s property of the React element. Instead, ' +
49
- 'specify the correct value when initially creating the element.',
50
- key
51
- ) : null);
52
- this._store[key] = value;
53
- }
54
-
55
- });
56
- }
57
-
58
- /**
59
- * This is updated to true if the membrane is successfully created.
60
- */
61
- var useMutationMembrane = false;
62
-
63
- /**
64
- * Warn for mutations.
65
- *
66
- * @internal
67
- * @param {object} element
68
- */
69
- function defineMutationMembrane(prototype) {
70
- try {
71
- var pseudoFrozenProperties = {
72
- props: true
73
- };
74
- for (var key in pseudoFrozenProperties) {
75
- defineWarningProperty(prototype, key);
76
- }
77
- useMutationMembrane = true;
78
- } catch (x) {
79
- // IE will fail on defineProperty
80
- }
81
- }
82
-
83
23
  /**
84
24
  * Base constructor for all React elements. This is only used to make this
85
25
  * work with a dynamic instanceof check. Nothing should live on this prototype.
86
26
  *
87
27
  * @param {*} type
88
- * @param {string|object} ref
89
28
  * @param {*} key
29
+ * @param {string|object} ref
30
+ * @param {*} owner
90
31
  * @param {*} props
91
32
  * @internal
92
33
  */
93
- var ReactElement = function(type, key, ref, owner, context, props) {
34
+ var ReactElement = function (type, key, ref, owner, props) {
94
35
  // Built-in properties that belong on the element
95
36
  this.type = type;
96
37
  this.key = key;
@@ -99,16 +40,14 @@ var ReactElement = function(type, key, ref, owner, context, props) {
99
40
  // Record the component responsible for creating this element.
100
41
  this._owner = owner;
101
42
 
102
- // TODO: Deprecate withContext, and then the context becomes accessible
103
- // through the owner.
104
- this._context = context;
43
+ this.props = props;
105
44
 
106
- if ("production" !== process.env.NODE_ENV) {
107
- // The validation flag and props are currently mutative. We put them on
45
+ if ('production' !== process.env.NODE_ENV) {
46
+ // The validation flag is currently mutative. We put it on
108
47
  // an external backing store so that we can freeze the whole object.
109
48
  // This can be replaced with a WeakMap once they are implemented in
110
49
  // commonly used development environments.
111
- this._store = {props: props, originalProps: assign({}, props)};
50
+ this._store = {};
112
51
 
113
52
  // To make comparing ReactElements easier for testing purposes, we make
114
53
  // the validation flag non-enumerable (where possible, which should
@@ -118,22 +57,15 @@ var ReactElement = function(type, key, ref, owner, context, props) {
118
57
  Object.defineProperty(this._store, 'validated', {
119
58
  configurable: false,
120
59
  enumerable: false,
121
- writable: true
60
+ writable: true,
61
+ value: false
122
62
  });
123
63
  } catch (x) {
64
+ this._store.validated = false;
124
65
  }
125
- this._store.validated = false;
126
-
127
- // We're not allowed to set props directly on the object so we early
128
- // return and rely on the prototype membrane to forward to the backing
129
- // store.
130
- if (useMutationMembrane) {
131
- Object.freeze(this);
132
- return;
133
- }
66
+ Object.freeze(this.props);
67
+ Object.freeze(this);
134
68
  }
135
-
136
- this.props = props;
137
69
  };
138
70
 
139
71
  // We intentionally don't expose the function on the constructor property.
@@ -142,11 +74,7 @@ ReactElement.prototype = {
142
74
  _isReactElement: true
143
75
  };
144
76
 
145
- if ("production" !== process.env.NODE_ENV) {
146
- defineMutationMembrane(ReactElement.prototype);
147
- }
148
-
149
- ReactElement.createElement = function(type, config, children) {
77
+ ReactElement.createElement = function (type, config, children) {
150
78
  var propName;
151
79
 
152
80
  // Reserved names are extracted
@@ -160,8 +88,7 @@ ReactElement.createElement = function(type, config, children) {
160
88
  key = config.key === undefined ? null : '' + config.key;
161
89
  // Remaining properties are added to a new props object
162
90
  for (propName in config) {
163
- if (config.hasOwnProperty(propName) &&
164
- !RESERVED_PROPS.hasOwnProperty(propName)) {
91
+ if (config.hasOwnProperty(propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
165
92
  props[propName] = config[propName];
166
93
  }
167
94
  }
@@ -190,20 +117,13 @@ ReactElement.createElement = function(type, config, children) {
190
117
  }
191
118
  }
192
119
 
193
- return new ReactElement(
194
- type,
195
- key,
196
- ref,
197
- ReactCurrentOwner.current,
198
- ReactContext.current,
199
- props
200
- );
120
+ return new ReactElement(type, key, ref, ReactCurrentOwner.current, props);
201
121
  };
202
122
 
203
- ReactElement.createFactory = function(type) {
123
+ ReactElement.createFactory = function (type) {
204
124
  var factory = ReactElement.createElement.bind(null, type);
205
125
  // Expose the type on the factory and the prototype so that it can be
206
- // easily accessed on elements. E.g. <Foo />.type === Foo.type.
126
+ // easily accessed on elements. E.g. `<Foo />.type === Foo`.
207
127
  // This should not be named `constructor` since this may not be the function
208
128
  // that created the element, and it may not even be a constructor.
209
129
  // Legacy hook TODO: Warn if this is accessed
@@ -211,24 +131,18 @@ ReactElement.createFactory = function(type) {
211
131
  return factory;
212
132
  };
213
133
 
214
- ReactElement.cloneAndReplaceProps = function(oldElement, newProps) {
215
- var newElement = new ReactElement(
216
- oldElement.type,
217
- oldElement.key,
218
- oldElement.ref,
219
- oldElement._owner,
220
- oldElement._context,
221
- newProps
222
- );
134
+ ReactElement.cloneAndReplaceProps = function (oldElement, newProps) {
135
+ var newElement = new ReactElement(oldElement.type, oldElement.key, oldElement.ref, oldElement._owner, newProps);
223
136
 
224
- if ("production" !== process.env.NODE_ENV) {
137
+ if ('production' !== process.env.NODE_ENV) {
225
138
  // If the key on the original is valid, then the clone is valid
226
139
  newElement._store.validated = oldElement._store.validated;
227
140
  }
141
+
228
142
  return newElement;
229
143
  };
230
144
 
231
- ReactElement.cloneElement = function(element, config, children) {
145
+ ReactElement.cloneElement = function (element, config, children) {
232
146
  var propName;
233
147
 
234
148
  // Original props are copied
@@ -252,8 +166,7 @@ ReactElement.cloneElement = function(element, config, children) {
252
166
  }
253
167
  // Remaining properties override existing props
254
168
  for (propName in config) {
255
- if (config.hasOwnProperty(propName) &&
256
- !RESERVED_PROPS.hasOwnProperty(propName)) {
169
+ if (config.hasOwnProperty(propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
257
170
  props[propName] = config[propName];
258
171
  }
259
172
  }
@@ -272,14 +185,7 @@ ReactElement.cloneElement = function(element, config, children) {
272
185
  props.children = childArray;
273
186
  }
274
187
 
275
- return new ReactElement(
276
- element.type,
277
- key,
278
- ref,
279
- owner,
280
- element._context,
281
- props
282
- );
188
+ return new ReactElement(element.type, key, ref, owner, props);
283
189
  };
284
190
 
285
191
  /**
@@ -287,7 +193,7 @@ ReactElement.cloneElement = function(element, config, children) {
287
193
  * @return {boolean} True if `object` is a valid component.
288
194
  * @final
289
195
  */
290
- ReactElement.isValidElement = function(object) {
196
+ ReactElement.isValidElement = function (object) {
291
197
  // ReactTestUtils is often used outside of beforeEach where as React is
292
198
  // within it. This leads to two different instances of React on the same
293
199
  // page. To identify a element from a different React instance we use
@@ -301,4 +207,4 @@ ReactElement.isValidElement = function(object) {
301
207
  return isElement;
302
208
  };
303
209
 
304
- module.exports = ReactElement;
210
+ module.exports = ReactElement;