react 0.14.0-beta1 → 0.14.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 (173) hide show
  1. package/addons.js +8 -3
  2. package/dist/react-with-addons.js +5048 -4095
  3. package/dist/react-with-addons.min.js +6 -6
  4. package/dist/react.js +4555 -3729
  5. package/dist/react.min.js +6 -5
  6. package/lib/AutoFocusUtils.js +3 -3
  7. package/lib/BeforeInputEventPlugin.js +13 -13
  8. package/lib/CSSProperty.js +18 -3
  9. package/lib/CSSPropertyOperations.js +27 -14
  10. package/lib/CallbackQueue.js +4 -4
  11. package/lib/ChangeEventPlugin.js +15 -14
  12. package/lib/DOMChildrenOperations.js +22 -7
  13. package/lib/DOMProperty.js +8 -8
  14. package/lib/DOMPropertyOperations.js +23 -10
  15. package/lib/Danger.js +21 -16
  16. package/lib/DefaultEventPluginOrder.js +2 -2
  17. package/lib/EnterLeaveEventPlugin.js +18 -10
  18. package/lib/EventConstants.js +23 -1
  19. package/lib/EventPluginHub.js +29 -21
  20. package/lib/EventPluginRegistry.js +8 -8
  21. package/lib/EventPluginUtils.js +34 -38
  22. package/lib/EventPropagators.js +8 -8
  23. package/lib/FallbackCompositionState.js +9 -3
  24. package/lib/HTMLDOMPropertyConfig.js +24 -4
  25. package/lib/LinkedStateMixin.js +2 -2
  26. package/lib/LinkedValueUtils.js +8 -8
  27. package/lib/MetaMatchers.js +118 -0
  28. package/lib/OrderedMap.js +453 -0
  29. package/lib/PooledClass.js +3 -5
  30. package/lib/React.js +18 -7
  31. package/lib/ReactBrowserComponentMixin.js +4 -4
  32. package/lib/ReactBrowserEventEmitter.js +36 -7
  33. package/lib/ReactCSSTransitionGroup.js +35 -9
  34. package/lib/ReactCSSTransitionGroupChild.js +48 -30
  35. package/lib/ReactChildReconciler.js +24 -19
  36. package/lib/ReactChildren.js +72 -32
  37. package/lib/ReactClass.js +46 -46
  38. package/lib/ReactComponent.js +18 -16
  39. package/lib/ReactComponentBrowserEnvironment.js +2 -2
  40. package/lib/ReactComponentEnvironment.js +2 -2
  41. package/lib/ReactComponentWithPureRenderMixin.js +1 -1
  42. package/lib/ReactCompositeComponent.js +95 -44
  43. package/lib/ReactDOM.js +74 -159
  44. package/lib/ReactDOMComponent.js +235 -93
  45. package/lib/ReactDOMFactories.js +177 -0
  46. package/lib/{emptyObject.js → ReactDOMFeatureFlags.js} +6 -8
  47. package/lib/ReactDOMIDOperations.js +8 -81
  48. package/lib/ReactDOMInput.js +18 -9
  49. package/lib/ReactDOMOption.js +7 -7
  50. package/lib/ReactDOMSelect.js +9 -9
  51. package/lib/ReactDOMSelection.js +19 -3
  52. package/lib/ReactDOMServer.js +5 -3
  53. package/lib/ReactDOMTextComponent.js +33 -20
  54. package/lib/ReactDOMTextarea.js +14 -12
  55. package/lib/ReactDefaultBatchingStrategy.js +4 -4
  56. package/lib/ReactDefaultInjection.js +23 -25
  57. package/lib/ReactDefaultPerf.js +17 -11
  58. package/lib/ReactDefaultPerfAnalysis.js +13 -12
  59. package/lib/ReactElement.js +85 -39
  60. package/lib/ReactElementValidator.js +47 -90
  61. package/lib/ReactEmptyComponent.js +26 -62
  62. package/lib/ReactEmptyComponentRegistry.js +48 -0
  63. package/lib/ReactErrorUtils.js +53 -9
  64. package/lib/ReactEventEmitterMixin.js +2 -2
  65. package/lib/ReactEventListener.js +33 -21
  66. package/lib/ReactFragment.js +27 -118
  67. package/lib/ReactInjection.js +10 -12
  68. package/lib/ReactInputSelection.js +4 -4
  69. package/lib/ReactInstanceHandles.js +10 -11
  70. package/lib/ReactIsomorphic.js +15 -11
  71. package/lib/ReactLink.js +2 -2
  72. package/lib/ReactMarkupChecksum.js +6 -2
  73. package/lib/ReactMount.js +186 -85
  74. package/lib/ReactMultiChild.js +119 -25
  75. package/lib/ReactMultiChildUpdateTypes.js +2 -1
  76. package/lib/ReactNativeComponent.js +3 -3
  77. package/lib/ReactNoopUpdateQueue.js +3 -3
  78. package/lib/ReactOwner.js +3 -3
  79. package/lib/ReactPerf.js +2 -2
  80. package/lib/ReactPropTransferer.js +3 -3
  81. package/lib/ReactPropTypeLocationNames.js +1 -1
  82. package/lib/ReactPropTypeLocations.js +1 -1
  83. package/lib/ReactPropTypes.js +38 -9
  84. package/lib/ReactReconcileTransaction.js +10 -8
  85. package/lib/ReactReconciler.js +5 -6
  86. package/lib/ReactRef.js +14 -2
  87. package/lib/ReactServerBatchingStrategy.js +5 -5
  88. package/lib/ReactServerRendering.js +12 -12
  89. package/lib/ReactServerRenderingTransaction.js +6 -5
  90. package/lib/ReactTestUtils.js +47 -39
  91. package/lib/ReactTransitionChildMapping.js +3 -6
  92. package/lib/ReactTransitionEvents.js +1 -1
  93. package/lib/ReactTransitionGroup.js +5 -6
  94. package/lib/ReactUpdateQueue.js +19 -19
  95. package/lib/ReactUpdates.js +15 -15
  96. package/lib/{performance.js → ReactVersion.js} +3 -12
  97. package/lib/ReactWithAddons.js +24 -15
  98. package/lib/ResponderEventPlugin.js +514 -0
  99. package/lib/ResponderSyntheticEvent.js +40 -0
  100. package/lib/ResponderTouchHistoryStore.js +180 -0
  101. package/lib/SVGDOMPropertyConfig.js +1 -1
  102. package/lib/SelectEventPlugin.js +19 -9
  103. package/lib/SimpleEventPlugin.js +198 -43
  104. package/lib/SyntheticClipboardEvent.js +1 -1
  105. package/lib/SyntheticCompositionEvent.js +1 -1
  106. package/lib/SyntheticDragEvent.js +1 -1
  107. package/lib/SyntheticEvent.js +18 -4
  108. package/lib/SyntheticFocusEvent.js +1 -1
  109. package/lib/SyntheticInputEvent.js +1 -1
  110. package/lib/SyntheticKeyboardEvent.js +4 -4
  111. package/lib/SyntheticMouseEvent.js +3 -3
  112. package/lib/SyntheticTouchEvent.js +2 -2
  113. package/lib/SyntheticUIEvent.js +2 -2
  114. package/lib/SyntheticWheelEvent.js +1 -1
  115. package/lib/TapEventPlugin.js +119 -0
  116. package/lib/Transaction.js +7 -7
  117. package/lib/accumulate.js +44 -0
  118. package/lib/accumulateInto.js +2 -2
  119. package/lib/adler32.js +19 -7
  120. package/lib/cloneWithProps.js +11 -6
  121. package/lib/createHierarchyRenderer.js +85 -0
  122. package/lib/dangerousStyleValue.js +1 -1
  123. package/lib/deprecated.js +7 -6
  124. package/lib/findDOMNode.js +9 -9
  125. package/lib/flattenChildren.js +4 -4
  126. package/lib/getEventKey.js +1 -1
  127. package/lib/{isTextNode.js → getTestDocument.js} +7 -11
  128. package/lib/getTextContentAccessor.js +1 -1
  129. package/lib/instantiateReactComponent.js +15 -17
  130. package/lib/isEventSupported.js +1 -1
  131. package/lib/onlyChild.js +3 -3
  132. package/lib/quoteAttributeValueForBrowser.js +1 -1
  133. package/lib/reactComponentExpect.js +216 -0
  134. package/lib/renderSubtreeIntoContainer.js +1 -1
  135. package/lib/setInnerHTML.js +1 -1
  136. package/lib/setTextContent.js +3 -3
  137. package/lib/shallowCompare.js +1 -1
  138. package/lib/shouldUpdateReactComponent.js +12 -8
  139. package/lib/sliceChildren.js +34 -0
  140. package/lib/traverseAllChildren.js +25 -18
  141. package/lib/update.js +13 -13
  142. package/lib/validateDOMNesting.js +6 -6
  143. package/lib/webcomponents.js +6379 -0
  144. package/package.json +4 -6
  145. package/react.js +1 -51
  146. package/dist/JSXTransformer.js +0 -17588
  147. package/lib/CSSCore.js +0 -97
  148. package/lib/EventListener.js +0 -84
  149. package/lib/ExecutionEnvironment.js +0 -38
  150. package/lib/ReactDOMClient.js +0 -90
  151. package/lib/camelize.js +0 -32
  152. package/lib/camelizeStyleName.js +0 -40
  153. package/lib/containsNode.js +0 -55
  154. package/lib/createArrayFromMixed.js +0 -85
  155. package/lib/createNodesFromMarkup.js +0 -84
  156. package/lib/emptyFunction.js +0 -38
  157. package/lib/focusNode.js +0 -26
  158. package/lib/getActiveElement.js +0 -29
  159. package/lib/getMarkupWrap.js +0 -93
  160. package/lib/getUnboundedScrollPosition.js +0 -38
  161. package/lib/hyphenate.js +0 -33
  162. package/lib/hyphenateStyleName.js +0 -39
  163. package/lib/invariant.js +0 -49
  164. package/lib/isNode.js +0 -23
  165. package/lib/joinClasses.js +0 -39
  166. package/lib/keyMirror.js +0 -48
  167. package/lib/keyOf.js +0 -35
  168. package/lib/mapObject.js +0 -51
  169. package/lib/memoizeStringOnly.js +0 -31
  170. package/lib/performanceNow.js +0 -28
  171. package/lib/shallowEqual.js +0 -48
  172. package/lib/toArray.js +0 -57
  173. package/lib/warning.js +0 -57
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Copyright 2013-2015, 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 createHierarchyRenderer
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ var React = require('./React');
15
+
16
+ /**
17
+ * Creates a render method that makes it easier to create, render, and inspect a
18
+ * hierarchy of mock React component classes.
19
+ *
20
+ * A component class is created for each of the supplied render methods. Each
21
+ * render method is invoked with the classes created using the render methods
22
+ * that come after it in the supplied list of render methods.
23
+ *
24
+ * var renderHierarchy = createHierarchyRenderer(
25
+ * function ComponentA(ComponentB, ComponentC) {...},
26
+ * function ComponentB(ComponentC) {...},
27
+ * function ComponentC() {...}
28
+ * );
29
+ *
30
+ * When the hierarchy is invoked, a two-dimensional array is returned. Each
31
+ * array corresponds to a supplied render method and contains the instances
32
+ * returned by that render method in the order it was invoked.
33
+ *
34
+ * var instances = renderHierarchy(
35
+ * function(ComponentA[, ComponentB, ComponentC]) {
36
+ * ReactDOM.render(<ComponentA />, ...);
37
+ * })
38
+ * );
39
+ * instances[0][0]; // First return value of first render method.
40
+ * instances[1][0]; // First return value of second render method.
41
+ * instances[1][1]; // Second return value of second render method.
42
+ *
43
+ * Refs should be used to reference components that are not the return value of
44
+ * render methods.
45
+ *
46
+ * expect(instances[0][0].refs.X).toBe(...);
47
+ *
48
+ * NOTE: The component classes created for each render method are re-used for
49
+ * each invocation of the hierarchy renderer. If new classes are needed, you
50
+ * should re-execute `createHierarchyRenderer` with the same arguments.
51
+ *
52
+ * @param {array<function>} ...renderMethods
53
+ * @return {function}
54
+ */
55
+ function createHierarchyRenderer() {
56
+ for (var _len = arguments.length, renderMethods = Array(_len), _key = 0; _key < _len; _key++) {
57
+ renderMethods[_key] = arguments[_key];
58
+ }
59
+
60
+ var instances;
61
+ var Components = renderMethods.reduceRight(function (ComponentsAccumulator, renderMethod, depth) {
62
+ var Component = React.createClass({
63
+ displayName: renderMethod.name,
64
+ render: function () {
65
+ instances[depth].push(this);
66
+ return renderMethod.apply(this, ComponentsAccumulator);
67
+ }
68
+ });
69
+ return [Component].concat(ComponentsAccumulator);
70
+ }, []);
71
+ /**
72
+ * @param {function} renderComponent
73
+ * @return {array<array<*>>}
74
+ */
75
+ function renderHierarchy(renderComponent) {
76
+ instances = renderMethods.map(function () {
77
+ return [];
78
+ });
79
+ renderComponent.apply(null, Components);
80
+ return instances;
81
+ }
82
+ return renderHierarchy;
83
+ }
84
+
85
+ module.exports = createHierarchyRenderer;
@@ -12,7 +12,7 @@
12
12
 
