react 15.0.3-alpha.1 → 15.2.0-rc.1

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 (122) hide show
  1. package/dist/react-with-addons.js +3311 -2007
  2. package/dist/react-with-addons.min.js +7 -6
  3. package/dist/react.js +2734 -2014
  4. package/dist/react.min.js +6 -6
  5. package/lib/CSSPropertyOperations.js +5 -5
  6. package/lib/CallbackQueue.js +3 -2
  7. package/lib/DOMChildrenOperations.js +42 -7
  8. package/lib/DOMLazyTree.js +18 -5
  9. package/lib/DOMProperty.js +6 -4
  10. package/lib/DOMPropertyOperations.js +35 -12
  11. package/lib/Danger.js +10 -8
  12. package/lib/DisabledInputUtils.js +5 -5
  13. package/lib/EventPluginHub.js +8 -2
  14. package/lib/EventPluginRegistry.js +13 -7
  15. package/lib/EventPluginUtils.js +3 -1
  16. package/lib/HTMLDOMPropertyConfig.js +1 -2
  17. package/lib/LinkedStateMixin.js +1 -0
  18. package/lib/LinkedValueUtils.js +5 -3
  19. package/lib/NativeMethodsMixin.js +6 -4
  20. package/lib/PooledClass.js +3 -1
  21. package/lib/React.js +1 -1
  22. package/lib/ReactCSSTransitionGroup.js +5 -0
  23. package/lib/ReactCSSTransitionGroupChild.js +15 -8
  24. package/lib/ReactChildReconciler.js +15 -6
  25. package/lib/ReactChildren.js +9 -1
  26. package/lib/ReactClass.js +15 -13
  27. package/lib/ReactComponent.js +3 -6
  28. package/lib/ReactComponentBrowserEnvironment.js +0 -5
  29. package/lib/ReactComponentEnvironment.js +3 -1
  30. package/lib/ReactComponentTreeDevtool.js +223 -0
  31. package/lib/ReactComponentTreeTestUtils.js +87 -0
  32. package/lib/ReactComponentWithPureRenderMixin.js +2 -0
  33. package/lib/ReactCompositeComponent.js +208 -119
  34. package/lib/ReactDOM.js +3 -6
  35. package/lib/ReactDOMButton.js +2 -2
  36. package/lib/ReactDOMComponent.js +165 -71
  37. package/lib/ReactDOMComponentTree.js +23 -21
  38. package/lib/ReactDOMDebugTool.js +7 -1
  39. package/lib/ReactDOMEmptyComponent.js +9 -9
  40. package/lib/ReactDOMFactories.js +1 -1
  41. package/lib/ReactDOMIDOperations.js +0 -5
  42. package/lib/ReactDOMInput.js +57 -19
  43. package/lib/ReactDOMOption.js +40 -26
  44. package/lib/ReactDOMSelect.js +3 -3
  45. package/lib/ReactDOMTextComponent.js +28 -26
  46. package/lib/ReactDOMTextarea.js +59 -32
  47. package/lib/ReactDOMTreeTraversal.js +18 -16
  48. package/lib/ReactDOMUnknownPropertyDevtool.js +41 -15
  49. package/lib/ReactDebugTool.js +250 -11
  50. package/lib/ReactDefaultInjection.js +2 -11
  51. package/lib/ReactElement.js +90 -25
  52. package/lib/ReactElementValidator.js +26 -81
  53. package/lib/ReactEventListener.js +2 -2
  54. package/lib/ReactFragment.js +8 -3
  55. package/lib/{ReactNativeComponent.js → ReactHostComponent.js} +10 -29
  56. package/lib/ReactHostOperationHistoryDevtool.js +37 -0
  57. package/lib/ReactInjection.js +2 -4
  58. package/lib/ReactInstanceHandles.js +8 -6
  59. package/lib/ReactLink.js +3 -0
  60. package/lib/ReactMount.js +43 -20
  61. package/lib/ReactMultiChild.js +51 -8
  62. package/lib/ReactNativeAttributePayload.js +5 -2
  63. package/lib/ReactNativeBaseComponent.js +7 -7
  64. package/lib/ReactNativeBridgeEventPlugin.js +1 -1
  65. package/lib/ReactNativeComponentTree.js +8 -6
  66. package/lib/ReactNativeDOMIDOperations.js +4 -8
  67. package/lib/ReactNativeDefaultInjection.js +9 -7
  68. package/lib/ReactNativeGlobalResponderHandler.js +1 -1
  69. package/lib/ReactNativeMount.js +25 -8
  70. package/lib/ReactNativeTagHandles.js +3 -1
  71. package/lib/ReactNativeTextComponent.js +18 -9
  72. package/lib/ReactNativeTreeTraversal.js +11 -11
  73. package/lib/ReactNodeTypes.js +5 -3
  74. package/lib/ReactNoop.js +76 -0
  75. package/lib/ReactOwner.js +4 -2
  76. package/lib/ReactPerf.js +473 -75
  77. package/lib/ReactPropTypes.js +23 -0
  78. package/lib/ReactReconcileTransaction.js +1 -1
  79. package/lib/ReactReconciler.js +57 -11
  80. package/lib/ReactServerRendering.js +24 -3
  81. package/lib/ReactServerRenderingTransaction.js +5 -1
  82. package/lib/ReactSimpleEmptyComponent.js +4 -4
  83. package/lib/ReactTestMount.js +126 -0
  84. package/lib/ReactTestReconcileTransaction.js +100 -0
  85. package/lib/ReactTestRenderer.js +133 -0
  86. package/lib/ReactTestUtils.js +25 -10
  87. package/lib/ReactTransitionChildMapping.js +7 -1
  88. package/lib/ReactTransitionGroup.js +44 -5
  89. package/lib/ReactUpdateQueue.js +9 -1
  90. package/lib/ReactUpdates.js +30 -11
  91. package/lib/ReactVersion.js +1 -1
  92. package/lib/ReactWithAddons.js +1 -1
  93. package/lib/ResponderEventPlugin.js +8 -6
  94. package/lib/ResponderTouchHistoryStore.js +6 -4
  95. package/lib/SimpleEventPlugin.js +3 -1
  96. package/lib/SyntheticEvent.js +2 -3
  97. package/lib/SyntheticUIEvent.js +1 -1
  98. package/lib/Transaction.js +4 -2
  99. package/lib/accumulate.js +3 -1
  100. package/lib/accumulateInto.js +3 -1
  101. package/lib/checkReactTypeSpec.js +71 -0
  102. package/lib/createReactNativeComponentClass.js +2 -2
  103. package/lib/dangerousStyleValue.js +3 -1
  104. package/lib/escapeTextContentForBrowser.js +96 -12
  105. package/lib/findDOMNode.js +8 -4
  106. package/lib/findNodeHandle.js +5 -3
  107. package/lib/flattenChildren.js +13 -4
  108. package/lib/{getNativeComponentFromComposite.js → getHostComponentFromComposite.js} +4 -4
  109. package/lib/instantiateReactComponent.js +44 -10
  110. package/lib/onlyChild.js +10 -5
  111. package/lib/reactComponentExpect.js +3 -3
  112. package/lib/reactProdInvariant.js +38 -0
  113. package/lib/setInnerHTML.js +17 -1
  114. package/lib/setTextContent.js +8 -0
  115. package/lib/shallowCompare.js +1 -0
  116. package/lib/traverseAllChildren.js +3 -1
  117. package/lib/update.js +16 -11
  118. package/package.json +2 -2
  119. package/lib/MetaMatchers.js +0 -118
  120. package/lib/ReactDebugInstanceMap.js +0 -102
  121. package/lib/ReactDefaultPerf.js +0 -316
  122. package/lib/ReactDefaultPerfAnalysis.js +0 -210
