react 15.0.2 → 15.1.0

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 (56) hide show
  1. package/dist/react-with-addons.js +1545 -918
  2. package/dist/react-with-addons.min.js +6 -6
  3. package/dist/react.js +1515 -1339
  4. package/dist/react.min.js +6 -6
  5. package/lib/CSSPropertyOperations.js +5 -5
  6. package/lib/DOMChildrenOperations.js +41 -6
  7. package/lib/DOMLazyTree.js +15 -3
  8. package/lib/DOMPropertyOperations.js +22 -13
  9. package/lib/LinkedStateMixin.js +1 -0
  10. package/lib/ReactCSSTransitionGroup.js +5 -0
  11. package/lib/ReactChildren.js +9 -1
  12. package/lib/ReactClass.js +1 -0
  13. package/lib/ReactComponentBrowserEnvironment.js +0 -5
  14. package/lib/ReactComponentTreeDevtool.js +145 -0
  15. package/lib/ReactComponentWithPureRenderMixin.js +2 -0
  16. package/lib/ReactCompositeComponent.js +147 -18
  17. package/lib/ReactDOM.js +1 -4
  18. package/lib/ReactDOMComponent.js +51 -11
  19. package/lib/ReactDOMIDOperations.js +0 -5
  20. package/lib/ReactDOMInput.js +5 -3
  21. package/lib/ReactDOMTextComponent.js +7 -6
  22. package/lib/ReactDebugTool.js +188 -10
  23. package/lib/ReactDefaultInjection.js +0 -9
  24. package/lib/ReactElement.js +26 -0
  25. package/lib/ReactFragment.js +5 -2
  26. package/lib/ReactInjection.js +0 -2
  27. package/lib/ReactLink.js +3 -0
  28. package/lib/ReactMount.js +22 -7
  29. package/lib/ReactMultiChild.js +21 -0
  30. package/lib/ReactNativeAttributePayload.js +7 -36
  31. package/lib/{IOSNativeBridgeEventPlugin.js → ReactNativeBridgeEventPlugin.js} +8 -5
  32. package/lib/ReactNativeDOMIDOperations.js +3 -6
  33. package/lib/ReactNativeDefaultInjection.js +15 -12
  34. package/lib/ReactNativeEventEmitter.js +6 -3
  35. package/lib/{IOSDefaultEventPluginOrder.js → ReactNativeEventPluginOrder.js} +3 -3
  36. package/lib/ReactNativeMount.js +24 -7
  37. package/lib/ReactNativeOperationHistoryDevtool.js +37 -0
  38. package/lib/ReactNativeTextComponent.js +8 -0
  39. package/lib/ReactPerf.js +397 -75
  40. package/lib/ReactReconciler.js +46 -5
  41. package/lib/ReactServerRendering.js +20 -1
  42. package/lib/ReactServerRenderingTransaction.js +5 -1
  43. package/lib/ReactTestUtils.js +8 -0
  44. package/lib/ReactTransitionGroup.js +5 -0
  45. package/lib/ReactUpdates.js +21 -3
  46. package/lib/ReactVersion.js +1 -1
  47. package/lib/ReactWithAddons.js +1 -1
  48. package/lib/findDOMNode.js +2 -0
  49. package/lib/instantiateReactComponent.js +34 -1
  50. package/lib/onlyChild.js +7 -4
  51. package/lib/shallowCompare.js +1 -0
  52. package/lib/update.js +4 -0
  53. package/package.json +2 -2
  54. package/lib/ReactDebugInstanceMap.js +0 -102
  55. package/lib/ReactDefaultPerf.js +0 -316
  56. package/lib/ReactDefaultPerfAnalysis.js +0 -210
