react 0.14.0-alpha3 → 0.14.0-rc1

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 (200) hide show
  1. package/README.md +5 -2
  2. package/addons.js +8 -3
  3. package/dist/react-dom.js +42 -0
  4. package/dist/react-dom.min.js +12 -0
  5. package/dist/react-with-addons.js +6076 -5337
  6. package/dist/react-with-addons.min.js +6 -6
  7. package/dist/react.js +5445 -4839
  8. package/dist/react.min.js +6 -5
  9. package/lib/{AutoFocusMixin.js → AutoFocusUtils.js} +15 -5
  10. package/lib/BeforeInputEventPlugin.js +13 -13
  11. package/lib/CSSProperty.js +18 -3
  12. package/lib/CSSPropertyOperations.js +22 -14
  13. package/lib/CallbackQueue.js +4 -4
  14. package/lib/ChangeEventPlugin.js +18 -15
  15. package/lib/DOMChildrenOperations.js +17 -7
  16. package/lib/DOMProperty.js +82 -117
  17. package/lib/DOMPropertyOperations.js +84 -33
  18. package/lib/Danger.js +21 -16
  19. package/lib/DefaultEventPluginOrder.js +2 -2
  20. package/lib/EnterLeaveEventPlugin.js +21 -13
  21. package/lib/EventConstants.js +23 -1
  22. package/lib/EventPluginHub.js +17 -20
  23. package/lib/EventPluginRegistry.js +8 -8
  24. package/lib/EventPluginUtils.js +33 -42
  25. package/lib/EventPropagators.js +8 -8
  26. package/lib/FallbackCompositionState.js +9 -3
  27. package/lib/HTMLDOMPropertyConfig.js +19 -3
  28. package/lib/LinkedStateMixin.js +2 -2
  29. package/lib/LinkedValueUtils.js +50 -38
  30. package/lib/MetaMatchers.js +118 -0
  31. package/lib/OrderedMap.js +453 -0
  32. package/lib/PooledClass.js +15 -5
  33. package/lib/React.js +18 -7
  34. package/lib/ReactBrowserComponentMixin.js +4 -4
  35. package/lib/ReactBrowserEventEmitter.js +30 -7
  36. package/lib/ReactCSSTransitionGroup.js +35 -9
  37. package/lib/ReactCSSTransitionGroupChild.js +56 -30
  38. package/lib/ReactChildReconciler.js +24 -19
  39. package/lib/ReactChildren.js +75 -35
  40. package/lib/ReactClass.js +70 -87
  41. package/lib/ReactComponent.js +27 -20
  42. package/lib/ReactComponentBrowserEnvironment.js +2 -2
  43. package/lib/ReactComponentEnvironment.js +2 -2
  44. package/lib/ReactComponentWithPureRenderMixin.js +3 -3
  45. package/lib/ReactCompositeComponent.js +117 -106
  46. package/lib/ReactDOM.js +74 -158
  47. package/lib/ReactDOMButton.js +15 -26
  48. package/lib/ReactDOMComponent.js +441 -72
  49. package/lib/ReactDOMFactories.js +177 -0
  50. package/lib/{emptyObject.js → ReactDOMFeatureFlags.js} +6 -8
  51. package/lib/ReactDOMIDOperations.js +8 -66
  52. package/lib/ReactDOMInput.js +87 -99
  53. package/lib/ReactDOMOption.js +25 -44
  54. package/lib/ReactDOMSelect.js +88 -98
  55. package/lib/ReactDOMSelection.js +3 -3
  56. package/lib/ReactDOMServer.js +5 -3
  57. package/lib/ReactDOMTextComponent.js +33 -20
  58. package/lib/ReactDOMTextarea.js +48 -61
  59. package/lib/ReactDefaultBatchingStrategy.js +4 -4
  60. package/lib/ReactDefaultInjection.js +23 -72
  61. package/lib/ReactDefaultPerf.js +7 -7
  62. package/lib/ReactDefaultPerfAnalysis.js +6 -11
  63. package/lib/ReactElement.js +92 -107
  64. package/lib/ReactElementValidator.js +53 -173
  65. package/lib/ReactEmptyComponent.js +26 -62
  66. package/lib/ReactEmptyComponentRegistry.js +48 -0
  67. package/lib/ReactErrorUtils.js +45 -9
  68. package/lib/ReactEventEmitterMixin.js +3 -4
  69. package/lib/ReactEventListener.js +64 -12
  70. package/lib/ReactFragment.js +29 -115
  71. package/lib/ReactInjection.js +10 -12
  72. package/lib/ReactInputSelection.js +8 -7
  73. package/lib/ReactInstanceHandles.js +12 -12
  74. package/lib/ReactIsomorphic.js +15 -11
  75. package/lib/ReactLink.js +1 -1
  76. package/lib/ReactMarkupChecksum.js +6 -2
  77. package/lib/ReactMount.js +196 -122
  78. package/lib/ReactMultiChild.js +119 -25
  79. package/lib/ReactMultiChildUpdateTypes.js +2 -1
  80. package/lib/ReactNativeComponent.js +3 -8
  81. package/lib/ReactNoopUpdateQueue.js +118 -0
  82. package/lib/ReactOwner.js +3 -3
  83. package/lib/ReactPerf.js +2 -2
  84. package/lib/ReactPropTransferer.js +3 -3
  85. package/lib/ReactPropTypeLocationNames.js +1 -1
  86. package/lib/ReactPropTypeLocations.js +1 -1
  87. package/lib/ReactPropTypes.js +41 -12
  88. package/lib/ReactReconcileTransaction.js +12 -10
  89. package/lib/ReactReconciler.js +8 -11
  90. package/lib/ReactRef.js +15 -2
  91. package/lib/ReactServerBatchingStrategy.js +23 -0
  92. package/lib/ReactServerRendering.js +22 -9
  93. package/lib/ReactServerRenderingTransaction.js +8 -7
  94. package/lib/ReactTestUtils.js +89 -64
  95. package/lib/ReactTransitionChildMapping.js +3 -6
  96. package/lib/ReactTransitionEvents.js +1 -1
  97. package/lib/ReactTransitionGroup.js +5 -6
  98. package/lib/ReactUpdateQueue.js +60 -35
  99. package/lib/ReactUpdates.js +15 -18
  100. package/lib/{isTextNode.js → ReactVersion.js} +2 -13
  101. package/lib/ReactWithAddons.js +24 -17
  102. package/lib/ResponderEventPlugin.js +514 -0
  103. package/lib/ResponderSyntheticEvent.js +40 -0
  104. package/lib/ResponderTouchHistoryStore.js +180 -0
  105. package/lib/SVGDOMPropertyConfig.js +1 -1
  106. package/lib/SelectEventPlugin.js +25 -16
  107. package/lib/SimpleEventPlugin.js +200 -45
  108. package/lib/SyntheticClipboardEvent.js +3 -3
  109. package/lib/SyntheticCompositionEvent.js +3 -3
  110. package/lib/SyntheticDragEvent.js +3 -3
  111. package/lib/SyntheticEvent.js +24 -8
  112. package/lib/SyntheticFocusEvent.js +3 -3
  113. package/lib/SyntheticInputEvent.js +3 -3
  114. package/lib/SyntheticKeyboardEvent.js +6 -6
  115. package/lib/SyntheticMouseEvent.js +5 -5
  116. package/lib/SyntheticTouchEvent.js +4 -4
  117. package/lib/SyntheticUIEvent.js +4 -4
  118. package/lib/SyntheticWheelEvent.js +3 -3
  119. package/lib/TapEventPlugin.js +119 -0
  120. package/lib/Transaction.js +17 -11
  121. package/lib/accumulate.js +44 -0
  122. package/lib/accumulateInto.js +2 -2
  123. package/lib/adler32.js +19 -7
  124. package/lib/cloneWithProps.js +12 -7
  125. package/lib/createHierarchyRenderer.js +85 -0
  126. package/lib/dangerousStyleValue.js +1 -1
  127. package/lib/deprecated.js +48 -0
  128. package/lib/findDOMNode.js +11 -12
  129. package/lib/flattenChildren.js +4 -4
  130. package/lib/forEachAccumulated.js +1 -1
  131. package/lib/getEventCharCode.js +1 -1
  132. package/lib/getEventKey.js +1 -1
  133. package/lib/getEventModifierState.js +0 -1
  134. package/lib/getTestDocument.js +28 -0
  135. package/lib/getTextContentAccessor.js +1 -1
  136. package/lib/instantiateReactComponent.js +27 -25
  137. package/lib/isEventSupported.js +1 -1
  138. package/lib/isTextInputElement.js +2 -1
  139. package/lib/joinClasses.js +1 -1
  140. package/lib/onlyChild.js +3 -3
  141. package/lib/quoteAttributeValueForBrowser.js +1 -1
  142. package/lib/reactComponentExpect.js +216 -0
  143. package/lib/renderSubtreeIntoContainer.js +1 -1
  144. package/lib/setInnerHTML.js +2 -2
  145. package/lib/setTextContent.js +3 -3
  146. package/lib/shallowCompare.js +1 -1
  147. package/lib/shouldUpdateReactComponent.js +12 -8
  148. package/lib/sliceChildren.js +34 -0
  149. package/lib/traverseAllChildren.js +21 -19
  150. package/lib/update.js +13 -13
  151. package/lib/validateDOMNesting.js +6 -6
  152. package/lib/webcomponents.js +6379 -0
  153. package/package.json +4 -6
  154. package/react.js +2 -0
  155. package/addons/CSSTransitionGroup.js +0 -1
  156. package/addons/LinkedStateMixin.js +0 -1
  157. package/addons/Perf.js +0 -1
  158. package/addons/PureRenderMixin.js +0 -1
  159. package/addons/TestUtils.js +0 -1
  160. package/addons/TransitionGroup.js +0 -1
  161. package/addons/batchedUpdates.js +0 -1
  162. package/addons/cloneWithProps.js +0 -1
  163. package/addons/createFragment.js +0 -1
  164. package/addons/renderSubtreeIntoContainer.js +0 -1
  165. package/addons/shallowCompare.js +0 -1
  166. package/addons/update.js +0 -1
  167. package/dist/JSXTransformer.js +0 -17589
  168. package/lib/CSSCore.js +0 -97
  169. package/lib/EventListener.js +0 -84
  170. package/lib/ExecutionEnvironment.js +0 -38
  171. package/lib/LocalEventTrapMixin.js +0 -46
  172. package/lib/ReactContext.js +0 -32
  173. package/lib/ReactDOMClient.js +0 -85
  174. package/lib/ReactDOMForm.js +0 -47
  175. package/lib/ReactDOMIframe.js +0 -43
  176. package/lib/ReactDOMImg.js +0 -44
  177. package/lib/ReactLifeCycle.js +0 -35
  178. package/lib/camelize.js +0 -32
  179. package/lib/camelizeStyleName.js +0 -40
  180. package/lib/containsNode.js +0 -55
  181. package/lib/createArrayFromMixed.js +0 -85
  182. package/lib/createFullPageComponent.js +0 -51
  183. package/lib/createNodesFromMarkup.js +0 -84
  184. package/lib/emptyFunction.js +0 -38
  185. package/lib/focusNode.js +0 -26
  186. package/lib/getActiveElement.js +0 -29
  187. package/lib/getMarkupWrap.js +0 -115
  188. package/lib/getUnboundedScrollPosition.js +0 -38
  189. package/lib/hyphenate.js +0 -33
  190. package/lib/hyphenateStyleName.js +0 -39
  191. package/lib/invariant.js +0 -49
  192. package/lib/isNode.js +0 -23
  193. package/lib/keyMirror.js +0 -48
  194. package/lib/keyOf.js +0 -35
  195. package/lib/mapObject.js +0 -51
  196. package/lib/performance.js +0 -23
  197. package/lib/performanceNow.js +0 -28
  198. package/lib/shallowEqual.js +0 -48
  199. package/lib/toArray.js +0 -57
  200. package/lib/warning.js +0 -61