@@ -11,6 +11,8 @@
11
11
  */
12
12
  'use strict';
13
13
 
14
+ var _prodInvariant = require('./reactProdInvariant');
15
+
14
16
  var invariant = require('fbjs/lib/invariant');
15
17
 
16
18
  /**
@@ -42,7 +44,7 @@ var ReactNativeTagHandles = {
42
44
  },
43
45
 
44
46
  assertRootTag: function (tag) {
45
- !this.reactTagIsNativeTopRootID(tag) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Expect a native root tag, instead got %s', tag) : invariant(false) : void 0;
47
+ !this.reactTagIsNativeTopRootID(tag) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Expect a native root tag, instead got %s', tag) : _prodInvariant('19', tag) : void 0;
46
48
  },
47
49
 
48
50
  reactTagIsNativeTopRootID: function (reactTag) {
@@ -11,11 +11,13 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- var _assign = require('object-assign');
14
+ var _prodInvariant = require('./reactProdInvariant'),
15
+ _assign = require('object-assign');
15
16
 
17
+ var ReactInstrumentation = require('./ReactInstrumentation');
16
18
  var ReactNativeComponentTree = require('./ReactNativeComponentTree');
17
19
  var ReactNativeTagHandles = require('./ReactNativeTagHandles');
18
- var UIManager = require('UIManager');
20
+ var UIManager = require('react-native/lib/UIManager');
19
21
 
20
22
  var invariant = require('fbjs/lib/invariant');
21
23
 
@@ -23,19 +25,23 @@ var ReactNativeTextComponent = function (text) {
23
25
  // This is really a ReactText (ReactNode), not a ReactElement
24
26
  this._currentElement = text;
25
27
  this._stringText = '' + text;
26
- this._nativeParent = null;
28
+ this._hostParent = null;
27
29
  this._rootNodeID = null;
28
30
  };
29
31
 
30
32
  _assign(ReactNativeTextComponent.prototype, {
31
33
 
32
- mountComponent: function (transaction, nativeParent, nativeContainerInfo, context) {
33
- // TODO: nativeParent should have this context already. Stop abusing context.
34
- !context.isInAParentText ? process.env.NODE_ENV !== 'production' ? invariant(false, 'RawText "%s" must be wrapped in an explicit <Text> component.', this._stringText) : invariant(false) : void 0;
35
- this._nativeParent = nativeParent;
34
+ mountComponent: function (transaction, hostParent, hostContainerInfo, context) {
35
+ if (process.env.NODE_ENV !== 'production') {
36
+ ReactInstrumentation.debugTool.onSetText(this._debugID, this._stringText);
37
+ }
38
+
39
+ // TODO: hostParent should have this context already. Stop abusing context.
40
+ !context.isInAParentText ? process.env.NODE_ENV !== 'production' ? invariant(false, 'RawText "%s" must be wrapped in an explicit <Text> component.', this._stringText) : _prodInvariant('20', this._stringText) : void 0;
41
+ this._hostParent = hostParent;
36
42
  var tag = ReactNativeTagHandles.allocateTag();
37
43
  this._rootNodeID = tag;
38
- var nativeTopRootTag = nativeContainerInfo._tag;
44
+ var nativeTopRootTag = hostContainerInfo._tag;
39
45
  UIManager.createView(tag, 'RCTRawText', nativeTopRootTag, { text: this._stringText });
40
46
 
41
47
  ReactNativeComponentTree.precacheNode(this, tag);
@@ -43,7 +49,7 @@ _assign(ReactNativeTextComponent.prototype, {
43
49
  return tag;
44
50
  },
45
51
 
46
- getNativeNode: function () {
52
+ getHostNode: function () {
47
53
  return this._rootNodeID;
48
54
  },
49
55
 
@@ -54,6 +60,9 @@ _assign(ReactNativeTextComponent.prototype, {
54
60
  if (nextStringText !== this._stringText) {
55
61
  this._stringText = nextStringText;
56
62
  UIManager.updateView(this._rootNodeID, 'RCTRawText', { text: this._stringText });
63
+ if (process.env.NODE_ENV !== 'production') {
64
+ ReactInstrumentation.debugTool.onSetText(this._debugID, nextStringText);
65
+ }
57
66
  }
58
67
  }
59
68
  },
@@ -20,23 +20,23 @@
20
20
 
21
21
  function getLowestCommonAncestor(instA, instB) {
22
22
  var depthA = 0;
23
- for (var tempA = instA; tempA; tempA = tempA._nativeParent) {
23
+ for (var tempA = instA; tempA; tempA = tempA._hostParent) {
24
24
  depthA++;
25
25
  }
26
26
  var depthB = 0;
27
- for (var tempB = instB; tempB; tempB = tempB._nativeParent) {
27
+ for (var tempB = instB; tempB; tempB = tempB._hostParent) {
28
28
  depthB++;
29
29
  }
30
30
 
31
31
  // If A is deeper, crawl up.
32
32
  while (depthA - depthB > 0) {
33
- instA = instA._nativeParent;
33
+ instA = instA._hostParent;
34
34
  depthA--;
35
35
  }
36
36
 
37
37
  // If B is deeper, crawl up.
38
38
  while (depthB - depthA > 0) {
39
- instB = instB._nativeParent;
39
+ instB = instB._hostParent;
40
40
  depthB--;
41
41
  }
42
42
 
@@ -46,8 +46,8 @@ function getLowestCommonAncestor(instA, instB) {
46
46
  if (instA === instB) {
47
47
  return instA;
48
48
  }
49
- instA = instA._nativeParent;
50
- instB = instB._nativeParent;
49
+ instA = instA._hostParent;
50
+ instB = instB._hostParent;
51
51
  }
52
52
  return null;
53
53
  }
@@ -60,7 +60,7 @@ function isAncestor(instA, instB) {
60
60
  if (instB === instA) {
61
61
  return true;
62
62
  }
63
- instB = instB._nativeParent;
63
+ instB = instB._hostParent;
64
64
  }
65
65
  return false;
66
66
  }
@@ -69,7 +69,7 @@ function isAncestor(instA, instB) {
69
69
  * Return the parent instance of the passed-in instance.
70
70
  */
