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
@@ -14,6 +14,8 @@
14
14
  var EventConstants = require("./EventConstants");
15
15
  var EventPluginHub = require("./EventPluginHub");
16
16
 
17
+ var warning = require("./warning");
18
+
17
19
  var accumulateInto = require("./accumulateInto");
18
20
  var forEachAccumulated = require("./forEachAccumulated");
19
21
 
@@ -25,8 +27,7 @@ var getListener = EventPluginHub.getListener;
25
27
  * "phases" of propagation. This finds listeners by a given phase.
26
28
  */
27
29
  function listenerAtPhase(id, event, propagationPhase) {
28
- var registrationName =
29
- event.dispatchConfig.phasedRegistrationNames[propagationPhase];
30
+ var registrationName = event.dispatchConfig.phasedRegistrationNames[propagationPhase];
30
31
  return getListener(id, registrationName);
31
32
  }
32
33
 
@@ -37,16 +38,13 @@ function listenerAtPhase(id, event, propagationPhase) {
37
38
  * "dispatch" object that pairs the event with the listener.
38
39
  */
39
40
  function accumulateDirectionalDispatches(domID, upwards, event) {
40
- if ("production" !== process.env.NODE_ENV) {
41
- if (!domID) {
42
- throw new Error('Dispatching id must not be null');
43
- }
41
+ if ('production' !== process.env.NODE_ENV) {
42
+ 'production' !== process.env.NODE_ENV ? warning(domID, 'Dispatching id must not be null') : undefined;
44
43
  }
45
44
  var phase = upwards ? PropagationPhases.bubbled : PropagationPhases.captured;
46
45
  var listener = listenerAtPhase(domID, event, phase);
47
46
  if (listener) {
48
- event._dispatchListeners =
49
- accumulateInto(event._dispatchListeners, listener);
47
+ event._dispatchListeners = accumulateInto(event._dispatchListeners, listener);
50
48
  event._dispatchIDs = accumulateInto(event._dispatchIDs, domID);
51
49
  }
52
50
  }
@@ -60,14 +58,18 @@ function accumulateDirectionalDispatches(domID, upwards, event) {
60
58
  */
61
59
  function accumulateTwoPhaseDispatchesSingle(event) {
62
60
  if (event && event.dispatchConfig.phasedRegistrationNames) {
63
- EventPluginHub.injection.getInstanceHandle().traverseTwoPhase(
64
- event.dispatchMarker,
65
- accumulateDirectionalDispatches,
66
- event
67
- );
61
+ EventPluginHub.injection.getInstanceHandle().traverseTwoPhase(event.dispatchMarker, accumulateDirectionalDispatches, event);
68
62
  }
69
63
  }
70
64
 
65
+ /**
66
+ * Same as `accumulateTwoPhaseDispatchesSingle`, but skips over the targetID.
67
+ */
68
+ function accumulateTwoPhaseDispatchesSingleSkipTarget(event) {
69
+ if (event && event.dispatchConfig.phasedRegistrationNames) {
70
+ EventPluginHub.injection.getInstanceHandle().traverseTwoPhaseSkipTarget(event.dispatchMarker, accumulateDirectionalDispatches, event);
71
+ }
72
+ }
71
73
 
72
74
  /**
73
75
  * Accumulates without regard to direction, does not look for phased
@@ -79,8 +81,7 @@ function accumulateDispatches(id, ignoredDirection, event) {
79
81
  var registrationName = event.dispatchConfig.registrationName;
80
82
  var listener = getListener(id, registrationName);
81
83
  if (listener) {
82
- event._dispatchListeners =
83
- accumulateInto(event._dispatchListeners, listener);
84
+ event._dispatchListeners = accumulateInto(event._dispatchListeners, listener);
84
85
  event._dispatchIDs = accumulateInto(event._dispatchIDs, id);
85
86
  }
86
87
  }
@@ -101,23 +102,18 @@ function accumulateTwoPhaseDispatches(events) {
101
102
  forEachAccumulated(events, accumulateTwoPhaseDispatchesSingle);
102
103
  }
103
104
 
104
- function accumulateEnterLeaveDispatches(leave, enter, fromID, toID) {
105
- EventPluginHub.injection.getInstanceHandle().traverseEnterLeave(
106
- fromID,
107
- toID,
108
- accumulateDispatches,
109
- leave,
110
- enter
111
- );
105
+ function accumulateTwoPhaseDispatchesSkipTarget(events) {
106
+ forEachAccumulated(events, accumulateTwoPhaseDispatchesSingleSkipTarget);
112
107
  }
113
108
 
109
+ function accumulateEnterLeaveDispatches(leave, enter, fromID, toID) {
110
+ EventPluginHub.injection.getInstanceHandle().traverseEnterLeave(fromID, toID, accumulateDispatches, leave, enter);
111
+ }
114
112
 
115
113
  function accumulateDirectDispatches(events) {
116
114
  forEachAccumulated(events, accumulateDirectDispatchesSingle);
117
115
  }
118
116
 
119
-
120
-
121
117
  /**
122
118
  * A small set of propagation patterns, each of which will accept a small amount
123
119
  * of information, and generate a set of "dispatch ready event objects" - which
@@ -131,8 +127,9 @@ function accumulateDirectDispatches(events) {
131
127
  */
132
128
  var EventPropagators = {
133
129
  accumulateTwoPhaseDispatches: accumulateTwoPhaseDispatches,
130
+ accumulateTwoPhaseDispatchesSkipTarget: accumulateTwoPhaseDispatchesSkipTarget,
134
131
  accumulateDirectDispatches: accumulateDirectDispatches,
135
132
  accumulateEnterLeaveDispatches: accumulateEnterLeaveDispatches
136
133
  };
137
134
 
138
- module.exports = EventPropagators;
135
+ module.exports = EventPropagators;
@@ -11,12 +11,9 @@
11
11
 
12
12
  /*jslint evil: true */
13
13
 
14
- "use strict";
14
+ 'use strict';
15
15
 
16
- var canUseDOM = !!(
17
- (typeof window !== 'undefined' &&
18
- window.document && window.document.createElement)
19
- );
16
+ var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
20
17
 
21
18
  /**
22
19
  * Simple, lightweight module assisting with the detection and context of
@@ -30,8 +27,7 @@ var ExecutionEnvironment = {
30
27
 
31
28
  canUseWorkers: typeof Worker !== 'undefined',
32
29
 
33
- canUseEventListeners:
34
- canUseDOM && !!(window.addEventListener || window.attachEvent),
30
+ canUseEventListeners: canUseDOM && !!(window.addEventListener || window.attachEvent),
35
31
 
36
32
  canUseViewport: canUseDOM && !!window.screen,
37
33
 
@@ -39,4 +35,4 @@ var ExecutionEnvironment = {
39
35
 
40
36
  };
41
37
 
42
- module.exports = ExecutionEnvironment;
38
+ module.exports = ExecutionEnvironment;
@@ -40,7 +40,7 @@ assign(FallbackCompositionState.prototype, {
40
40
  *
41
41
  * @return {string}
42
42
  */
43
- getText: function() {
43
+ getText: function () {
44
44
  if ('value' in this._root) {
45
45
  return this._root.value;
46
46
  }
@@ -53,7 +53,7 @@ assign(FallbackCompositionState.prototype, {
53
53
  *
54
54
  * @return {string}
55
55
  */
56
- getData: function() {
56
+ getData: function () {
57
57
  if (this._fallbackText) {
58
58
  return this._fallbackText;
59
59
  }
@@ -86,4 +86,4 @@ assign(FallbackCompositionState.prototype, {
86
86
 
87
87
  PooledClass.addPoolingTo(FallbackCompositionState);
88
88
 
89
- module.exports = FallbackCompositionState;
89
+ module.exports = FallbackCompositionState;
@@ -9,8 +9,6 @@
9
9
  * @providesModule HTMLDOMPropertyConfig
10
10
  */
11
11
 
12
- /*jslint bitwise: true*/
13
-
14
12
  'use strict';
15
13
 
16
14
  var DOMProperty = require("./DOMProperty");
@@ -21,29 +19,17 @@ var MUST_USE_PROPERTY = DOMProperty.injection.MUST_USE_PROPERTY;
21
19
  var HAS_BOOLEAN_VALUE = DOMProperty.injection.HAS_BOOLEAN_VALUE;
22
20
  var HAS_SIDE_EFFECTS = DOMProperty.injection.HAS_SIDE_EFFECTS;
23
21
  var HAS_NUMERIC_VALUE = DOMProperty.injection.HAS_NUMERIC_VALUE;
24
- var HAS_POSITIVE_NUMERIC_VALUE =
25
- DOMProperty.injection.HAS_POSITIVE_NUMERIC_VALUE;
26
- var HAS_OVERLOADED_BOOLEAN_VALUE =
27
- DOMProperty.injection.HAS_OVERLOADED_BOOLEAN_VALUE;
22
+ var HAS_POSITIVE_NUMERIC_VALUE = DOMProperty.injection.HAS_POSITIVE_NUMERIC_VALUE;
23
+ var HAS_OVERLOADED_BOOLEAN_VALUE = DOMProperty.injection.HAS_OVERLOADED_BOOLEAN_VALUE;
28
24
 
29
25
  var hasSVG;
30
26
  if (ExecutionEnvironment.canUseDOM) {
31
27
  var implementation = document.implementation;
32
- hasSVG = (
33
- implementation &&
34
- implementation.hasFeature &&
35
- implementation.hasFeature(
36
- 'http://www.w3.org/TR/SVG11/feature#BasicStructure',
37
- '1.1'
38
- )
39
- );
28
+ hasSVG = implementation && implementation.hasFeature && implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#BasicStructure', '1.1');
40
29
  }
41
30
 
42
-
43
31
  var HTMLDOMPropertyConfig = {
44
- isCustomAttribute: RegExp.prototype.test.bind(
45
- /^(data|aria)-[a-z_][a-z\d_.\-]*$/
46
- ),
32
+ isCustomAttribute: RegExp.prototype.test.bind(/^(data|aria)-[a-z_][a-z\d_.\-]*$/),
47
33
  Properties: {
48
34
  /**
49
35
  * Standard Properties
@@ -57,12 +43,14 @@ var HTMLDOMPropertyConfig = {
57
43
  alt: null,
58
44
  async: HAS_BOOLEAN_VALUE,
59
45
  autoComplete: null,
60
- // autoFocus is polyfilled/normalized by AutoFocusMixin
46
+ // autoFocus is polyfilled/normalized by AutoFocusUtils
61
47
  // autoFocus: HAS_BOOLEAN_VALUE,
62
48
  autoPlay: HAS_BOOLEAN_VALUE,
49
+ capture: MUST_USE_ATTRIBUTE | HAS_BOOLEAN_VALUE,
63
50
  cellPadding: null,
64
51
  cellSpacing: null,
65
52
  charSet: MUST_USE_ATTRIBUTE,
53
+ challenge: MUST_USE_ATTRIBUTE,
66
54
  checked: MUST_USE_PROPERTY | HAS_BOOLEAN_VALUE,
67
55
  classID: MUST_USE_ATTRIBUTE,
68
56
  // To set className on SVG elements, it's necessary to use .setAttribute;
@@ -104,6 +92,9 @@ var HTMLDOMPropertyConfig = {
104
92
  httpEquiv: null,
105
93
  icon: null,
106
94
  id: MUST_USE_PROPERTY,
95
+ is: MUST_USE_ATTRIBUTE,
96
+ keyParams: MUST_USE_ATTRIBUTE,
97
+ keyType: MUST_USE_ATTRIBUTE,
107
98
  label: null,
108
99
  lang: null,
109
100
  list: MUST_USE_ATTRIBUTE,
@@ -118,6 +109,7 @@ var HTMLDOMPropertyConfig = {
118
109
  mediaGroup: null,
119
110
  method: null,
120
111
  min: null,
112
+ minLength: MUST_USE_ATTRIBUTE,
121
113
  multiple: MUST_USE_PROPERTY | HAS_BOOLEAN_VALUE,
122
114
  muted: MUST_USE_PROPERTY | HAS_BOOLEAN_VALUE,
123
115
  name: null,
@@ -180,6 +172,9 @@ var HTMLDOMPropertyConfig = {
180
172
  itemRef: MUST_USE_ATTRIBUTE,
181
173
  // property is supported for OpenGraph in meta tags.
182
174
  property: null,
175
+ // IE-only attribute that specifies security restrictions on an iframe
176
+ // as an alternative to the sandbox attribute on IE<10
177
+ security: MUST_USE_ATTRIBUTE,
183
178
  // IE-only attribute that controls focus behavior
184
179
  unselectable: MUST_USE_ATTRIBUTE
185
180
  },
@@ -206,4 +201,4 @@ var HTMLDOMPropertyConfig = {
206
201
  }
207
202
  };
208
203
 
209
- module.exports = HTMLDOMPropertyConfig;
204
+ module.exports = HTMLDOMPropertyConfig;
@@ -28,12 +28,9 @@ var LinkedStateMixin = {
28
28
  * if you're using Google Closure Compiler advanced mode.
29
29
  * @return {ReactLink} ReactLink instance linking to the state.
30
30
  */
31
- linkState: function(key) {
32
- return new ReactLink(
33
- this.state[key],
34
- ReactStateSetters.createStateKeySetter(this, key)
35
- );
31
+ linkState: function (key) {
32
+ return new ReactLink(this.state[key], ReactStateSetters.createStateKeySetter(this, key));
36
33
  }
37
34
  };
38
35
 
39
- module.exports = LinkedStateMixin;
36
+ module.exports = LinkedStateMixin;
@@ -13,8 +13,10 @@
13
13
  'use strict';
14
14
 
15
15
  var ReactPropTypes = require("./ReactPropTypes");
16
+ var ReactPropTypeLocations = require("./ReactPropTypeLocations");
16
17
 
17
18
  var invariant = require("./invariant");
19
+ var warning = require("./warning");
18
20
 
19
21
  var hasReadOnlyValue = {
20
22
  'button': true,
@@ -26,46 +28,44 @@ var hasReadOnlyValue = {
26
28
  'submit': true
27
29
  };
28
30
 
29
- function _assertSingleLink(input) {
30
- ("production" !== process.env.NODE_ENV ? invariant(
31
- input.props.checkedLink == null || input.props.valueLink == null,
32
- 'Cannot provide a checkedLink and a valueLink. If you want to use ' +
33
- 'checkedLink, you probably don\'t want to use valueLink and vice versa.'
34
- ) : invariant(input.props.checkedLink == null || input.props.valueLink == null));
31
+ function _assertSingleLink(inputProps) {
32
+ !(inputProps.checkedLink == null || inputProps.valueLink == null) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'Cannot provide a checkedLink and a valueLink. If you want to use ' + 'checkedLink, you probably don\'t want to use valueLink and vice versa.') : invariant(false) : undefined;
35
33
  }
36
- function _assertValueLink(input) {
37
- _assertSingleLink(input);
38
- ("production" !== process.env.NODE_ENV ? invariant(
39
- input.props.value == null && input.props.onChange == null,
40
- 'Cannot provide a valueLink and a value or onChange event. If you want ' +
41
- 'to use value or onChange, you probably don\'t want to use valueLink.'
42
- ) : invariant(input.props.value == null && input.props.onChange == null));
34
+ function _assertValueLink(inputProps) {
35
+ _assertSingleLink(inputProps);
36
+ !(inputProps.value == null && inputProps.onChange == null) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'Cannot provide a valueLink and a value or onChange event. If you want ' + 'to use value or onChange, you probably don\'t want to use valueLink.') : invariant(false) : undefined;
43
37
  }
44
38
 
45
- function _assertCheckedLink(input) {
46
- _assertSingleLink(input);
47
- ("production" !== process.env.NODE_ENV ? invariant(
48
- input.props.checked == null && input.props.onChange == null,
49
- 'Cannot provide a checkedLink and a checked property or onChange event. ' +
50
- 'If you want to use checked or onChange, you probably don\'t want to ' +
51
- 'use checkedLink'
52
- ) : invariant(input.props.checked == null && input.props.onChange == null));
39
+ function _assertCheckedLink(inputProps) {
40
+ _assertSingleLink(inputProps);
41
+ !(inputProps.checked == null && inputProps.onChange == null) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'Cannot provide a checkedLink and a checked property or onChange event. ' + 'If you want to use checked or onChange, you probably don\'t want to ' + 'use checkedLink') : invariant(false) : undefined;
53
42
  }
54
43
 
55
- /**
56
- * @param {SyntheticEvent} e change event to handle
57
- */
58
- function _handleLinkedValueChange(e) {
59
- /*jshint validthis:true */
60
- this.props.valueLink.requestChange(e.target.value);
61
- }
44
+ var propTypes = {
45
+ value: function (props, propName, componentName) {
46
+ if (!props[propName] || hasReadOnlyValue[props.type] || props.onChange || props.readOnly || props.disabled) {
47
+ return null;
48
+ }
49
+ return new Error('You provided a `value` prop to a form field without an ' + '`onChange` handler. This will render a read-only field. If ' + 'the field should be mutable use `defaultValue`. Otherwise, ' + 'set either `onChange` or `readOnly`.');
50
+ },
51
+ checked: function (props, propName, componentName) {
52
+ if (!props[propName] || props.onChange || props.readOnly || props.disabled) {
53
+ return null;
54
+ }
55
+ return new Error('You provided a `checked` prop to a form field without an ' + '`onChange` handler. This will render a read-only field. If ' + 'the field should be mutable use `defaultChecked`. Otherwise, ' + 'set either `onChange` or `readOnly`.');
56
+ },
57
+ onChange: ReactPropTypes.func
58
+ };
62
59
 
63
- /**
64
- * @param {SyntheticEvent} e change event to handle
65
- */
66
- function _handleLinkedCheckChange(e) {
67
- /*jshint validthis:true */
68
- this.props.checkedLink.requestChange(e.target.checked);
60
+ var loggedTypeFailures = {};
61
+ function getDeclarationErrorAddendum(owner) {
62
+ if (owner) {
63
+ var name = owner.getName();
64
+ if (name) {
65
+ return ' Check the render method of `' + name + '`.';
66
+ }
67
+ }
68
+ return '';
69
69
  }
70
70
 
71
71
  /**
@@ -73,80 +73,62 @@ function _handleLinkedCheckChange(e) {
73
73
  * this outside of the ReactDOM controlled form components.
74
74
  */
75
75
  var LinkedValueUtils = {
76
- Mixin: {
77
- propTypes: {
78
- value: function(props, propName, componentName) {
79
- if (!props[propName] ||
80
- hasReadOnlyValue[props.type] ||
81
- props.onChange ||
82
- props.readOnly ||
83
- props.disabled) {
84
- return null;
85
- }
86
- return new Error(
87
- 'You provided a `value` prop to a form field without an ' +
88
- '`onChange` handler. This will render a read-only field. If ' +
89
- 'the field should be mutable use `defaultValue`. Otherwise, ' +
90
- 'set either `onChange` or `readOnly`.'
91
- );
92
- },
93
- checked: function(props, propName, componentName) {
94
- if (!props[propName] ||
95
- props.onChange ||
96
- props.readOnly ||
97
- props.disabled) {
98
- return null;
99
- }
100
- return new Error(
101
- 'You provided a `checked` prop to a form field without an ' +
102
- '`onChange` handler. This will render a read-only field. If ' +
103
- 'the field should be mutable use `defaultChecked`. Otherwise, ' +
104
- 'set either `onChange` or `readOnly`.'
105
- );
106
- },
107
- onChange: ReactPropTypes.func
76
+ checkPropTypes: function (tagName, props, owner) {
77
+ for (var propName in propTypes) {
78
+ if (propTypes.hasOwnProperty(propName)) {
79
+ var error = propTypes[propName](props, propName, tagName, ReactPropTypeLocations.prop);
80
+ }
81
+ if (error instanceof Error && !(error.message in loggedTypeFailures)) {
82
+ // Only monitor this failure once because there tends to be a lot of the
83
+ // same error.
84
+ loggedTypeFailures[error.message] = true;
85
+
86
+ var addendum = getDeclarationErrorAddendum(owner);
87
+ 'production' !== process.env.NODE_ENV ? warning(false, 'Failed form propType: %s%s', error.message, addendum) : undefined;
88
+ }
108
89
  }
109
90
  },
110
91
 
111
92
  /**
112
- * @param {ReactComponent} input Form component
93
+ * @param {object} inputProps Props for form component
113
94
  * @return {*} current value of the input either from value prop or link.
114
95
  */
115
- getValue: function(input) {
116
- if (input.props.valueLink) {
117
- _assertValueLink(input);
118
- return input.props.valueLink.value;
96
+ getValue: function (inputProps) {
97
+ if (inputProps.valueLink) {
98
+ _assertValueLink(inputProps);
99
+ return inputProps.valueLink.value;
119
100
  }
120
- return input.props.value;
101
+ return inputProps.value;
121
102
  },
122
103
 
123
104
  /**
124
- * @param {ReactComponent} input Form component
105
+ * @param {object} inputProps Props for form component
125
106
  * @return {*} current checked status of the input either from checked prop
126
107
  * or link.
127
108
  */
128
- getChecked: function(input) {
129
- if (input.props.checkedLink) {
130
- _assertCheckedLink(input);
131
- return input.props.checkedLink.value;
109
+ getChecked: function (inputProps) {
110
+ if (inputProps.checkedLink) {
111
+ _assertCheckedLink(inputProps);
112
+ return inputProps.checkedLink.value;
132
113
  }
133
- return input.props.checked;
114
+ return inputProps.checked;
134
115
  },
135
116
 
136
117
  /**
137
- * @param {ReactComponent} input Form component
138
- * @return {function} change callback either from onChange prop or link.
118
+ * @param {object} inputProps Props for form component
119
+ * @param {SyntheticEvent} event change event to handle
139
120
  */
140
- getOnChange: function(input) {
141
- if (input.props.valueLink) {
142
- _assertValueLink(input);
143
- return _handleLinkedValueChange;
144
- } else if (input.props.checkedLink) {
145
- _assertCheckedLink(input);
146
- return _handleLinkedCheckChange;
121
+ executeOnChange: function (inputProps, event) {
122
+ if (inputProps.valueLink) {
123
+ _assertValueLink(inputProps);
124
+ return inputProps.valueLink.requestChange(event.target.value);
125
+ } else if (inputProps.checkedLink) {
126
+ _assertCheckedLink(inputProps);
127
+ return inputProps.checkedLink.requestChange(event.target.checked);
128
+ } else if (inputProps.onChange) {
129
+ return inputProps.onChange.call(undefined, event);
147
130
  }
148
- return input.props.onChange;
149
131
  }
150
132
  };
151
133
 
152
- module.exports = LinkedValueUtils;
134
+ module.exports = LinkedValueUtils;