package/lib/focusNode.js DELETED
@@ -1,26 +0,0 @@
1
- /**
2
- * Copyright 2014-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 focusNode
10
- */
11
-
12
- "use strict";
13
-
14
- /**
15
- * @param {DOMElement} node input/textarea to focus
16
- */
17
- function focusNode(node) {
18
- // IE8 can throw "Can't move focus to the control because it is invisible,
19
- // not enabled, or of a type that does not accept the focus." for all kinds of
20
- // reasons that are too expensive and fragile to test.
21
- try {
22
- node.focus();
23
- } catch (e) {}
24
- }
25
-
26
- module.exports = focusNode;
@@ -1,29 +0,0 @@
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 getActiveElement
10
- * @typechecks
11
- */
12
-
13
- /**
14
- * Same as document.activeElement but wraps in a try-catch block. In IE it is
15
- * not safe to call document.activeElement if there is nothing focused.
16
- *
17
- * The activeElement will be null only if the document body is not yet defined.
18
- */
19
- "use strict";
20
-
21
- function getActiveElement() /*?DOMElement*/{
22
- try {
23
- return document.activeElement || document.body;
24
- } catch (e) {
25
- return document.body;
26
- }
27
- }
28
-
29
- module.exports = getActiveElement;
@@ -1,115 +0,0 @@
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 getMarkupWrap
10
- */
11
-
12
- 'use strict';
13
-
14
- var ExecutionEnvironment = require("./ExecutionEnvironment");
15
-
16
- var invariant = require("./invariant");
17
-
18
- /**
19
- * Dummy container used to detect which wraps are necessary.
20
- */
21
- var dummyNode = ExecutionEnvironment.canUseDOM ? document.createElement('div') : null;
22
-
23
- /**
24
- * Some browsers cannot use `innerHTML` to render certain elements standalone,
25
- * so we wrap them, render the wrapped nodes, then extract the desired node.
26
- *
27
- * In IE8, certain elements cannot render alone, so wrap all elements ('*').
28
- */
29
- var shouldWrap = {
30
- // Force wrapping for SVG elements because if they get created inside a <div>,
31
- // they will be initialized in the wrong namespace (and will not display).
32
- 'circle': true,
33
- 'clipPath': true,
34
- 'defs': true,
35
- 'ellipse': true,
36
- 'g': true,
37
- 'line': true,
38
- 'linearGradient': true,
39
- 'path': true,
40
- 'polygon': true,
41
- 'polyline': true,
42
- 'radialGradient': true,
43
- 'rect': true,
44
- 'stop': true,
45
- 'text': true
46
- };
47
-
48
- var selectWrap = [1, '<select multiple="true">', '</select>'];
49
- var tableWrap = [1, '<table>', '</table>'];
50
- var trWrap = [3, '<table><tbody><tr>', '</tr></tbody></table>'];
51
-
52
- var svgWrap = [1, '<svg>', '</svg>'];
53
-
54
- var markupWrap = {
55
- '*': [1, '?<div>', '</div>'],
56
-
57
- 'area': [1, '<map>', '</map>'],
58
- 'col': [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
59
- 'legend': [1, '<fieldset>', '</fieldset>'],
60
- 'param': [1, '<object>', '</object>'],
61
- 'tr': [2, '<table><tbody>', '</tbody></table>'],
62
-
63
- 'optgroup': selectWrap,
64
- 'option': selectWrap,
65
-
66
- 'caption': tableWrap,
67
- 'colgroup': tableWrap,
68
- 'tbody': tableWrap,
69
- 'tfoot': tableWrap,
70
- 'thead': tableWrap,
71
-
72
- 'td': trWrap,
73
- 'th': trWrap,
74
-
75
- 'circle': svgWrap,
76
- 'clipPath': svgWrap,
77
- 'defs': svgWrap,
78
- 'ellipse': svgWrap,
79
- 'g': svgWrap,
80
- 'line': svgWrap,
81
- 'linearGradient': svgWrap,
82
- 'path': svgWrap,
83
- 'polygon': svgWrap,
84
- 'polyline': svgWrap,
85
- 'radialGradient': svgWrap,
86
- 'rect': svgWrap,
87
- 'stop': svgWrap,
88
- 'text': svgWrap
89
- };
90
-
91
- /**
92
- * Gets the markup wrap configuration for the supplied `nodeName`.
93
- *
94
- * NOTE: This lazily detects which wraps are necessary for the current browser.
95
- *
96
- * @param {string} nodeName Lowercase `nodeName`.
97
- * @return {?array} Markup wrap configuration, if applicable.
98
- */
99
- function getMarkupWrap(nodeName) {
100
- !!!dummyNode ? 'production' !== process.env.NODE_ENV ? invariant(false, 'Markup wrapping node not initialized') : invariant(false) : undefined;
101
- if (!markupWrap.hasOwnProperty(nodeName)) {
102
- nodeName = '*';
103
- }
104
- if (!shouldWrap.hasOwnProperty(nodeName)) {
105
- if (nodeName === '*') {
106
- dummyNode.innerHTML = '<link />';
107
- } else {
108
- dummyNode.innerHTML = '<' + nodeName + '></' + nodeName + '>';
109
- }
110
- shouldWrap[nodeName] = !dummyNode.firstChild;
111
- }
112
- return shouldWrap[nodeName] ? markupWrap[nodeName] : null;
113
- }
114
-
115
- module.exports = getMarkupWrap;
@@ -1,38 +0,0 @@
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 getUnboundedScrollPosition
10
- * @typechecks
11
- */
12
-
13
- "use strict";
14
-
15
- /**
16
- * Gets the scroll position of the supplied element or window.
17
- *
18
- * The return values are unbounded, unlike `getScrollPosition`. This means they
19
- * may be negative or exceed the element boundaries (which is possible using
20
- * inertial scrolling).
21
- *
22
- * @param {DOMWindow|DOMElement} scrollable
23
- * @return {object} Map with `x` and `y` keys.
24
- */
25
- function getUnboundedScrollPosition(scrollable) {
26
- if (scrollable === window) {
27
- return {
28
- x: window.pageXOffset || document.documentElement.scrollLeft,
29
- y: window.pageYOffset || document.documentElement.scrollTop
30
- };
31
- }
32
- return {
33
- x: scrollable.scrollLeft,
34
- y: scrollable.scrollTop
35
- };
36
- }
37
-
38
- module.exports = getUnboundedScrollPosition;
package/lib/hyphenate.js DELETED
@@ -1,33 +0,0 @@
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 hyphenate
10
- * @typechecks
11
- */
12
-
13
- 'use strict';
14
-
15
- var _uppercasePattern = /([A-Z])/g;
16
-
17
- /**
18
- * Hyphenates a camelcased string, for example:
19
- *
20
- * > hyphenate('backgroundColor')
21
- * < "background-color"
22
- *
23
- * For CSS style names, use `hyphenateStyleName` instead which works properly
24
- * with all vendor prefixes, including `ms`.
25
- *
26
- * @param {string} string
27
- * @return {string}
28
- */
29
- function hyphenate(string) {
30
- return string.replace(_uppercasePattern, '-$1').toLowerCase();
31
- }
32
-
33
- module.exports = hyphenate;
@@ -1,39 +0,0 @@
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 hyphenateStyleName
10
- * @typechecks
11
- */
12
-
13
- 'use strict';
14
-
15
- var hyphenate = require("./hyphenate");
16
-
17
- var msPattern = /^ms-/;
18
-
19
- /**
20
- * Hyphenates a camelcased CSS property name, for example:
21
- *
22
- * > hyphenateStyleName('backgroundColor')
23
- * < "background-color"
24
- * > hyphenateStyleName('MozTransition')
25
- * < "-moz-transition"
26
- * > hyphenateStyleName('msTransition')
27
- * < "-ms-transition"
28
- *
29
- * As Modernizr suggests (http://modernizr.com/docs/#prefixed), an `ms` prefix
30
- * is converted to `-ms-`.
31
- *
32
- * @param {string} string
33
- * @return {string}
34
- */
35
- function hyphenateStyleName(string) {
36
- return hyphenate(string).replace(msPattern, '-ms-');
37
- }
38
-
39
- module.exports = hyphenateStyleName;
package/lib/invariant.js DELETED
@@ -1,49 +0,0 @@
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 invariant
10
- */
11
-
12
- 'use strict';
13
-
14
- /**
15
- * Use invariant() to assert state which your program assumes to be true.
16
- *
17
- * Provide sprintf-style format (only %s is supported) and arguments
18
- * to provide information about what broke and what you were
19
- * expecting.
20
- *
21
- * The invariant message will be stripped in production, but the invariant
22
- * will remain to ensure logic does not differ in production.
23
- */
24
-
25
- var invariant = function (condition, format, a, b, c, d, e, f) {
26
- if ('production' !== process.env.NODE_ENV) {
27
- if (format === undefined) {
28
- throw new Error('invariant requires an error message argument');
29
- }
30
- }
31
-
32
- if (!condition) {
33
- var error;
34
- if (format === undefined) {
35
- error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
36
- } else {
37
- var args = [a, b, c, d, e, f];
38
- var argIndex = 0;
39
- error = new Error('Invariant Violation: ' + format.replace(/%s/g, function () {
40
- return args[argIndex++];
41
- }));
42
- }
43
-
44
- error.framesToPop = 1; // we don't care about invariant's own frame
45
- throw error;
46
- }
47
- };
48
-
49
- module.exports = invariant;
package/lib/isNode.js DELETED
@@ -1,23 +0,0 @@
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 isNode
10
- * @typechecks
11
- */
12
-
13
- /**
14
- * @param {*} object The object to check.
15
- * @return {boolean} Whether or not the object is a DOM node.
16
- */
17
- 'use strict';
18
-
19
- function isNode(object) {
20
- return !!(object && (typeof Node === 'function' ? object instanceof Node : typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string'));
21
- }
22
-
23
- module.exports = isNode;
package/lib/keyMirror.js DELETED
@@ -1,48 +0,0 @@
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 keyMirror
10
- * @typechecks static-only
11
- */
12
-
13
- 'use strict';
14
-
15
- var invariant = require("./invariant");
16
-
17
- /**
18
- * Constructs an enumeration with keys equal to their value.
19
- *
20
- * For example:
21
- *
22
- * var COLORS = keyMirror({blue: null, red: null});
23
- * var myColor = COLORS.blue;
24
- * var isColorValid = !!COLORS[myColor];
25
- *
26
- * The last line could not be performed if the values of the generated enum were
27
- * not equal to their keys.
28
- *
29
- * Input: {key1: val1, key2: val2}
30
- * Output: {key1: key1, key2: key2}
31
- *
32
- * @param {object} obj
33
- * @return {object}
34
- */
35
- var keyMirror = function (obj) {
36
- var ret = {};
37
- var key;
38
- !(obj instanceof Object && !Array.isArray(obj)) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'keyMirror(...): Argument must be an object.') : invariant(false) : undefined;
39
- for (key in obj) {
40
- if (!obj.hasOwnProperty(key)) {
41
- continue;
42
- }
43
- ret[key] = key;
44
- }
45
- return ret;
46
- };
47
-
48
- module.exports = keyMirror;
package/lib/keyOf.js DELETED
@@ -1,35 +0,0 @@
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 keyOf
10
- */
11
-
12
- /**
13
- * Allows extraction of a minified key. Let's the build system minify keys
14
- * without loosing the ability to dynamically use key strings as values
15
- * themselves. Pass in an object with a single key/val pair and it will return
16
- * you the string key of that single record. Suppose you want to grab the
17
- * value for a key 'className' inside of an object. Key/val minification may
18
- * have aliased that key to be 'xa12'. keyOf({className: null}) will return
19
- * 'xa12' in that case. Resolve keys you want to use once at startup time, then
20
- * reuse those resolutions.
21
- */
22
- "use strict";
23
-
24
- var keyOf = function (oneKeyObj) {
25
- var key;
26
- for (key in oneKeyObj) {
27
- if (!oneKeyObj.hasOwnProperty(key)) {
28
- continue;
29
- }
30
- return key;
31
- }
32
- return null;
33
- };
34
-
35
- module.exports = keyOf;