71
71
  function getParentInstance(inst) {
72
- return inst._nativeParent;
72
+ return inst._hostParent;
73
73
  }
74
74
 
75
75
  /**
@@ -79,7 +79,7 @@ function traverseTwoPhase(inst, fn, arg) {
79
79
  var path = [];
80
80
  while (inst) {
81
81
  path.push(inst);
82
- inst = inst._nativeParent;
82
+ inst = inst._hostParent;
83
83
  }
84
84
  var i;
85
85
  for (i = path.length; i-- > 0;) {
@@ -102,12 +102,12 @@ function traverseEnterLeave(from, to, fn, argFrom, argTo) {
102
102
  var pathFrom = [];
103
103
  while (from && from !== common) {
104
104
  pathFrom.push(from);
105
- from = from._nativeParent;
105
+ from = from._hostParent;
106
106
  }
107
107
  var pathTo = [];
108
108
  while (to && to !== common) {
109
109
  pathTo.push(to);
110
- to = to._nativeParent;
110
+ to = to._hostParent;
111
111
  }
112
112
  var i;
113
113
  for (i = 0; i < pathFrom.length; i++) {
@@ -11,12 +11,14 @@
11
11
 
12
12
  'use strict';
13
13
 
14
+ var _prodInvariant = require('./reactProdInvariant');
15
+
14
16
  var ReactElement = require('./ReactElement');
15
17
 
16
18
  var invariant = require('fbjs/lib/invariant');
17
19
 
18
20
  var ReactNodeTypes = {
19
- NATIVE: 0,
21
+ HOST: 0,
20
22
  COMPOSITE: 1,
21
23
  EMPTY: 2,
22
24
 
@@ -27,10 +29,10 @@ var ReactNodeTypes = {
27
29
  if (typeof node.type === 'function') {
28
30
  return ReactNodeTypes.COMPOSITE;
29
31
  } else {
30
- return ReactNodeTypes.NATIVE;
32
+ return ReactNodeTypes.HOST;
31
33
  }
32
34
  }
33
- !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Unexpected node: %s', node) : invariant(false) : void 0;
35
+ !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Unexpected node: %s', node) : _prodInvariant('26', node) : void 0;
34
36
  }
35
37
  };
36
38
 
@@ -0,0 +1,76 @@
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 ReactNoop
10
+ *
11
+ */
12
+
13
+ /**
14
+ * This is a renderer of React that doesn't have a render target output.
15
+ * It is useful to demonstrate the internals of the reconciler in isolation
16
+ * and for testing semantics of reconciliation separate from the host
17
+ * environment.
18
+ */
19
+
20
+ 'use strict';
21
+
22
+ var ReactFiberReconciler = require('./ReactFiberReconciler');
23
+
24
+ var scheduledHighPriCallback = null;
25
+ var scheduledLowPriCallback = null;
26
+
27
+ var NoopRenderer = ReactFiberReconciler({
28
+ createHostInstance: function () {},
29
+ scheduleHighPriCallback: function (callback) {
30
+ scheduledHighPriCallback = callback;
31
+ },
32
+ scheduleLowPriCallback: function (callback) {
33
+ scheduledLowPriCallback = callback;
34
+ }
35
+ });
36
+
37
+ var ReactNoop = {
38
+ render: function (element) {
39
+
40
+ NoopRenderer.mountNewRoot(element);
41
+ },
42
+ flushHighPri: function () {
43
+ var cb = scheduledHighPriCallback;
44
+ if (cb === null) {
45
+ return;
46
+ }
47
+ scheduledHighPriCallback = null;
48
+ cb();
49
+ },
50
+ flushLowPri: function () {
51
+ var timeout = arguments.length <= 0 || arguments[0] === undefined ? Infinity : arguments[0];
52
+
53
+ var cb = scheduledLowPriCallback;
54
+ if (cb === null) {
55
+ return;
56
+ }
57
+ scheduledLowPriCallback = null;
58
+ var timeRemaining = timeout;
59
+ cb({
60
+ timeRemaining: function () {
61
+ // Simulate a fix amount of time progressing between each call.
62
+ timeRemaining -= 5;
63
+ if (timeRemaining < 0) {
64
+ timeRemaining = 0;
65
+ }
66
+ return timeRemaining;
67
+ }
68
+ });
69
+ },
70
+ flush: function () {
71
+ ReactNoop.flushHighPri();
72
+ ReactNoop.flushLowPri();
73
+ }
74
+ };
75
+
76
+ module.exports = ReactNoop;
package/lib/ReactOwner.js CHANGED
@@ -11,6 +11,8 @@
11
11
 