@@ -1,316 +0,0 @@
1
- /**
2
- * Copyright 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- *
9
- * @providesModule ReactDefaultPerf
10
- */
11
-
12
- 'use strict';
13
-
14
- var DOMProperty = require('./DOMProperty');
15
- var ReactDOMComponentTree = require('./ReactDOMComponentTree');
16
- var ReactDefaultPerfAnalysis = require('./ReactDefaultPerfAnalysis');
17
- var ReactMount = require('./ReactMount');
18
- var ReactPerf = require('./ReactPerf');
19
-
20
- var performanceNow = require('fbjs/lib/performanceNow');
21
- var warning = require('fbjs/lib/warning');
22
-
23
- function roundFloat(val) {
24
- return Math.floor(val * 100) / 100;
25
- }
26
-
27
- function addValue(obj, key, val) {
28
- obj[key] = (obj[key] || 0) + val;
29
- }
30
-
31
- // Composite/text components don't have any built-in ID: we have to make our own
32
- var compositeIDMap;
33
- var compositeIDCounter = 17000;
34
- function getIDOfComposite(inst) {
35
- if (!compositeIDMap) {
36
- compositeIDMap = new WeakMap();
37
- }
38
- if (compositeIDMap.has(inst)) {
39
- return compositeIDMap.get(inst);
40
- } else {
41
- var id = compositeIDCounter++;
42
- compositeIDMap.set(inst, id);
43
- return id;
44
- }
45
- }
46
-
47
- function getID(inst) {
48
- if (inst.hasOwnProperty('_rootNodeID')) {
49
- return inst._rootNodeID;
50
- } else {
51
- return getIDOfComposite(inst);
52
- }
53
- }
54
-
55
- function stripComplexValues(key, value) {
56
- if (typeof value !== 'object' || Array.isArray(value) || value == null) {
57
- return value;
58
- }
59
- var prototype = Object.getPrototypeOf(value);
60
- if (!prototype || prototype === Object.prototype) {
61
- return value;
62
- }
63
- return '<not serializable>';
64
- }
65
-
66
- // This implementation of ReactPerf is going away some time mid 15.x.
67
- // While we plan to keep most of the API, the actual format of measurements
68
- // will change dramatically. To signal this, we wrap them into an opaque-ish
69
- // object to discourage reaching into it until the API stabilizes.
70
- function wrapLegacyMeasurements(measurements) {
71
- return { __unstable_this_format_will_change: measurements };
72
- }
73
- function unwrapLegacyMeasurements(measurements) {
74
- return measurements && measurements.__unstable_this_format_will_change || measurements;
75
- }
76
-
77
- var warnedAboutPrintDOM = false;
78
- var warnedAboutGetMeasurementsSummaryMap = false;
79
-
80
- var ReactDefaultPerf = {
81
- _allMeasurements: [], // last item in the list is the current one
82
- _mountStack: [0],
83
- _compositeStack: [],
84
- _injected: false,
85
-
86
- start: function () {
87
- if (!ReactDefaultPerf._injected) {
88
- ReactPerf.injection.injectMeasure(ReactDefaultPerf.measure);
89
- }
90
-
91
- ReactDefaultPerf._allMeasurements.length = 0;
92
- ReactPerf.enableMeasure = true;
93
- },
94
-
95
- stop: function () {
96
- ReactPerf.enableMeasure = false;
97
- },
98
-
99
- getLastMeasurements: function () {
100
- return wrapLegacyMeasurements(ReactDefaultPerf._allMeasurements);
101
- },
102
-
103
- printExclusive: function (measurements) {
104
- measurements = unwrapLegacyMeasurements(measurements || ReactDefaultPerf._allMeasurements);
105
- var summary = ReactDefaultPerfAnalysis.getExclusiveSummary(measurements);
106
- console.table(summary.map(function (item) {
107
- return {
108
- 'Component class name': item.componentName,
109
- 'Total inclusive time (ms)': roundFloat(item.inclusive),
110
- 'Exclusive mount time (ms)': roundFloat(item.exclusive),
111
- 'Exclusive render time (ms)': roundFloat(item.render),
112
- 'Mount time per instance (ms)': roundFloat(item.exclusive / item.count),
113
- 'Render time per instance (ms)': roundFloat(item.render / item.count),
114
- 'Instances': item.count
115
- };
116
- }));
117
- // TODO: ReactDefaultPerfAnalysis.getTotalTime() does not return the correct
118
- // number.
119
- },
120
-
121
- printInclusive: function (measurements) {
122
- measurements = unwrapLegacyMeasurements(measurements || ReactDefaultPerf._allMeasurements);
123
- var summary = ReactDefaultPerfAnalysis.getInclusiveSummary(measurements);
124
- console.table(summary.map(function (item) {
125
- return {
126
- 'Owner > component': item.componentName,
127
- 'Inclusive time (ms)': roundFloat(item.time),
128
- 'Instances': item.count
129
- };
130
- }));
131
- console.log('Total time:', ReactDefaultPerfAnalysis.getTotalTime(measurements).toFixed(2) + ' ms');
132
- },
133
-
134
- getMeasurementsSummaryMap: function (measurements) {
135
- process.env.NODE_ENV !== 'production' ? warning(warnedAboutGetMeasurementsSummaryMap, '`ReactPerf.getMeasurementsSummaryMap(...)` is deprecated. Use ' + '`ReactPerf.getWasted(...)` instead.') : void 0;
136
- warnedAboutGetMeasurementsSummaryMap = true;
137
- return ReactDefaultPerf.getWasted(measurements);
138
- },
139
-
140
- getWasted: function (measurements) {
141
- measurements = unwrapLegacyMeasurements(measurements);
142
- var summary = ReactDefaultPerfAnalysis.getInclusiveSummary(measurements, true);
143
- return summary.map(function (item) {
144
- return {
145
- 'Owner > component': item.componentName,
146
- 'Wasted time (ms)': item.time,
147
- 'Instances': item.count
148
- };
149
- });
150
- },
151
-
152
- printWasted: function (measurements) {
153
- measurements = unwrapLegacyMeasurements(measurements || ReactDefaultPerf._allMeasurements);
154
- console.table(ReactDefaultPerf.getWasted(measurements));
155
- console.log('Total time:', ReactDefaultPerfAnalysis.getTotalTime(measurements).toFixed(2) + ' ms');
156
- },
157
-
158
- printDOM: function (measurements) {
159
- process.env.NODE_ENV !== 'production' ? warning(warnedAboutPrintDOM, '`ReactPerf.printDOM(...)` is deprecated. Use ' + '`ReactPerf.printOperations(...)` instead.') : void 0;
160
- warnedAboutPrintDOM = true;
161
- return ReactDefaultPerf.printOperations(measurements);
162
- },
163
-
164
- printOperations: function (measurements) {
165
- measurements = unwrapLegacyMeasurements(measurements || ReactDefaultPerf._allMeasurements);
166
- var summary = ReactDefaultPerfAnalysis.getDOMSummary(measurements);
167
- console.table(summary.map(function (item) {
168
- var result = {};
169
- result[DOMProperty.ID_ATTRIBUTE_NAME] = item.id;
170
- result.type = item.type;
171
- result.args = JSON.stringify(item.args, stripComplexValues);
172
- return result;
173
- }));
174
- console.log('Total time:', ReactDefaultPerfAnalysis.getTotalTime(measurements).toFixed(2) + ' ms');
175
- },
176
-
177
- _recordWrite: function (id, fnName, totalTime, args) {
178
- // TODO: totalTime isn't that useful since it doesn't count paints/reflows
179
- var entry = ReactDefaultPerf._allMeasurements[ReactDefaultPerf._allMeasurements.length - 1];
180
- var writes = entry.writes;
181
- writes[id] = writes[id] || [];
182
- writes[id].push({
183
- type: fnName,
184
- time: totalTime,
185
- args: args
186
- });
187
- },
188
-
189
- measure: function (moduleName, fnName, func) {
190
- return function () {
191
- for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
192
- args[_key] = arguments[_key];
193
- }
194
-
195
- var totalTime;
196
- var rv;
197
- var start;
198
-
199
- var entry = ReactDefaultPerf._allMeasurements[ReactDefaultPerf._allMeasurements.length - 1];
200
-
201
- if (fnName === '_renderNewRootComponent' || fnName === 'flushBatchedUpdates') {
202
- // A "measurement" is a set of metrics recorded for each flush. We want
203
- // to group the metrics for a given flush together so we can look at the
204
- // components that rendered and the DOM operations that actually
205
- // happened to determine the amount of "wasted work" performed.
206
- ReactDefaultPerf._allMeasurements.push(entry = {
207
- exclusive: {},
208
- inclusive: {},
209
- render: {},
210
- counts: {},
211
- writes: {},
212
- displayNames: {},
213
- hierarchy: {},
214
- totalTime: 0,
215
- created: {}
216
- });
217
- start = performanceNow();
218
- rv = func.apply(this, args);
219
- entry.totalTime = performanceNow() - start;
220
- return rv;
221
- } else if (fnName === '_mountImageIntoNode' || moduleName === 'ReactDOMIDOperations' || moduleName === 'CSSPropertyOperations' || moduleName === 'DOMChildrenOperations' || moduleName === 'DOMPropertyOperations' || moduleName === 'ReactComponentBrowserEnvironment') {
222
- start = performanceNow();
223
- rv = func.apply(this, args);
224
- totalTime = performanceNow() - start;
225
-
226
- if (fnName === '_mountImageIntoNode') {
227
- ReactDefaultPerf._recordWrite('', fnName, totalTime, args[0]);
228
- } else if (fnName === 'dangerouslyProcessChildrenUpdates') {
229
- // special format
230
- args[1].forEach(function (update) {
231
- var writeArgs = {};
232
- if (update.fromIndex !== null) {
233
- writeArgs.fromIndex = update.fromIndex;
234
- }
235
- if (update.toIndex !== null) {
236
- writeArgs.toIndex = update.toIndex;
237
- }
238
- if (update.content !== null) {
239
- writeArgs.content = update.content;
240
- }
241
- ReactDefaultPerf._recordWrite(args[0]._rootNodeID, update.type, totalTime, writeArgs);
242
- });
243
- } else {
244
- // basic format
245
- var id = args[0];
246
- if (moduleName === 'EventPluginHub') {
247
- id = id._rootNodeID;
248
- } else if (fnName === 'replaceNodeWithMarkup') {
249
- // Old node is already unmounted; can't get its instance
250
- id = ReactDOMComponentTree.getInstanceFromNode(args[1].node)._rootNodeID;
251
- } else if (fnName === 'replaceDelimitedText') {
252
- id = getID(ReactDOMComponentTree.getInstanceFromNode(args[0]));
253
- } else if (typeof id === 'object') {
254
- id = getID(ReactDOMComponentTree.getInstanceFromNode(args[0]));
255
- }
256
- ReactDefaultPerf._recordWrite(id, fnName, totalTime, Array.prototype.slice.call(args, 1));
257
- }
258
- return rv;
259
- } else if (moduleName === 'ReactCompositeComponent' && (fnName === 'mountComponent' || fnName === 'updateComponent' || // TODO: receiveComponent()?
260
- fnName === '_renderValidatedComponent')) {
261
-
262
- if (this._currentElement.type === ReactMount.TopLevelWrapper) {
263
- return func.apply(this, args);
264
- }
265
-
266
- var rootNodeID = getIDOfComposite(this);
267
- var isRender = fnName === '_renderValidatedComponent';
268
- var isMount = fnName === 'mountComponent';
269
-
270
- var mountStack = ReactDefaultPerf._mountStack;
271
-
272
- if (isRender) {
273
- addValue(entry.counts, rootNodeID, 1);
274
- } else if (isMount) {
275
- entry.created[rootNodeID] = true;
276
- mountStack.push(0);
277
- }
278
-
279
- ReactDefaultPerf._compositeStack.push(rootNodeID);
280
-
281
- start = performanceNow();
282
- rv = func.apply(this, args);
283
- totalTime = performanceNow() - start;
284
-
285
- ReactDefaultPerf._compositeStack.pop();
286
-
287
- if (isRender) {
288
- addValue(entry.render, rootNodeID, totalTime);
289
- } else if (isMount) {
290
- var subMountTime = mountStack.pop();
291
- mountStack[mountStack.length - 1] += totalTime;
292
- addValue(entry.exclusive, rootNodeID, totalTime - subMountTime);
293
- addValue(entry.inclusive, rootNodeID, totalTime);
294
- } else {
295
- addValue(entry.inclusive, rootNodeID, totalTime);
296
- }
297
-
298
- entry.displayNames[rootNodeID] = {
299
- current: this.getName(),
300
- owner: this._currentElement._owner ? this._currentElement._owner.getName() : '<root>'
301
- };
302
-
303
- return rv;
304
- } else if ((moduleName === 'ReactDOMComponent' || moduleName === 'ReactDOMTextComponent') && (fnName === 'mountComponent' || fnName === 'receiveComponent')) {
305
-
306
- rv = func.apply(this, args);
307
- entry.hierarchy[getID(this)] = ReactDefaultPerf._compositeStack.slice();
308
- return rv;
309
- } else {
310
- return func.apply(this, args);
311
- }
312
- };
313
- }
314
- };
315
-
316
- module.exports = ReactDefaultPerf;
@@ -1,210 +0,0 @@
1
- /**
2
- * Copyright 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- *
9
- * @providesModule ReactDefaultPerfAnalysis
10
- */
11
-
12
- 'use strict';
13
-
14
- // Don't try to save users less than 1.2ms (a number I made up)
15
-
16
- var _assign = require('object-assign');
17
-
18
- var DONT_CARE_THRESHOLD = 1.2;
19
- var DOM_OPERATION_TYPES = {
20
- '_mountImageIntoNode': 'set innerHTML',
21
- INSERT_MARKUP: 'set innerHTML',
22
- MOVE_EXISTING: 'move',
23
- REMOVE_NODE: 'remove',
24
- SET_MARKUP: 'set innerHTML',
25
- TEXT_CONTENT: 'set textContent',
26
- 'setValueForProperty': 'update attribute',
27
- 'setValueForAttribute': 'update attribute',
28
- 'deleteValueForProperty': 'remove attribute',
29
- 'setValueForStyles': 'update styles',
30
- 'replaceNodeWithMarkup': 'replace',
31
- 'replaceDelimitedText': 'replace'
32
- };
33
-
34
- function getTotalTime(measurements) {
35
- // TODO: return number of DOM ops? could be misleading.
36
- // TODO: measure dropped frames after reconcile?
37
- // TODO: log total time of each reconcile and the top-level component
38
- // class that triggered it.
39
- var totalTime = 0;
40
- for (var i = 0; i < measurements.length; i++) {
41
- var measurement = measurements[i];
42
- totalTime += measurement.totalTime;
43
- }
44
- return totalTime;
45
- }
46
-
47
- function getDOMSummary(measurements) {
48
- var items = [];
49
- measurements.forEach(function (measurement) {
50
- Object.keys(measurement.writes).forEach(function (id) {
51
- measurement.writes[id].forEach(function (write) {
52
- items.push({
53
- id: id,
54
- type: DOM_OPERATION_TYPES[write.type] || write.type,
55
- args: write.args
56
- });
57
- });
58
- });
59
- });
60
- return items;
61
- }
62
-
63
- function getExclusiveSummary(measurements) {
64
- var candidates = {};
65
- var displayName;
66
-
67
- for (var i = 0; i < measurements.length; i++) {
68
- var measurement = measurements[i];
69
- var allIDs = _assign({}, measurement.exclusive, measurement.inclusive);
70
-
71
- for (var id in allIDs) {
72
- displayName = measurement.displayNames[id].current;
73
-
74
- candidates[displayName] = candidates[displayName] || {
75
- componentName: displayName,
76
- inclusive: 0,
77
- exclusive: 0,
78
- render: 0,
79
- count: 0
80
- };
81
- if (measurement.render[id]) {
82
- candidates[displayName].render += measurement.render[id];
83
- }
84
- if (measurement.exclusive[id]) {
85
- candidates[displayName].exclusive += measurement.exclusive[id];
86
- }
87
- if (measurement.inclusive[id]) {
88
- candidates[displayName].inclusive += measurement.inclusive[id];
89
- }
90
- if (measurement.counts[id]) {
91
- candidates[displayName].count += measurement.counts[id];
92
- }
93
- }
94
- }
95
-
96
- // Now make a sorted array with the results.
97
- var arr = [];
98
- for (displayName in candidates) {
99
- if (candidates[displayName].exclusive >= DONT_CARE_THRESHOLD) {
100
- arr.push(candidates[displayName]);
101
- }
102
- }
103
-
104
- arr.sort(function (a, b) {
105
- return b.exclusive - a.exclusive;
106
- });
107
-
108
- return arr;
109
- }
110
-
111
- function getInclusiveSummary(measurements, onlyClean) {
112
- var candidates = {};
113
- var inclusiveKey;
114
-
115
- for (var i = 0; i < measurements.length; i++) {
116
- var measurement = measurements[i];
117
- var allIDs = _assign({}, measurement.exclusive, measurement.inclusive);
118
- var cleanComponents;
119
-
120
- if (onlyClean) {
121
- cleanComponents = getUnchangedComponents(measurement);
122
- }
123
-
124
- for (var id in allIDs) {
125
- if (onlyClean && !cleanComponents[id]) {
126
- continue;
127
- }
128
-
129
- var displayName = measurement.displayNames[id];
130
-
131
- // Inclusive time is not useful for many components without knowing where
132
- // they are instantiated. So we aggregate inclusive time with both the
133
- // owner and current displayName as the key.
134
- inclusiveKey = displayName.owner + ' > ' + displayName.current;
135
-
136
- candidates[inclusiveKey] = candidates[inclusiveKey] || {
137
- componentName: inclusiveKey,
138
- time: 0,
139
- count: 0
140
- };
141
-
142
- if (measurement.inclusive[id]) {
143
- candidates[inclusiveKey].time += measurement.inclusive[id];
144
- }
145
- if (measurement.counts[id]) {
146
- candidates[inclusiveKey].count += measurement.counts[id];
147
- }
148
- }
149
- }
150
-
151
- // Now make a sorted array with the results.
152
- var arr = [];
153
- for (inclusiveKey in candidates) {
154
- if (candidates[inclusiveKey].time >= DONT_CARE_THRESHOLD) {
155
- arr.push(candidates[inclusiveKey]);
156
- }
157
- }
158
-
159
- arr.sort(function (a, b) {
160
- return b.time - a.time;
161
- });
162
-
163
- return arr;
164
- }
165
-
166
- function getUnchangedComponents(measurement) {
167
- // For a given reconcile, look at which components did not actually
168
- // render anything to the DOM and return a mapping of their ID to
169
- // the amount of time it took to render the entire subtree.
170
- var cleanComponents = {};
171
- var writes = measurement.writes;
172
- var hierarchy = measurement.hierarchy;
173
- var dirtyComposites = {};
174
- Object.keys(writes).forEach(function (id) {
175
- writes[id].forEach(function (write) {
176
- // Root mounting (innerHTML set) is recorded with an ID of ''
177
- if (id !== '' && hierarchy.hasOwnProperty(id)) {
178
- hierarchy[id].forEach(function (c) {
179
- return dirtyComposites[c] = true;
180
- });
181
- }
182
- });
183
- });
184
- var allIDs = _assign({}, measurement.exclusive, measurement.inclusive);
185
-
186
- for (var id in allIDs) {
187
- var isDirty = false;
188
- // See if any of the DOM operations applied to this component's subtree.
189
- if (dirtyComposites[id]) {
190
- isDirty = true;
191
- }
192
- // check if component newly created
193
- if (measurement.created[id]) {
194
- isDirty = true;
195
- }
196
- if (!isDirty && measurement.counts[id] > 0) {
197
- cleanComponents[id] = true;
198
- }
199
- }
200
- return cleanComponents;
201
- }
202
-
203
- var ReactDefaultPerfAnalysis = {
204
- getExclusiveSummary: getExclusiveSummary,
205
- getInclusiveSummary: getInclusiveSummary,
206
- getDOMSummary: getDOMSummary,
207
- getTotalTime: getTotalTime
208
- };
209
-
210
- module.exports = ReactDefaultPerfAnalysis;