react 0.8.0 → 0.10.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 (160) hide show
  1. package/README.md +0 -8
  2. package/addons.js +0 -3
  3. package/lib/AutoFocusMixin.js +32 -0
  4. package/lib/CSSCore.js +23 -22
  5. package/lib/CSSProperty.js +32 -1
  6. package/lib/CSSPropertyOperations.js +1 -1
  7. package/lib/ChangeEventPlugin.js +27 -5
  8. package/lib/ClientReactRootIndex.js +30 -0
  9. package/lib/CompositionEventPlugin.js +58 -10
  10. package/lib/DOMChildrenOperations.js +39 -3
  11. package/lib/DOMProperty.js +9 -5
  12. package/lib/DOMPropertyOperations.js +21 -8
  13. package/lib/Danger.js +9 -8
  14. package/lib/DefaultDOMPropertyConfig.js +23 -14
  15. package/lib/DefaultEventPluginOrder.js +1 -1
  16. package/lib/EnterLeaveEventPlugin.js +38 -5
  17. package/lib/EventConstants.js +4 -1
  18. package/lib/EventListener.js +42 -34
  19. package/lib/EventPluginHub.js +118 -13
  20. package/lib/EventPluginRegistry.js +62 -18
  21. package/lib/EventPluginUtils.js +33 -4
  22. package/lib/EventPropagators.js +7 -43
  23. package/lib/ExecutionEnvironment.js +4 -1
  24. package/lib/LinkedStateMixin.js +1 -1
  25. package/lib/LinkedValueUtils.js +160 -0
  26. package/lib/MobileSafariClickEventPlugin.js +1 -1
  27. package/lib/PooledClass.js +7 -1
  28. package/lib/React.js +30 -4
  29. package/lib/ReactBrowserComponentMixin.js +42 -0
  30. package/lib/ReactCSSTransitionGroup.js +65 -0
  31. package/lib/{ReactTransitionableChild.js → ReactCSSTransitionGroupChild.js} +22 -36
  32. package/lib/ReactChildren.js +4 -4
  33. package/lib/ReactComponent.js +163 -83
  34. package/lib/ReactComponentBrowserEnvironment.js +55 -71
  35. package/lib/ReactCompositeComponent.js +686 -119
  36. package/lib/ReactContext.js +67 -0
  37. package/lib/ReactCurrentOwner.js +1 -1
  38. package/lib/ReactDOM.js +19 -6
  39. package/lib/ReactDOMButton.js +6 -1
  40. package/lib/ReactDOMComponent.js +66 -24
  41. package/lib/ReactDOMForm.js +13 -3
  42. package/lib/ReactDOMIDOperations.js +106 -61
  43. package/lib/ReactDOMImg.js +61 -0
  44. package/lib/ReactDOMInput.js +28 -15
  45. package/lib/ReactDOMOption.js +13 -8
  46. package/lib/ReactDOMSelect.js +38 -18
  47. package/lib/ReactDOMSelection.js +1 -1
  48. package/lib/ReactDOMTextarea.js +19 -11
  49. package/lib/ReactDefaultBatchingStrategy.js +1 -1
  50. package/lib/ReactDefaultInjection.js +60 -26
  51. package/lib/ReactDefaultPerf.js +208 -371
  52. package/lib/ReactDefaultPerfAnalysis.js +199 -0
  53. package/lib/ReactErrorUtils.js +6 -15
  54. package/lib/ReactEventEmitter.js +144 -146
  55. package/lib/ReactEventEmitterMixin.js +1 -33
  56. package/lib/ReactEventTopLevelCallback.js +75 -15
  57. package/lib/ReactInjection.js +43 -0
  58. package/lib/ReactInputSelection.js +3 -2
  59. package/lib/ReactInstanceHandles.js +36 -20
  60. package/lib/ReactLink.js +2 -2
  61. package/lib/ReactMarkupChecksum.js +1 -1
  62. package/lib/ReactMount.js +136 -104
  63. package/lib/ReactMountReady.js +2 -2
  64. package/lib/ReactMultiChild.js +40 -49
  65. package/lib/ReactMultiChildUpdateTypes.js +3 -1
  66. package/lib/ReactOwner.js +17 -4
  67. package/lib/ReactPerf.js +6 -9
  68. package/lib/ReactPropTransferer.js +41 -22
  69. package/lib/ReactPropTypeLocationNames.js +31 -0
  70. package/lib/{ReactComponentEnvironment.js → ReactPropTypeLocations.js} +11 -6
  71. package/lib/ReactPropTypes.js +249 -48
  72. package/lib/ReactPutListenerQueue.js +61 -0
  73. package/lib/ReactReconcileTransaction.js +28 -7
  74. package/lib/ReactRootIndex.js +36 -0
  75. package/lib/ReactServerRendering.js +46 -19
  76. package/lib/ReactServerRenderingTransaction.js +116 -0
  77. package/lib/ReactStateSetters.js +1 -1
  78. package/lib/ReactTestUtils.js +394 -0
  79. package/lib/ReactTextComponent.js +33 -6
  80. package/lib/{ReactTransitionKeySet.js → ReactTransitionChildMapping.js} +43 -48
  81. package/lib/ReactTransitionEvents.js +1 -1
  82. package/lib/ReactTransitionGroup.js +133 -58
  83. package/lib/ReactUpdates.js +15 -12
  84. package/lib/ReactWithAddons.js +15 -3
  85. package/lib/SelectEventPlugin.js +23 -40
  86. package/lib/ServerReactRootIndex.js +36 -0
  87. package/lib/SimpleEventPlugin.js +55 -7
  88. package/lib/SyntheticClipboardEvent.js +8 -2
  89. package/lib/SyntheticCompositionEvent.js +1 -1
  90. package/lib/SyntheticDragEvent.js +44 -0
  91. package/lib/SyntheticEvent.js +3 -2
  92. package/lib/SyntheticFocusEvent.js +1 -1
  93. package/lib/SyntheticKeyboardEvent.js +5 -3
  94. package/lib/SyntheticMouseEvent.js +1 -1
  95. package/lib/SyntheticTouchEvent.js +1 -1
  96. package/lib/SyntheticUIEvent.js +1 -1
  97. package/lib/SyntheticWheelEvent.js +11 -8
  98. package/lib/Transaction.js +62 -37
  99. package/lib/ViewportMetrics.js +1 -1
  100. package/lib/accumulate.js +1 -1
  101. package/lib/adler32.js +1 -1
  102. package/lib/cloneWithProps.js +59 -0
  103. package/lib/containsNode.js +1 -1
  104. package/lib/copyProperties.js +1 -1
  105. package/lib/createArrayFrom.js +11 -14
  106. package/lib/createFullPageComponent.js +63 -0
  107. package/lib/createNodesFromMarkup.js +1 -1
  108. package/lib/createObjectFrom.js +1 -1
  109. package/lib/cx.js +3 -3
  110. package/lib/dangerousStyleValue.js +1 -1
  111. package/lib/emptyFunction.js +1 -1
  112. package/lib/emptyObject.js +27 -0
  113. package/lib/escapeTextForBrowser.js +1 -1
  114. package/lib/flattenChildren.js +6 -3
  115. package/lib/focusNode.js +33 -0
  116. package/lib/forEachAccumulated.js +1 -1
  117. package/lib/getActiveElement.js +5 -4
  118. package/lib/getEventKey.js +85 -0
  119. package/lib/getEventTarget.js +1 -1
  120. package/lib/getMarkupWrap.js +11 -1
  121. package/lib/getNodeForCharacterOffset.js +1 -1
  122. package/lib/getReactRootElementInContainer.js +1 -1
  123. package/lib/getTextContentAccessor.js +6 -4
  124. package/lib/getUnboundedScrollPosition.js +3 -3
  125. package/lib/hyphenate.js +1 -1
  126. package/lib/instantiateReactComponent.js +70 -0
  127. package/lib/invariant.js +20 -12
  128. package/lib/isEventSupported.js +8 -12
  129. package/lib/isNode.js +2 -2
  130. package/lib/isTextInputElement.js +1 -1
  131. package/lib/isTextNode.js +1 -1
  132. package/lib/joinClasses.js +1 -1
  133. package/lib/keyMirror.js +1 -1
  134. package/lib/keyOf.js +1 -1
  135. package/lib/memoizeStringOnly.js +1 -1
  136. package/lib/merge.js +1 -1
  137. package/lib/mergeHelpers.js +6 -7
  138. package/lib/mergeInto.js +1 -1
  139. package/lib/mixInto.js +1 -1
  140. package/lib/monitorCodeUse.js +37 -0
  141. package/lib/objMap.js +1 -1
  142. package/lib/objMapKeyVal.js +1 -1
  143. package/lib/onlyChild.js +43 -0
  144. package/lib/performanceNow.js +1 -1
  145. package/lib/shallowEqual.js +1 -1
  146. package/lib/shouldUpdateReactComponent.js +61 -0
  147. package/lib/toArray.js +75 -0
  148. package/lib/traverseAllChildren.js +72 -9
  149. package/lib/update.js +159 -0
  150. package/lib/warning.js +48 -0
  151. package/package.json +3 -3
  152. package/react.js +0 -3
  153. package/ReactJSErrors.js +0 -40
  154. package/lib/$.js +0 -46
  155. package/lib/CallbackRegistry.js +0 -91
  156. package/lib/LinkedValueMixin.js +0 -68
  157. package/lib/ex.js +0 -49
  158. package/lib/filterAttributes.js +0 -45
  159. package/lib/ge.js +0 -76
  160. package/lib/mutateHTMLNodeWithMarkup.js +0 -100
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -34,6 +34,9 @@ var ExecutionEnvironment = {
34
34
 
35
35
  canUseWorkers: typeof Worker !== 'undefined',
36
36
 
37
+ canUseEventListeners:
38
+ canUseDOM && (window.addEventListener || window.attachEvent),
39
+
37
40
  isInWorker: !canUseDOM // For now, this is true - might change in the future.
38
41
 
39
42
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Copyright 2013-2014 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule LinkedValueUtils
17
+ * @typechecks static-only
18
+ */
19
+
20
+ "use strict";
21
+
22
+ var ReactPropTypes = require("./ReactPropTypes");
23
+
24
+ var invariant = require("./invariant");
25
+ var warning = require("./warning");
26
+
27
+ var hasReadOnlyValue = {
28
+ 'button': true,
29
+ 'checkbox': true,
30
+ 'image': true,
31
+ 'hidden': true,
32
+ 'radio': true,
33
+ 'reset': true,
34
+ 'submit': true
35
+ };
36
+
37
+ function _assertSingleLink(input) {
38
+ ("production" !== process.env.NODE_ENV ? invariant(
39
+ input.props.checkedLink == null || input.props.valueLink == null,
40
+ 'Cannot provide a checkedLink and a valueLink. If you want to use ' +
41
+ 'checkedLink, you probably don\'t want to use valueLink and vice versa.'
42
+ ) : invariant(input.props.checkedLink == null || input.props.valueLink == null));
43
+ }
44
+ function _assertValueLink(input) {
45
+ _assertSingleLink(input);
46
+ ("production" !== process.env.NODE_ENV ? invariant(
47
+ input.props.value == null && input.props.onChange == null,
48
+ 'Cannot provide a valueLink and a value or onChange event. If you want ' +
49
+ 'to use value or onChange, you probably don\'t want to use valueLink.'
50
+ ) : invariant(input.props.value == null && input.props.onChange == null));
51
+ }
52
+
53
+ function _assertCheckedLink(input) {
54
+ _assertSingleLink(input);
55
+ ("production" !== process.env.NODE_ENV ? invariant(
56
+ input.props.checked == null && input.props.onChange == null,
57
+ 'Cannot provide a checkedLink and a checked property or onChange event. ' +
58
+ 'If you want to use checked or onChange, you probably don\'t want to ' +
59
+ 'use checkedLink'
60
+ ) : invariant(input.props.checked == null && input.props.onChange == null));
61
+ }
62
+
63
+ /**
64
+ * @param {SyntheticEvent} e change event to handle
65
+ */
66
+ function _handleLinkedValueChange(e) {
67
+ /*jshint validthis:true */
68
+ this.props.valueLink.requestChange(e.target.value);
69
+ }
70
+
71
+ /**
72
+ * @param {SyntheticEvent} e change event to handle
73
+ */
74
+ function _handleLinkedCheckChange(e) {
75
+ /*jshint validthis:true */
76
+ this.props.checkedLink.requestChange(e.target.checked);
77
+ }
78
+
79
+ /**
80
+ * Provide a linked `value` attribute for controlled forms. You should not use
81
+ * this outside of the ReactDOM controlled form components.
82
+ */
83
+ var LinkedValueUtils = {
84
+ Mixin: {
85
+ propTypes: {
86
+ value: function(props, propName, componentName) {
87
+ if ("production" !== process.env.NODE_ENV) {
88
+ ("production" !== process.env.NODE_ENV ? warning(
89
+ !props[propName] ||
90
+ hasReadOnlyValue[props.type] ||
91
+ props.onChange ||
92
+ props.readOnly ||
93
+ props.disabled,
94
+ 'You provided a `value` prop to a form field without an ' +
95
+ '`onChange` handler. This will render a read-only field. If ' +
96
+ 'the field should be mutable use `defaultValue`. Otherwise, ' +
97
+ 'set either `onChange` or `readOnly`.'
98
+ ) : null);
99
+ }
100
+ },
101
+ checked: function(props, propName, componentName) {
102
+ if ("production" !== process.env.NODE_ENV) {
103
+ ("production" !== process.env.NODE_ENV ? warning(
104
+ !props[propName] ||
105
+ props.onChange ||
106
+ props.readOnly ||
107
+ props.disabled,
108
+ 'You provided a `checked` prop to a form field without an ' +
109
+ '`onChange` handler. This will render a read-only field. If ' +
110
+ 'the field should be mutable use `defaultChecked`. Otherwise, ' +
111
+ 'set either `onChange` or `readOnly`.'
112
+ ) : null);
113
+ }
114
+ },
115
+ onChange: ReactPropTypes.func
116
+ }
117
+ },
118
+
119
+ /**
120
+ * @param {ReactComponent} input Form component
121
+ * @return {*} current value of the input either from value prop or link.
122
+ */
123
+ getValue: function(input) {
124
+ if (input.props.valueLink) {
125
+ _assertValueLink(input);
126
+ return input.props.valueLink.value;
127
+ }
128
+ return input.props.value;
129
+ },
130
+
131
+ /**
132
+ * @param {ReactComponent} input Form component
133
+ * @return {*} current checked status of the input either from checked prop
134
+ * or link.
135
+ */
136
+ getChecked: function(input) {
137
+ if (input.props.checkedLink) {
138
+ _assertCheckedLink(input);
139
+ return input.props.checkedLink.value;
140
+ }
141
+ return input.props.checked;
142
+ },
143
+
144
+ /**
145
+ * @param {ReactComponent} input Form component
146
+ * @return {function} change callback either from onChange prop or link.
147
+ */
148
+ getOnChange: function(input) {
149
+ if (input.props.valueLink) {
150
+ _assertValueLink(input);
151
+ return _handleLinkedValueChange;
152
+ } else if (input.props.checkedLink) {
153
+ _assertCheckedLink(input);
154
+ return _handleLinkedCheckChange;
155
+ }
156
+ return input.props.onChange;
157
+ }
158
+ };
159
+
160
+ module.exports = LinkedValueUtils;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -18,6 +18,8 @@
18
18
 
19
19
  "use strict";
20
20
 
21
+ var invariant = require("./invariant");
22
+
21
23
  /**
22
24
  * Static poolers. Several custom versions for each potential number of
23
25
  * arguments. A completely generic pooler is easy to implement, but would
@@ -71,6 +73,10 @@ var fiveArgumentPooler = function(a1, a2, a3, a4, a5) {
71
73
 
72
74
  var standardReleaser = function(instance) {
73
75
  var Klass = this;
76
+ ("production" !== process.env.NODE_ENV ? invariant(
77
+ instance instanceof Klass,
78
+ 'Trying to release an instance into a pool of a different type.'
79
+ ) : invariant(instance instanceof Klass));
74
80
  if (instance.destructor) {
75
81
  instance.destructor();
76
82
  }
package/lib/React.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -18,8 +18,12 @@
18
18
 
19
19
  "use strict";
20
20
 
21
+ var DOMPropertyOperations = require("./DOMPropertyOperations");
22
+ var EventPluginUtils = require("./EventPluginUtils");
23
+ var ReactChildren = require("./ReactChildren");
21
24
  var ReactComponent = require("./ReactComponent");
22
25
  var ReactCompositeComponent = require("./ReactCompositeComponent");
26
+ var ReactContext = require("./ReactContext");
23
27
  var ReactCurrentOwner = require("./ReactCurrentOwner");
24
28
  var ReactDOM = require("./ReactDOM");
25
29
  var ReactDOMComponent = require("./ReactDOMComponent");
@@ -32,13 +36,20 @@ var ReactPropTypes = require("./ReactPropTypes");
32
36
  var ReactServerRendering = require("./ReactServerRendering");
33
37
  var ReactTextComponent = require("./ReactTextComponent");
34
38
 
39
+ var onlyChild = require("./onlyChild");
40
+
35
41
  ReactDefaultInjection.inject();
36
42
 
37
43
  var React = {
44
+ Children: {
45
+ map: ReactChildren.map,
46
+ forEach: ReactChildren.forEach,
47
+ only: onlyChild
48
+ },
38
49
  DOM: ReactDOM,
39
50
  PropTypes: ReactPropTypes,
40
51
  initializeTouchEvents: function(shouldUseTouch) {
41
- ReactMount.useTouchEvents = shouldUseTouch;
52
+ EventPluginUtils.useTouchEvents = shouldUseTouch;
42
53
  },
43
54
  createClass: ReactCompositeComponent.createClass,
44
55
  constructAndRenderComponent: ReactMount.constructAndRenderComponent,
@@ -49,14 +60,17 @@ var React = {
49
60
  ReactMount.renderComponent
50
61
  ),
51
62
  renderComponentToString: ReactServerRendering.renderComponentToString,
63
+ renderComponentToStaticMarkup:
64
+ ReactServerRendering.renderComponentToStaticMarkup,
52
65
  unmountComponentAtNode: ReactMount.unmountComponentAtNode,
53
- unmountAndReleaseReactRootNode: ReactMount.unmountAndReleaseReactRootNode,
54
66
  isValidClass: ReactCompositeComponent.isValidClass,
55
67
  isValidComponent: ReactComponent.isValidComponent,
68
+ withContext: ReactContext.withContext,
56
69
  __internals: {
57
70
  Component: ReactComponent,
58
71
  CurrentOwner: ReactCurrentOwner,
59
72
  DOMComponent: ReactDOMComponent,
73
+ DOMPropertyOperations: DOMPropertyOperations,
60
74
  InstanceHandles: ReactInstanceHandles,
61
75
  Mount: ReactMount,
62
76
  MultiChild: ReactMultiChild,
@@ -64,8 +78,20 @@ var React = {
64
78
  }
65
79
  };
66
80
 
81
+ if ("production" !== process.env.NODE_ENV) {
82
+ var ExecutionEnvironment = require("./ExecutionEnvironment");
83
+ if (ExecutionEnvironment.canUseDOM &&
84
+ window.top === window.self &&
85
+ navigator.userAgent.indexOf('Chrome') > -1) {
86
+ console.debug(
87
+ 'Download the React DevTools for a better development experience: ' +
88
+ 'http://fb.me/react-devtools'
89
+ );
90
+ }
91
+ }
92
+
67
93
  // Version exists only in the open-source version of React, not in Facebook's
68
94
  // internal version.
69
- React.version = '0.8.0';
95
+ React.version = '0.10.0';
70
96
 
71
97
  module.exports = React;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Copyright 2013-2014 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule ReactBrowserComponentMixin
17
+ */
18
+
19
+ "use strict";
20
+
21
+ var ReactMount = require("./ReactMount");
22
+
23
+ var invariant = require("./invariant");
24
+
25
+ var ReactBrowserComponentMixin = {
26
+ /**
27
+ * Returns the DOM node rendered by this component.
28
+ *
29
+ * @return {DOMElement} The root node of this component.
30
+ * @final
31
+ * @protected
32
+ */
33
+ getDOMNode: function() {
34
+ ("production" !== process.env.NODE_ENV ? invariant(
35
+ this.isMounted(),
36
+ 'getDOMNode(): A component must be mounted to have a DOM node.'
37
+ ) : invariant(this.isMounted()));
38
+ return ReactMount.getNode(this._rootNodeID);
39
+ }
40
+ };
41
+
42
+ module.exports = ReactBrowserComponentMixin;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Copyright 2013-2014 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @typechecks
17
+ * @providesModule ReactCSSTransitionGroup
18
+ */
19
+
20
+ "use strict";
21
+
22
+ var React = require("./React");
23
+
24
+ var ReactTransitionGroup = require("./ReactTransitionGroup");
25
+ var ReactCSSTransitionGroupChild = require("./ReactCSSTransitionGroupChild");
26
+
27
+ var ReactCSSTransitionGroup = React.createClass({
28
+ propTypes: {
29
+ transitionName: React.PropTypes.string.isRequired,
30
+ transitionEnter: React.PropTypes.bool,
31
+ transitionLeave: React.PropTypes.bool
32
+ },
33
+
34
+ getDefaultProps: function() {
35
+ return {
36
+ transitionEnter: true,
37
+ transitionLeave: true
38
+ };
39
+ },
40
+
41
+ _wrapChild: function(child) {
42
+ // We need to provide this childFactory so that
43
+ // ReactCSSTransitionGroupChild can receive updates to name, enter, and
44
+ // leave while it is leaving.
45
+ return ReactCSSTransitionGroupChild(
46
+ {
47
+ name: this.props.transitionName,
48
+ enter: this.props.transitionEnter,
49
+ leave: this.props.transitionLeave
50
+ },
51
+ child
52
+ );
53
+ },
54
+
55
+ render: function() {
56
+ return this.transferPropsTo(
57
+ ReactTransitionGroup(
58
+ {childFactory: this._wrapChild},
59
+ this.props.children
60
+ )
61
+ );
62
+ }
63
+ });
64
+
65
+ module.exports = ReactCSSTransitionGroup;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -13,15 +13,19 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  *
16
- * @providesModule ReactTransitionableChild
16
+ * @typechecks
17
+ * @providesModule ReactCSSTransitionGroupChild
17
18
  */
18
19
 
19
20
  "use strict";
20
21
 
21
22
  var React = require("./React");
23
+
22
24
  var CSSCore = require("./CSSCore");
23
25
  var ReactTransitionEvents = require("./ReactTransitionEvents");
24
26
 
27
+ var onlyChild = require("./onlyChild");
28
+
25
29
  // We don't remove the element from the DOM until we receive an animationend or
26
30
  // transitionend event. If the user screws up and forgets to add an animation
27
31
  // their node will be stuck in the DOM forever, so we detect if an animation
@@ -31,6 +35,7 @@ var NO_EVENT_TIMEOUT = 5000;
31
35
 
32
36
  var noEventListener = null;
33
37
 
38
+
34
39
  if ("production" !== process.env.NODE_ENV) {
35
40
  noEventListener = function() {
36
41
  console.warn(
@@ -42,20 +47,8 @@ if ("production" !== process.env.NODE_ENV) {
42
47
  };
43
48
  }
44
49
 
45
- /**
46
- * This component is simply responsible for watching when its single child
47
- * changes to undefined and animating the old child out. It does this by
48
- * recording its old child in savedChildren when it detects this event is about
49
- * to occur.
50
- */
51
- var ReactTransitionableChild = React.createClass({
52
- /**
53
- * Perform an actual DOM transition. This takes care of a few things:
54
- * - Adding the second CSS class to trigger the transition
55
- * - Listening for the finish event
56
- * - Cleaning up the css (unless noReset is true)
57
- */
58
- transition: function(animationType, noReset, finishCallback) {
50
+ var ReactCSSTransitionGroupChild = React.createClass({
51
+ transition: function(animationType, finishCallback) {
59
52
  var node = this.getDOMNode();
60
53
  var className = this.props.name + '-' + animationType;
61
54
  var activeClassName = className + '-active';
@@ -66,13 +59,8 @@ var ReactTransitionableChild = React.createClass({
66
59
  clearTimeout(noEventTimeout);
67
60
  }
68
61
 
69
- // If this gets invoked after the component is unmounted it's OK.
70
- if (!noReset) {
71
- // Usually this means you're about to remove the node if you want to
72
- // leave it in its animated state.
73
- CSSCore.removeClass(node, className);
74
- CSSCore.removeClass(node, activeClassName);
75
- }
62
+ CSSCore.removeClass(node, className);
63
+ CSSCore.removeClass(node, activeClassName);
76
64
 
77
65
  ReactTransitionEvents.removeEndEventListener(node, endListener);
78
66
 
@@ -126,27 +114,25 @@ var ReactTransitionableChild = React.createClass({
126
114
  }
127
115
  },
128
116
 
129
- componentWillReceiveProps: function(nextProps) {
130
- if (!nextProps.children && this.props.children) {
131
- this.savedChildren = this.props.children;
132
- }
133
- },
134
-
135
- componentDidMount: function(node) {
117
+ componentWillEnter: function(done) {
136
118
  if (this.props.enter) {
137
- this.transition('enter');
119
+ this.transition('enter', done);
120
+ } else {
121
+ done();
138
122
  }
139
123
  },
140
124
 
141
- componentDidUpdate: function(prevProps, prevState, node) {
142
- if (prevProps.children && !this.props.children) {
143
- this.transition('leave', true, this.props.onDoneLeaving);
125
+ componentWillLeave: function(done) {
126
+ if (this.props.leave) {
127
+ this.transition('leave', done);
128
+ } else {
129
+ done();
144
130
  }
145
131
  },
146
132
 
147
133
  render: function() {
148
- return this.props.children || this.savedChildren;
134
+ return onlyChild(this.props.children);
149
135
  }
150
136
  });
151
137
 
152
- module.exports = ReactTransitionableChild;
138
+ module.exports = ReactCSSTransitionGroupChild;