12
12
  'use strict';
13
13
 
14
+ var _prodInvariant = require('./reactProdInvariant');
15
+
14
16
  var invariant = require('fbjs/lib/invariant');
15
17
 
16
18
  /**
@@ -64,7 +66,7 @@ var ReactOwner = {
64
66
  * @internal
65
67
  */
66
68
  addComponentAsRefTo: function (component, ref, owner) {
67
- !ReactOwner.isValidOwner(owner) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'addComponentAsRefTo(...): Only a ReactOwner can have refs. You might ' + 'be adding a ref to a component that was not created inside a component\'s ' + '`render` method, or you have multiple copies of React loaded ' + '(details: https://fb.me/react-refs-must-have-owner).') : invariant(false) : void 0;
69
+ !ReactOwner.isValidOwner(owner) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component\'s `render` method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).') : _prodInvariant('119') : void 0;
68
70
  owner.attachRef(ref, component);
69
71
  },
70
72
 
@@ -78,7 +80,7 @@ var ReactOwner = {
78
80
  * @internal
79
81
  */
80
82
  removeComponentAsRefFrom: function (component, ref, owner) {
81
- !ReactOwner.isValidOwner(owner) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'removeComponentAsRefFrom(...): Only a ReactOwner can have refs. You might ' + 'be removing a ref to a component that was not created inside a component\'s ' + '`render` method, or you have multiple copies of React loaded ' + '(details: https://fb.me/react-refs-must-have-owner).') : invariant(false) : void 0;
83
+ !ReactOwner.isValidOwner(owner) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'removeComponentAsRefFrom(...): Only a ReactOwner can have refs. You might be removing a ref to a component that was not created inside a component\'s `render` method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).') : _prodInvariant('120') : void 0;
82
84
  var ownerPublicInstance = owner.getPublicInstance();
83
85
  // Check that `component`'s owner is still alive and that `component` is still the current ref
84
86
  // because we do not want to detach the ref if another component stole it.
package/lib/ReactPerf.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013-present, Facebook, Inc.
2
+ * Copyright 2016-present, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under the BSD-style license found in the
@@ -11,86 +11,484 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- /**
15
- * ReactPerf is a general AOP system designed to measure performance. This
16
- * module only has the hooks: see ReactDefaultPerf for the analysis tool.
17
- */
14
+ var _assign = require('object-assign');
18
15
 