13
13
  'use strict';
14
14
 
15
- var CSSProperty = require("./CSSProperty");
15
+ var CSSProperty = require('./CSSProperty');
16
16
 
17
17
  var isUnitlessNumber = CSSProperty.isUnitlessNumber;
18
18
 
package/lib/deprecated.js CHANGED
@@ -11,8 +11,8 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- var assign = require("./Object.assign");
15
- var warning = require("./warning");
14
+ var assign = require('./Object.assign');
15
+ var warning = require('fbjs/lib/warning');
16
16
 
17
17
  /**
18
18
  * This will log a single deprecation notice per function and forward the call
@@ -20,19 +20,20 @@ var warning = require("./warning");
20
20
  *
21
21
  * @param {string} fnName The name of the function
22
22
  * @param {string} newModule The module that fn will exist in
23
+ * @param {string} newPackage The module that fn will exist in
23
24
  * @param {*} ctx The context this forwarded call should run in
24
25
  * @param {function} fn The function to forward on to
25
26
  * @return {function} The function that will warn once and then call fn
26
27
  */
27
- function deprecated(fnName, newModule, ctx, fn) {
28
+ function deprecated(fnName, newModule, newPackage, ctx, fn) {
28
29
  var warned = false;
29
- if ('production' !== process.env.NODE_ENV) {
30
+ if (process.env.NODE_ENV !== 'production') {
30
31
  var newFn = function () {
31
- 'production' !== process.env.NODE_ENV ? warning(warned,
32
+ process.env.NODE_ENV !== 'production' ? warning(warned,
32
33
  // Require examples in this string must be split to prevent React's
33
34
  // build tools from mistaking them for real requires.
34
35
  // Otherwise the build tools will attempt to build a '%s' module.
35
- '`require' + '("react").%s` is deprecated. Please use `require' + '("%s").%s` ' + 'instead.', fnName, newModule, fnName) : undefined;
36
+ 'React.%s is deprecated. Please use %s.%s from require' + '(\'%s\') ' + 'instead.', fnName, newModule, fnName, newPackage) : undefined;
36
37
  warned = true;
37
38
  return fn.apply(ctx, arguments);
38
39
  };
@@ -12,12 +12,12 @@
12
12
 
13
13
  'use strict';
14
14
 
15
- var ReactCurrentOwner = require("./ReactCurrentOwner");
16
- var ReactInstanceMap = require("./ReactInstanceMap");
17
- var ReactMount = require("./ReactMount");
15
+ var ReactCurrentOwner = require('./ReactCurrentOwner');
16
+ var ReactInstanceMap = require('./ReactInstanceMap');
17
+ var ReactMount = require('./ReactMount');
18
18
 
19
- var invariant = require("./invariant");
20
- var warning = require("./warning");
19
+ var invariant = require('fbjs/lib/invariant');
20
+ var warning = require('fbjs/lib/warning');
21
21
 
22
22
  /**
23
23
  * Returns the DOM node rendered by this element.
@@ -26,10 +26,10 @@ var warning = require("./warning");
26
26
  * @return {?DOMElement} The root node of this element.
27
27
  */
28
28
  function findDOMNode(componentOrElement) {
29
- if ('production' !== process.env.NODE_ENV) {
29
+ if (process.env.NODE_ENV !== 'production') {
30
30
  var owner = ReactCurrentOwner.current;
31
31
  if (owner !== null) {
32
- 'production' !== process.env.NODE_ENV ? warning(owner._warnedAboutRefsInRender, '%s is accessing getDOMNode or findDOMNode inside its render(). ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', owner.getName() || 'A component') : undefined;
32
+ process.env.NODE_ENV !== 'production' ? warning(owner._warnedAboutRefsInRender, '%s is accessing getDOMNode or findDOMNode inside its render(). ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', owner.getName() || 'A component') : undefined;
33
33
  owner._warnedAboutRefsInRender = true;
34
34
  }
35
35
  }
@@ -42,8 +42,8 @@ function findDOMNode(componentOrElement) {
42
42
  if (ReactInstanceMap.has(componentOrElement)) {
43
43
  return ReactMount.getNodeFromInstance(componentOrElement);
44
44
  }
45
- !(componentOrElement.render == null || typeof componentOrElement.render !== 'function') ? 'production' !== process.env.NODE_ENV ? invariant(false, 'Component (with keys: %s) contains `render` method ' + 'but is not mounted in the DOM', Object.keys(componentOrElement)) : invariant(false) : undefined;
46
- !false ? 'production' !== process.env.NODE_ENV ? invariant(false, 'Element appears to be neither ReactComponent nor DOMNode (keys: %s)', Object.keys(componentOrElement)) : invariant(false) : undefined;
45
+ !(componentOrElement.render == null || typeof componentOrElement.render !== 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'findDOMNode was called on an unmounted component.') : invariant(false) : undefined;
46
+ !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Element appears to be neither ReactComponent nor DOMNode (keys: %s)', Object.keys(componentOrElement)) : invariant(false) : undefined;
47
47
  }
48
48
 
49
49
  module.exports = findDOMNode;
@@ -11,8 +11,8 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- var traverseAllChildren = require("./traverseAllChildren");
15
- var warning = require("./warning");
14
+ var traverseAllChildren = require('./traverseAllChildren');
15
+ var warning = require('fbjs/lib/warning');
16
16
 
17
17
  /**
18
18
  * @param {function} traverseContext Context passed through traversal.
@@ -23,8 +23,8 @@ function flattenSingleChildIntoContext(traverseContext, child, name) {
23
23
  // We found a component instance.
24
24
  var result = traverseContext;
25
25
  var keyUnique = result[name] === undefined;
26
- if ('production' !== process.env.NODE_ENV) {
27
- 'production' !== process.env.NODE_ENV ? warning(keyUnique, 'flattenChildren(...): Encountered two children with the same key, ' + '`%s`. Child keys must be unique; when two children share a key, only ' + 'the first child will be used.', name) : undefined;
26
+ if (process.env.NODE_ENV !== 'production') {
27
+ process.env.NODE_ENV !== 'production' ? warning(keyUnique, 'flattenChildren(...): Encountered two children with the same key, ' + '`%s`. Child keys must be unique; when two children share a key, only ' + 'the first child will be used.', name) : undefined;
28
28
  }
29
29
  if (keyUnique && child != null) {
30
30
  result[name] = child;
@@ -12,7 +12,7 @@
12
12
 
13
13
  'use strict';
14
14
 
15
- var getEventCharCode = require("./getEventCharCode");
15
+ var getEventCharCode = require('./getEventCharCode');
16
16
 
17
17
  /**
18
18
  * Normalization of deprecated HTML5 `key` values
@@ -6,20 +6,16 @@
6
6
  * LICENSE file in the root directory of this source tree. An additional grant
7
7
  * of patent rights can be found in the PATENTS file in the same directory.
8
8
  *
9
- * @providesModule isTextNode
10
- * @typechecks
9
+ * @providesModule getTestDocument
11
10
  */
12
11
 
13
12
  'use strict';
14
13
 
15
- var isNode = require("./isNode");
16
-
17
- /**
18
- * @param {*} object The object to check.
19
- * @return {boolean} Whether or not the object is a DOM text node.
20
- */
21
- function isTextNode(object) {
22
- return isNode(object) && object.nodeType == 3;
14
+ function getTestDocument(markup) {
15
+ document.open();
16
+ document.write(markup || '<!doctype html><html><meta charset=utf-8><title>test doc</title>');
17
+ document.close();
18
+ return document;
23
19
  }
24
20
 
25
- module.exports = isTextNode;
21
+ module.exports = getTestDocument;
@@ -11,7 +11,7 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- var ExecutionEnvironment = require("./ExecutionEnvironment");
14
+ var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
15
15
 
16
16
  var contentKey = null;
17
17
 
@@ -12,13 +12,13 @@
12
12
 
13
13
  'use strict';
14
14
 
15
- var ReactCompositeComponent = require("./ReactCompositeComponent");
16
- var ReactEmptyComponent = require("./ReactEmptyComponent");
17
- var ReactNativeComponent = require("./ReactNativeComponent");
15
+ var ReactCompositeComponent = require('./ReactCompositeComponent');
16
+ var ReactEmptyComponent = require('./ReactEmptyComponent');
17
+ var ReactNativeComponent = require('./ReactNativeComponent');
18
18
 
19
- var assign = require("./Object.assign");
20
- var invariant = require("./invariant");
21
- var warning = require("./warning");
19
+ var assign = require('./Object.assign');
20
+ var invariant = require('fbjs/lib/invariant');
21
+ var warning = require('fbjs/lib/warning');
22
22
 
23
23
  // To avoid a cyclic dependency, we create the final class in this module
24
24
  var ReactCompositeComponentWrapper = function () {};
@@ -58,19 +58,17 @@ function instantiateReactComponent(node) {
58
58
  var instance;
59
59
 
60
60
  if (node === null || node === false) {
61
- node = ReactEmptyComponent.emptyElement;
62
- }
63
-
64
- if (typeof node === 'object') {
61
+ instance = new ReactEmptyComponent(instantiateReactComponent);
62
+ } else if (typeof node === 'object') {
65
63
  var element = node;
66
- !(element && (typeof element.type === 'function' || typeof element.type === 'string')) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'Element type is invalid: expected a string (for built-in components) ' + 'or a class/function (for composite components) but got: %s.%s', element.type == null ? element.type : typeof element.type, getDeclarationErrorAddendum(element._owner)) : invariant(false) : undefined;
64
+ !(element && (typeof element.type === 'function' || typeof element.type === 'string')) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Element type is invalid: expected a string (for built-in components) ' + 'or a class/function (for composite components) but got: %s.%s', element.type == null ? element.type : typeof element.type, getDeclarationErrorAddendum(element._owner)) : invariant(false) : undefined;
67
65
 
68
66
  // Special case string values
69
67
  if (typeof element.type === 'string') {
70
68
  instance = ReactNativeComponent.createInternalComponent(element);
71
69
  } else if (isInternalComponentType(element.type)) {
72
70
  // This is temporarily available for custom components that are not string
73
- // represenations. I.e. ART. Once those are updated to use the string
71
+ // representations. I.e. ART. Once those are updated to use the string
74
72
  // representation, we can drop this code path.
75
73
  instance = new element.type(element);
76
74
  } else {
@@ -79,11 +77,11 @@ function instantiateReactComponent(node) {
79
77
  } else if (typeof node === 'string' || typeof node === 'number') {
80
78
  instance = ReactNativeComponent.createInstanceForText(node);
81
79
  } else {
82
- !false ? 'production' !== process.env.NODE_ENV ? invariant(false, 'Encountered invalid React node of type %s', typeof node) : invariant(false) : undefined;
80
+ !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Encountered invalid React node of type %s', typeof node) : invariant(false) : undefined;
83
81
  }
84
82
 
85
- if ('production' !== process.env.NODE_ENV) {
86
- 'production' !== process.env.NODE_ENV ? warning(typeof instance.construct === 'function' && typeof instance.mountComponent === 'function' && typeof instance.receiveComponent === 'function' && typeof instance.unmountComponent === 'function', 'Only React Components can be mounted.') : undefined;
83
+ if (process.env.NODE_ENV !== 'production') {
84
+ process.env.NODE_ENV !== 'production' ? warning(typeof instance.construct === 'function' && typeof instance.mountComponent === 'function' && typeof instance.receiveComponent === 'function' && typeof instance.unmountComponent === 'function', 'Only React Components can be mounted.') : undefined;
87
85
  }
88
86
 
89
87
  // Sets up the instance. This can probably just move into the constructor now.
@@ -95,14 +93,14 @@ function instantiateReactComponent(node) {
95
93
  instance._mountIndex = 0;
96
94
  instance._mountImage = null;
97
95
 
98
- if ('production' !== process.env.NODE_ENV) {
96
+ if (process.env.NODE_ENV !== 'production') {
99
97
  instance._isOwnerNecessary = false;
100
98
  instance._warnedAboutRefsInRender = false;
101
99
  }
102
100
 
103
101
  // Internal instances should fully constructed at this point, so they should
104
102
  // not get any new fields added to them at this point.
105
- if ('production' !== process.env.NODE_ENV) {
103
+ if (process.env.NODE_ENV !== 'production') {
106
104
  if (Object.preventExtensions) {
107
105
  Object.preventExtensions(instance);
108
106
  }
@@ -11,7 +11,7 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- var ExecutionEnvironment = require("./ExecutionEnvironment");
14
+ var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
15
15
 
16
16
  var useHasFeature;
17
17
  if (ExecutionEnvironment.canUseDOM) {
package/lib/onlyChild.js CHANGED
@@ -10,9 +10,9 @@
10
10
  */
11
11
  'use strict';
12
12
 
13
- var ReactElement = require("./ReactElement");
13
+ var ReactElement = require('./ReactElement');
14
14
 
15
- var invariant = require("./invariant");
15
+ var invariant = require('fbjs/lib/invariant');
16
16
 
17
17
  /**
18
18
  * Returns the first child in a collection of children and verifies that there
@@ -26,7 +26,7 @@ var invariant = require("./invariant");
26
26
  * structure.
27
27
  */
28
28
  function onlyChild(children) {
29
- !ReactElement.isValidElement(children) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'onlyChild must be passed a children with exactly one child.') : invariant(false) : undefined;
29
+ !ReactElement.isValidElement(children) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'onlyChild must be passed a children with exactly one child.') : invariant(false) : undefined;
30
30
  return children;
31
31
  }
32
32
 
@@ -11,7 +11,7 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- var escapeTextContentForBrowser = require("./escapeTextContentForBrowser");
14
+ var escapeTextContentForBrowser = require('./escapeTextContentForBrowser');
15
15
 
16
16
  /**
17
17
  * Escapes attribute value to prevent scripting attacks.
@@ -0,0 +1,216 @@
1
+ /**
2
+ * Copyright 2013-2015, 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 reactComponentExpect
10
+ * @nolint
11
+ */
12
+
13
+ 'use strict';
14
+
15
+ var ReactInstanceMap = require('./ReactInstanceMap');
16
+ var ReactTestUtils = require('./ReactTestUtils');
17
+
18
+ var assign = require('./Object.assign');
19
+ var invariant = require('fbjs/lib/invariant');
20
+
21
+ function reactComponentExpect(instance) {
22
+ if (instance instanceof reactComponentExpectInternal) {
23
+ return instance;
24
+ }
25
+
26
+ if (!(this instanceof reactComponentExpect)) {
27
+ return new reactComponentExpect(instance);
28
+ }
29
+
30
+ expect(instance).not.toBeNull();
31
+ expect(instance).not.toBeUndefined();
32
+
33
+ !ReactTestUtils.isCompositeComponent(instance) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'reactComponentExpect(...): instance must be a composite component') : invariant(false) : undefined;
34
+ var internalInstance = ReactInstanceMap.get(instance);
35
+
36
+ expect(typeof internalInstance).toBe('object');
37
+ expect(typeof internalInstance.constructor).toBe('function');
38
+ expect(ReactTestUtils.isElement(internalInstance)).toBe(false);
39
+
40
+ return new reactComponentExpectInternal(internalInstance);
41
+ }
42
+
43
+ function reactComponentExpectInternal(internalInstance) {
44
+ this._instance = internalInstance;
45
+ }
46
+
47
+ assign(reactComponentExpectInternal.prototype, {
48
+ // Getters -------------------------------------------------------------------
49
+
50
+ /**
51
+ * @instance: Retrieves the backing instance.
52
+ */
53
+ instance: function () {
54
+ return this._instance.getPublicInstance();
55
+ },
56
+
57
+ /**
58
+ * There are two types of components in the world.
59
+ * - A component created via React.createClass() - Has a single child
60
+ * subComponent - the return value from the .render() function. This
61
+ * function @subComponent expects that this._instance is component created
62
+ * with React.createClass().
63
+ * - A primitive DOM component - which has many renderedChildren, each of
64
+ * which may have a name that is unique with respect to its siblings. This
65
+ * method will fail if this._instance is a primitive component.
66
+ *
67
+ * TL;DR: An instance may have a subComponent (this._renderedComponent) or
68
+ * renderedChildren, but never both. Neither will actually show up until you
69
+ * render the component (simply instantiating is not enough).
70
+ */
71
+ expectRenderedChild: function () {
72
+ this.toBeCompositeComponent();
73
+ var child = this._instance._renderedComponent;
74
+ // TODO: Hide ReactEmptyComponent instances here?
75
+ return new reactComponentExpectInternal(child);
76
+ },
77
+
78
+ /**
79
+ * The nth child of a DOMish component instance that is not falsy.
80
+ */
81
+ expectRenderedChildAt: function (childIndex) {
82
+ // Currently only dom components have arrays of children, but that will
83
+ // change soon.
84
+ this.toBeDOMComponent();
85
+ var renderedChildren = this._instance._renderedChildren || {};
86
+ for (var name in renderedChildren) {
87
+ if (!renderedChildren.hasOwnProperty(name)) {
88
+ continue;
89
+ }
90
+ if (renderedChildren[name]) {
91
+ if (renderedChildren[name]._mountIndex === childIndex) {
92
+ return new reactComponentExpectInternal(renderedChildren[name]);
93
+ }
94
+ }
95
+ }
96
+ throw new Error('Child:' + childIndex + ' is not found');
97
+ },
98
+
99
+ toBeDOMComponentWithChildCount: function (count) {
100
+ this.toBeDOMComponent();
101
+ var renderedChildren = this._instance._renderedChildren;
102
+ expect(renderedChildren).toBeTruthy();
103
+ expect(Object.keys(renderedChildren).length).toBe(count);
104
+ return this;
105
+ },
106
+
107
+ toBeDOMComponentWithNoChildren: function () {
108
+ this.toBeDOMComponent();
109
+ expect(this._instance._renderedChildren).toBeFalsy();
110
+ return this;
111
+ },
112
+
113
+ // Matchers ------------------------------------------------------------------
114
+
115
+ toBeComponentOfType: function (constructor) {
116
+ expect(this._instance._currentElement.type === constructor).toBe(true);
117
+ return this;
118
+ },
119
+
120
+ /**
121
+ * A component that is created with React.createClass. Just duck typing
122
+ * here.
123
+ */
124
+ toBeCompositeComponent: function () {
125
+ expect(typeof this.instance() === 'object' && typeof this.instance().render === 'function').toBe(true);
126
+ return this;
127
+ },
128
+
129
+ toBeCompositeComponentWithType: function (constructor) {
130
+ this.toBeCompositeComponent();
131
+ expect(this._instance._currentElement.type === constructor).toBe(true);
132
+ return this;
133
+ },
134
+
135
+ toBeTextComponentWithValue: function (val) {
136
+ var elementType = typeof this._instance._currentElement;
137
+ expect(elementType === 'string' || elementType === 'number').toBe(true);
138
+ expect(this._instance._stringText).toBe(val);
139
+ return this;
140
+ },
141
+
142
+ toBeEmptyComponent: function () {
143
+ var element = this._instance._currentElement;
144
+ return element === null || element === false;
145
+ },
146
+
147
+ toBePresent: function () {
148
+ expect(this.instance()).toBeTruthy();
149
+ return this;
150
+ },
151
+
152
+ /**
153
+ * A terminal type of component representing some virtual dom node. Just duck
154
+ * typing here.
155
+ */
156
+ toBeDOMComponent: function () {
157
+ expect(ReactTestUtils.isDOMComponent(this.instance())).toBe(true);
158
+ return this;
159
+ },
160
+
161
+ /**
162
+ * @deprecated
163
+ * @see toBeComponentOfType
164
+ */
165
+ toBeDOMComponentWithTag: function (tag) {
166
+ this.toBeDOMComponent();
167
+ expect(this.instance().tagName).toBe(tag.toUpperCase());
168
+ return this;
169
+ },
170
+
171
+ /**
172
+ * Check that internal state values are equal to a state of expected values.
173
+ */
174
+ scalarStateEqual: function (stateNameToExpectedValue) {
175
+ expect(this.instance()).toBeTruthy();
176
+ for (var stateName in stateNameToExpectedValue) {
177
+ if (!stateNameToExpectedValue.hasOwnProperty(stateName)) {
178
+ continue;
179
+ }
180
+ expect(this.instance().state[stateName]).toEqual(stateNameToExpectedValue[stateName]);
181
+ }
182
+ return this;
183
+ },
184
+
185
+ /**
186
+ * Check a set of props are equal to a set of expected values - only works
187
+ * with scalars.
188
+ */
189
+ scalarPropsEqual: function (propNameToExpectedValue) {
190
+ expect(this.instance()).toBeTruthy();
191
+ for (var propName in propNameToExpectedValue) {
192
+ if (!propNameToExpectedValue.hasOwnProperty(propName)) {
193
+ continue;
194
+ }
195
+ expect(this.instance().props[propName]).toEqual(propNameToExpectedValue[propName]);
196
+ }
197
+ return this;
198
+ },
199
+
200
+ /**
201
+ * Check a set of props are equal to a set of expected values - only works
202
+ * with scalars.
203
+ */
204
+ scalarContextEqual: function (contextNameToExpectedValue) {
205
+ expect(this.instance()).toBeTruthy();
206
+ for (var contextName in contextNameToExpectedValue) {
207
+ if (!contextNameToExpectedValue.hasOwnProperty(contextName)) {
208
+ continue;
209
+ }
210
+ expect(this.instance().context[contextName]).toEqual(contextNameToExpectedValue[contextName]);
211
+ }
212
+ return this;
213
+ }
214
+ });
215
+
216
+ module.exports = reactComponentExpect;