19
- var ReactPerf = {
20
- /**
21
- * Boolean to enable/disable measurement. Set to false by default to prevent
22
- * accidental logging and perf loss.
23
- */
24
- enableMeasure: false,
25
-
26
- /**
27
- * Holds onto the measure function in use. By default, don't measure
28
- * anything, but we'll override this if we inject a measure function.
29
- */
30
- storedMeasure: _noMeasure,
31
-
32
- /**
33
- * @param {object} object
34
- * @param {string} objectName
35
- * @param {object<string>} methodNames
36
- */
37
- measureMethods: function (object, objectName, methodNames) {
38
- if (process.env.NODE_ENV !== 'production') {
39
- for (var key in methodNames) {
40
- if (!methodNames.hasOwnProperty(key)) {
41
- continue;
42
- }
43
- object[key] = ReactPerf.measure(objectName, methodNames[key], object[key]);
44
- }
16
+ var _extends = _assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
17
+
18
+ var ReactDebugTool = require('./ReactDebugTool');
19
+ var warning = require('fbjs/lib/warning');
20
+ var alreadyWarned = false;
21
+
22
+ function roundFloat(val) {
23
+ var base = arguments.length <= 1 || arguments[1] === undefined ? 2 : arguments[1];
24
+
25
+ var n = Math.pow(10, base);
26
+ return Math.floor(val * n) / n;
27
+ }
28
+
29
+ function warnInProduction() {
30
+ if (alreadyWarned) {
31
+ return;
32
+ }
33
+ alreadyWarned = true;
34
+ if (typeof console !== 'undefined') {
35
+ console.error('ReactPerf is not supported in the production builds of React. ' + 'To collect measurements, please use the development build of React instead.');
36
+ }
37
+ }
38
+
39
+ function getLastMeasurements() {
40
+ if (!(process.env.NODE_ENV !== 'production')) {
41
+ warnInProduction();
42
+ return [];
43
+ }
44
+
45
+ return ReactDebugTool.getFlushHistory();
46
+ }
47
+
48
+ function getExclusive() {
49
+ var flushHistory = arguments.length <= 0 || arguments[0] === undefined ? getLastMeasurements() : arguments[0];
50
+
51
+ if (!(process.env.NODE_ENV !== 'production')) {
52
+ warnInProduction();
53
+ return [];
54
+ }
55
+
56
+ var aggregatedStats = {};
57
+ var affectedIDs = {};
58
+
59
+ function updateAggregatedStats(treeSnapshot, instanceID, timerType, applyUpdate) {
60
+ var displayName = treeSnapshot[instanceID].displayName;
61
+
62
+ var key = displayName;
63
+ var stats = aggregatedStats[key];
64
+ if (!stats) {
65
+ affectedIDs[key] = {};
66
+ stats = aggregatedStats[key] = {
67
+ key: key,
68
+ instanceCount: 0,
69
+ counts: {},
70
+ durations: {},
71
+ totalDuration: 0
72
+ };
45
73
  }
46
- },
47
-
48
- /**
49
- * Use this to wrap methods you want to measure. Zero overhead in production.
50
- *
51
- * @param {string} objName
52
- * @param {string} fnName
53
- * @param {function} func
54
- * @return {function}
55
- */
56
- measure: function (objName, fnName, func) {
57
- if (process.env.NODE_ENV !== 'production') {
58
- var measuredFunc = null;
59
- var wrapper = function () {
60
- if (ReactPerf.enableMeasure) {
61
- if (!measuredFunc) {
62
- measuredFunc = ReactPerf.storedMeasure(objName, fnName, func);
63
- }
64
- return measuredFunc.apply(this, arguments);
65
- }
66
- return func.apply(this, arguments);
74
+ if (!stats.durations[timerType]) {
75
+ stats.durations[timerType] = 0;
76
+ }
77
+ if (!stats.counts[timerType]) {
78
+ stats.counts[timerType] = 0;
79
+ }
80
+ affectedIDs[key][instanceID] = true;
81
+ applyUpdate(stats);
82
+ }
83
+
84
+ flushHistory.forEach(function (flush) {
85
+ var measurements = flush.measurements;
86
+ var treeSnapshot = flush.treeSnapshot;
87
+
88
+ measurements.forEach(function (measurement) {
89
+ var duration = measurement.duration;
90
+ var instanceID = measurement.instanceID;
91
+ var timerType = measurement.timerType;
92
+
93
+ updateAggregatedStats(treeSnapshot, instanceID, timerType, function (stats) {
94
+ stats.totalDuration += duration;
95
+ stats.durations[timerType] += duration;
96
+ stats.counts[timerType]++;
97
+ });
98
+ });
99
+ });
100
+
101
+ return Object.keys(aggregatedStats).map(function (key) {
102
+ return _extends({}, aggregatedStats[key], {
103
+ instanceCount: Object.keys(affectedIDs[key]).length
104
+ });
105
+ }).sort(function (a, b) {
106
+ return b.totalDuration - a.totalDuration;
107
+ });
108
+ }
109
+
110
+ function getInclusive() {
111
+ var flushHistory = arguments.length <= 0 || arguments[0] === undefined ? getLastMeasurements() : arguments[0];
112
+
113
+ if (!(process.env.NODE_ENV !== 'production')) {
114
+ warnInProduction();
115
+ return [];
116
+ }
117
+
118
+ var aggregatedStats = {};
119
+ var affectedIDs = {};
120
+
121
+ function updateAggregatedStats(treeSnapshot, instanceID, applyUpdate) {
122
+ var _treeSnapshot$instanc = treeSnapshot[instanceID];
123
+ var displayName = _treeSnapshot$instanc.displayName;
124
+ var ownerID = _treeSnapshot$instanc.ownerID;
125
+
126
+ var owner = treeSnapshot[ownerID];
127
+ var key = (owner ? owner.displayName + ' > ' : '') + displayName;
128
+ var stats = aggregatedStats[key];
129
+ if (!stats) {
130
+ affectedIDs[key] = {};
131
+ stats = aggregatedStats[key] = {
132
+ key: key,
133
+ instanceCount: 0,
134
+ inclusiveRenderDuration: 0,
135
+ renderCount: 0
67
136
  };
68
- wrapper.displayName = objName + '_' + fnName;
69
- return wrapper;
70
137
  }
71
- return func;
72
- },
73
-
74
- injection: {
75
- /**
76
- * @param {function} measure
77
- */
78
- injectMeasure: function (measure) {
79
- ReactPerf.storedMeasure = measure;
138
+ affectedIDs[key][instanceID] = true;
139
+ applyUpdate(stats);
140
+ }
141
+
142
+ var isCompositeByID = {};
143
+ flushHistory.forEach(function (flush) {
144
+ var measurements = flush.measurements;
145
+
146
+ measurements.forEach(function (measurement) {
147
+ var instanceID = measurement.instanceID;
148
+ var timerType = measurement.timerType;
149
+
150
+ if (timerType !== 'render') {
151
+ return;
152
+ }
153
+ isCompositeByID[instanceID] = true;
154
+ });
155
+ });
156
+
157
+ flushHistory.forEach(function (flush) {
158
+ var measurements = flush.measurements;
159
+ var treeSnapshot = flush.treeSnapshot;
160
+
161
+ measurements.forEach(function (measurement) {
162
+ var duration = measurement.duration;
163
+ var instanceID = measurement.instanceID;
164
+ var timerType = measurement.timerType;
165
+
166
+ if (timerType !== 'render') {
167
+ return;
168
+ }
169
+ updateAggregatedStats(treeSnapshot, instanceID, function (stats) {
170
+ stats.renderCount++;
171
+ });
172
+ var nextParentID = instanceID;
173
+ while (nextParentID) {
174
+ // As we traverse parents, only count inclusive time towards composites.
175
+ // We know something is a composite if its render() was called.
176
+ if (isCompositeByID[nextParentID]) {
177
+ updateAggregatedStats(treeSnapshot, nextParentID, function (stats) {
178
+ stats.inclusiveRenderDuration += duration;
179
+ });
180
+ }
181
+ nextParentID = treeSnapshot[nextParentID].parentID;
182
+ }
183
+ });
184
+ });
185
+
186
+ return Object.keys(aggregatedStats).map(function (key) {
187
+ return _extends({}, aggregatedStats[key], {
188
+ instanceCount: Object.keys(affectedIDs[key]).length
189
+ });
190
+ }).sort(function (a, b) {
191
+ return b.inclusiveRenderDuration - a.inclusiveRenderDuration;
192
+ });
193
+ }
194
+
195
+ function getWasted() {
196
+ var flushHistory = arguments.length <= 0 || arguments[0] === undefined ? getLastMeasurements() : arguments[0];
197
+
198
+ if (!(process.env.NODE_ENV !== 'production')) {
199
+ warnInProduction();
200
+ return [];
201
+ }
202
+
203
+ var aggregatedStats = {};
204
+ var affectedIDs = {};
205
+
206
+ function updateAggregatedStats(treeSnapshot, instanceID, applyUpdate) {
207
+ var _treeSnapshot$instanc2 = treeSnapshot[instanceID];
208
+ var displayName = _treeSnapshot$instanc2.displayName;
209
+ var ownerID = _treeSnapshot$instanc2.ownerID;
210
+
211
+ var owner = treeSnapshot[ownerID];
212
+ var key = (owner ? owner.displayName + ' > ' : '') + displayName;
213
+ var stats = aggregatedStats[key];
214
+ if (!stats) {
215
+ affectedIDs[key] = {};
216
+ stats = aggregatedStats[key] = {
217
+ key: key,
218
+ instanceCount: 0,
219
+ inclusiveRenderDuration: 0,
220
+ renderCount: 0
221
+ };
80
222
  }
223
+ affectedIDs[key][instanceID] = true;
224
+ applyUpdate(stats);
81
225
  }
82
- };
83
226
 
84
- /**
85
- * Simply passes through the measured function, without measuring it.
86
- *
87
- * @param {string} objName
88
- * @param {string} fnName
89
- * @param {function} func
90
- * @return {function}
91
- */
92
- function _noMeasure(objName, fnName, func) {
93
- return func;
227
+ flushHistory.forEach(function (flush) {
228
+ var measurements = flush.measurements;
229
+ var treeSnapshot = flush.treeSnapshot;
230
+ var operations = flush.operations;
231
+
232
+ var isDefinitelyNotWastedByID = {};
233
+
234
+ // Find host components associated with an operation in this batch.
235
+ // Mark all components in their parent tree as definitely not wasted.
236
+ operations.forEach(function (operation) {
237
+ var instanceID = operation.instanceID;
238
+
239
+ var nextParentID = instanceID;
240
+ while (nextParentID) {
241
+ isDefinitelyNotWastedByID[nextParentID] = true;
242
+ nextParentID = treeSnapshot[nextParentID].parentID;
243
+ }
244
+ });
245
+
246
+ // Find composite components that rendered in this batch.
247
+ // These are potential candidates for being wasted renders.
248
+ var renderedCompositeIDs = {};
249
+ measurements.forEach(function (measurement) {
250
+ var instanceID = measurement.instanceID;
251
+ var timerType = measurement.timerType;
252
+
253
+ if (timerType !== 'render') {
254
+ return;
255
+ }
256
+ renderedCompositeIDs[instanceID] = true;
257
+ });
258
+
259
+ measurements.forEach(function (measurement) {
260
+ var duration = measurement.duration;
261
+ var instanceID = measurement.instanceID;
262
+ var timerType = measurement.timerType;
263
+
264
+ if (timerType !== 'render') {
265
+ return;
266
+ }
267
+
268
+ // If there was a DOM update below this component, or it has just been
269
+ // mounted, its render() is not considered wasted.
270
+ var updateCount = treeSnapshot[instanceID].updateCount;
271
+
272
+ if (isDefinitelyNotWastedByID[instanceID] || updateCount === 0) {
273
+ return;
274
+ }
275
+
276
+ // We consider this render() wasted.
277
+ updateAggregatedStats(treeSnapshot, instanceID, function (stats) {
278
+ stats.renderCount++;
279
+ });
280
+
281
+ var nextParentID = instanceID;
282
+ while (nextParentID) {
283
+ // Any parents rendered during this batch are considered wasted
284
+ // unless we previously marked them as dirty.
285
+ var isWasted = renderedCompositeIDs[nextParentID] && !isDefinitelyNotWastedByID[nextParentID];
286
+ if (isWasted) {
287
+ updateAggregatedStats(treeSnapshot, nextParentID, function (stats) {
288
+ stats.inclusiveRenderDuration += duration;
289
+ });
290
+ }
291
+ nextParentID = treeSnapshot[nextParentID].parentID;
292
+ }
293
+ });
294
+ });
295
+
296
+ return Object.keys(aggregatedStats).map(function (key) {
297
+ return _extends({}, aggregatedStats[key], {
298
+ instanceCount: Object.keys(affectedIDs[key]).length
299
+ });
300
+ }).sort(function (a, b) {
301
+ return b.inclusiveRenderDuration - a.inclusiveRenderDuration;
302
+ });
303
+ }
304
+
305
+ function getOperations() {
306
+ var flushHistory = arguments.length <= 0 || arguments[0] === undefined ? getLastMeasurements() : arguments[0];
307
+
308
+ if (!(process.env.NODE_ENV !== 'production')) {
309
+ warnInProduction();
310
+ return [];
311
+ }
312
+
313
+ var stats = [];
314
+ flushHistory.forEach(function (flush, flushIndex) {
315
+ var operations = flush.operations;
316
+ var treeSnapshot = flush.treeSnapshot;
317
+
318
+ operations.forEach(function (operation) {
319
+ var instanceID = operation.instanceID;
320
+ var type = operation.type;
321
+ var payload = operation.payload;
322
+ var _treeSnapshot$instanc3 = treeSnapshot[instanceID];
323
+ var displayName = _treeSnapshot$instanc3.displayName;
324
+ var ownerID = _treeSnapshot$instanc3.ownerID;
325
+
326
+ var owner = treeSnapshot[ownerID];
327
+ var key = (owner ? owner.displayName + ' > ' : '') + displayName;
328
+
329
+ stats.push({
330
+ flushIndex: flushIndex,
331
+ instanceID: instanceID,
332
+ key: key,
333
+ type: type,
334
+ ownerID: ownerID,
335
+ payload: payload
336
+ });
337
+ });
338
+ });
339
+ return stats;
340
+ }
341
+
342
+ function printExclusive(flushHistory) {
343
+ if (!(process.env.NODE_ENV !== 'production')) {
344
+ warnInProduction();
345
+ return;
346
+ }
347
+
348
+ var stats = getExclusive(flushHistory);
349
+ var table = stats.map(function (item) {
350
+ var key = item.key;
351
+ var instanceCount = item.instanceCount;
352
+ var totalDuration = item.totalDuration;
353
+
354
+ var renderCount = item.counts.render || 0;
355
+ var renderDuration = item.durations.render || 0;
356
+ return {
357
+ 'Component': key,
358
+ 'Total time (ms)': roundFloat(totalDuration),
359
+ 'Instance count': instanceCount,
360
+ 'Total render time (ms)': roundFloat(renderDuration),
361
+ 'Average render time (ms)': renderCount ? roundFloat(renderDuration / renderCount) : undefined,
362
+ 'Render count': renderCount,
363
+ 'Total lifecycle time (ms)': roundFloat(totalDuration - renderDuration)
364
+ };
365
+ });
366
+ console.table(table);
367
+ }
368
+
369
+ function printInclusive(flushHistory) {
370
+ if (!(process.env.NODE_ENV !== 'production')) {
371
+ warnInProduction();
372
+ return;
373
+ }
374
+
375
+ var stats = getInclusive(flushHistory);
376
+ var table = stats.map(function (item) {
377
+ var key = item.key;
378
+ var instanceCount = item.instanceCount;
379
+ var inclusiveRenderDuration = item.inclusiveRenderDuration;
380
+ var renderCount = item.renderCount;
381
+
382
+ return {
383
+ 'Owner > Component': key,
384
+ 'Inclusive render time (ms)': roundFloat(inclusiveRenderDuration),
385
+ 'Instance count': instanceCount,
386
+ 'Render count': renderCount
387
+ };
388
+ });
389
+ console.table(table);
390
+ }
391
+
392
+ function printWasted(flushHistory) {
393
+ if (!(process.env.NODE_ENV !== 'production')) {
394
+ warnInProduction();
395
+ return;
396
+ }
397
+
398
+ var stats = getWasted(flushHistory);
399
+ var table = stats.map(function (item) {
400
+ var key = item.key;
401
+ var instanceCount = item.instanceCount;
402
+ var inclusiveRenderDuration = item.inclusiveRenderDuration;
403
+ var renderCount = item.renderCount;
404
+
405
+ return {
406
+ 'Owner > Component': key,
407
+ 'Inclusive wasted time (ms)': roundFloat(inclusiveRenderDuration),
408
+ 'Instance count': instanceCount,
409
+ 'Render count': renderCount
410
+ };
411
+ });
412
+ console.table(table);
413
+ }
414
+
415
+ function printOperations(flushHistory) {
416
+ if (!(process.env.NODE_ENV !== 'production')) {
417
+ warnInProduction();
418
+ return;
419
+ }
420
+
421
+ var stats = getOperations(flushHistory);
422
+ var table = stats.map(function (stat) {
423
+ return {
424
+ 'Owner > Node': stat.key,
425
+ 'Operation': stat.type,
426
+ 'Payload': typeof stat.payload === 'object' ? JSON.stringify(stat.payload) : stat.payload,
427
+ 'Flush index': stat.flushIndex,
428
+ 'Owner Component ID': stat.ownerID,
429
+ 'DOM Component ID': stat.instanceID
430
+ };
431
+ });
432
+ console.table(table);
433
+ }
434
+
435
+ var warnedAboutPrintDOM = false;
436
+ function printDOM(measurements) {
437
+ process.env.NODE_ENV !== 'production' ? warning(warnedAboutPrintDOM, '`ReactPerf.printDOM(...)` is deprecated. Use ' + '`ReactPerf.printOperations(...)` instead.') : void 0;
438
+ warnedAboutPrintDOM = true;
439
+ return printOperations(measurements);
94
440
  }
95
441
 
96
- module.exports = ReactPerf;
442
+ var warnedAboutGetMeasurementsSummaryMap = false;
443
+ function getMeasurementsSummaryMap(measurements) {
444
+ process.env.NODE_ENV !== 'production' ? warning(warnedAboutGetMeasurementsSummaryMap, '`ReactPerf.getMeasurementsSummaryMap(...)` is deprecated. Use ' + '`ReactPerf.getWasted(...)` instead.') : void 0;
445
+ warnedAboutGetMeasurementsSummaryMap = true;
446
+ return getWasted(measurements);
447
+ }
448
+
449
+ function start() {
450
+ if (!(process.env.NODE_ENV !== 'production')) {
451
+ warnInProduction();
452
+ return;
453
+ }
454
+
455
+ ReactDebugTool.beginProfiling();
456
+ }
457
+
458
+ function stop() {
459
+ if (!(process.env.NODE_ENV !== 'production')) {
460
+ warnInProduction();
461
+ return;
462
+ }
463
+
464
+ ReactDebugTool.endProfiling();
465
+ }
466
+
467
+ function isRunning() {
468
+ if (!(process.env.NODE_ENV !== 'production')) {
469
+ warnInProduction();
470
+ return false;
471
+ }
472
+
473
+ return ReactDebugTool.isProfiling();
474
+ }
475
+
476
+ var ReactPerfAnalysis = {
477
+ getLastMeasurements: getLastMeasurements,
478
+ getExclusive: getExclusive,
479
+ getInclusive: getInclusive,
480
+ getWasted: getWasted,
481
+ getOperations: getOperations,
482
+ printExclusive: printExclusive,
483
+ printInclusive: printInclusive,
484
+ printWasted: printWasted,
485
+ printOperations: printOperations,
486
+ start: start,
487
+ stop: stop,
488
+ isRunning: isRunning,
489
+ // Deprecated:
490
+ printDOM: printDOM,
491
+ getMeasurementsSummaryMap: getMeasurementsSummaryMap
492
+ };
493
+
494
+ module.exports = ReactPerfAnalysis;