react 0.10.0 → 0.11.2

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 (104) hide show
  1. package/README.md +3 -0
  2. package/dist/JSXTransformer.js +20344 -0
  3. package/dist/react-with-addons.js +20276 -0
  4. package/dist/react-with-addons.min.js +22 -0
  5. package/dist/react.js +18484 -0
  6. package/dist/react.min.js +21 -0
  7. package/lib/BeforeInputEventPlugin.js +222 -0
  8. package/lib/CSSPropertyOperations.js +3 -3
  9. package/lib/{ReactMountReady.js → CallbackQueue.js} +32 -24
  10. package/lib/ChangeEventPlugin.js +1 -1
  11. package/lib/CompositionEventPlugin.js +5 -1
  12. package/lib/DOMChildrenOperations.js +21 -14
  13. package/lib/DOMProperty.js +45 -17
  14. package/lib/DOMPropertyOperations.js +22 -10
  15. package/lib/DefaultEventPluginOrder.js +1 -0
  16. package/lib/EventConstants.js +1 -0
  17. package/lib/EventListener.js +5 -2
  18. package/lib/EventPluginHub.js +0 -5
  19. package/lib/EventPluginRegistry.js +6 -4
  20. package/lib/EventPluginUtils.js +11 -1
  21. package/lib/ExecutionEnvironment.js +8 -2
  22. package/lib/{DefaultDOMPropertyConfig.js → HTMLDOMPropertyConfig.js} +42 -49
  23. package/lib/LinkedValueUtils.js +21 -22
  24. package/lib/LocalEventTrapMixin.js +52 -0
  25. package/lib/React.js +57 -3
  26. package/lib/ReactBrowserComponentMixin.js +4 -0
  27. package/lib/{ReactEventEmitter.js → ReactBrowserEventEmitter.js} +115 -94
  28. package/lib/ReactCSSTransitionGroup.js +2 -0
  29. package/lib/ReactCSSTransitionGroupChild.js +2 -5
  30. package/lib/ReactChildren.js +31 -10
  31. package/lib/ReactComponent.js +88 -237
  32. package/lib/ReactComponentBrowserEnvironment.js +3 -2
  33. package/lib/ReactComponentWithPureRenderMixin.js +54 -0
  34. package/lib/ReactCompositeComponent.js +222 -384
  35. package/lib/ReactDOM.js +22 -18
  36. package/lib/ReactDOMComponent.js +26 -24
  37. package/lib/ReactDOMForm.js +5 -13
  38. package/lib/ReactDOMIDOperations.js +2 -31
  39. package/lib/ReactDOMImg.js +5 -14
  40. package/lib/ReactDOMSelect.js +16 -15
  41. package/lib/ReactDOMSelection.js +35 -10
  42. package/lib/ReactDOMTextarea.js +2 -4
  43. package/lib/ReactDefaultBatchingStrategy.js +3 -3
  44. package/lib/ReactDefaultInjection.js +18 -15
  45. package/lib/ReactDefaultPerf.js +28 -11
  46. package/lib/ReactDefaultPerfAnalysis.js +4 -0
  47. package/lib/ReactDescriptor.js +251 -0
  48. package/lib/ReactDescriptorValidator.js +283 -0
  49. package/lib/ReactEmptyComponent.js +78 -0
  50. package/lib/ReactEventEmitterMixin.js +1 -3
  51. package/lib/ReactEventListener.js +189 -0
  52. package/lib/ReactInjection.js +4 -2
  53. package/lib/ReactLink.js +24 -0
  54. package/lib/ReactMount.js +51 -19
  55. package/lib/ReactMultiChild.js +9 -11
  56. package/lib/ReactPropTransferer.js +44 -29
  57. package/lib/ReactPropTypes.js +226 -242
  58. package/lib/ReactPutListenerQueue.js +2 -2
  59. package/lib/ReactReconcileTransaction.js +14 -14
  60. package/lib/ReactServerRendering.js +5 -5
  61. package/lib/ReactServerRenderingTransaction.js +4 -5
  62. package/lib/ReactTestUtils.js +39 -21
  63. package/lib/ReactTextComponent.js +8 -22
  64. package/lib/ReactTransitionChildMapping.js +2 -2
  65. package/lib/ReactTransitionEvents.js +19 -0
  66. package/lib/ReactTransitionGroup.js +9 -6
  67. package/lib/ReactUpdates.js +139 -22
  68. package/lib/ReactWithAddons.js +5 -2
  69. package/lib/SVGDOMPropertyConfig.js +97 -0
  70. package/lib/SimpleEventPlugin.js +7 -1
  71. package/lib/SyntheticInputEvent.js +52 -0
  72. package/lib/SyntheticKeyboardEvent.js +33 -4
  73. package/lib/SyntheticMouseEvent.js +3 -0
  74. package/lib/SyntheticTouchEvent.js +4 -1
  75. package/lib/SyntheticUIEvent.js +24 -2
  76. package/lib/Transaction.js +0 -32
  77. package/lib/cloneWithProps.js +3 -1
  78. package/lib/createFullPageComponent.js +1 -1
  79. package/lib/dangerousStyleValue.js +11 -5
  80. package/lib/escapeTextForBrowser.js +2 -3
  81. package/lib/flattenChildren.js +9 -7
  82. package/lib/getEventKey.js +35 -5
  83. package/lib/getEventModifierState.js +52 -0
  84. package/lib/getMarkupWrap.js +2 -0
  85. package/lib/getTextContentAccessor.js +1 -1
  86. package/lib/hyphenate.js +3 -0
  87. package/lib/hyphenateStyleName.js +46 -0
  88. package/lib/instantiateReactComponent.js +13 -21
  89. package/lib/invariant.js +17 -19
  90. package/lib/{objMap.js → mapObject.js} +8 -3
  91. package/lib/mergeHelpers.js +11 -0
  92. package/lib/mergeInto.js +3 -2
  93. package/lib/onlyChild.js +3 -3
  94. package/lib/performance.js +33 -0
  95. package/lib/performanceNow.js +5 -14
  96. package/lib/setInnerHTML.js +85 -0
  97. package/lib/shouldUpdateReactComponent.js +12 -29
  98. package/lib/toArray.js +1 -1
  99. package/lib/traverseAllChildren.js +7 -4
  100. package/lib/update.js +57 -45
  101. package/package.json +4 -3
  102. package/lib/ReactEventTopLevelCallback.js +0 -149
  103. package/lib/createObjectFrom.js +0 -61
  104. package/lib/objMapKeyVal.js +0 -47
package/lib/update.js CHANGED
@@ -32,39 +32,41 @@ function shallowCopy(x) {
32
32
  }
33
33
  }
34
34
 
35
- var DIRECTIVE_PUSH = keyOf({$push: null});
36
- var DIRECTIVE_UNSHIFT = keyOf({$unshift: null});
37
- var DIRECTIVE_SPLICE = keyOf({$splice: null});
38
- var DIRECTIVE_SET = keyOf({$set: null});
39
- var DIRECTIVE_MERGE = keyOf({$merge: null});
40
-
41
- var ALL_DIRECTIVES_LIST = [
42
- DIRECTIVE_PUSH,
43
- DIRECTIVE_UNSHIFT,
44
- DIRECTIVE_SPLICE,
45
- DIRECTIVE_SET,
46
- DIRECTIVE_MERGE
35
+ var COMMAND_PUSH = keyOf({$push: null});
36
+ var COMMAND_UNSHIFT = keyOf({$unshift: null});
37
+ var COMMAND_SPLICE = keyOf({$splice: null});
38
+ var COMMAND_SET = keyOf({$set: null});
39
+ var COMMAND_MERGE = keyOf({$merge: null});
40
+ var COMMAND_APPLY = keyOf({$apply: null});
41
+
42
+ var ALL_COMMANDS_LIST = [
43
+ COMMAND_PUSH,
44
+ COMMAND_UNSHIFT,
45
+ COMMAND_SPLICE,
46
+ COMMAND_SET,
47
+ COMMAND_MERGE,
48
+ COMMAND_APPLY
47
49
  ];
48
50
 
49
- var ALL_DIRECTIVES_SET = {};
51
+ var ALL_COMMANDS_SET = {};
50
52
 
51
- ALL_DIRECTIVES_LIST.forEach(function(directive) {
52
- ALL_DIRECTIVES_SET[directive] = true;
53
+ ALL_COMMANDS_LIST.forEach(function(command) {
54
+ ALL_COMMANDS_SET[command] = true;
53
55
  });
54
56
 
55
- function invariantArrayCase(value, spec, directive) {
57
+ function invariantArrayCase(value, spec, command) {
56
58
  ("production" !== process.env.NODE_ENV ? invariant(
57
59
  Array.isArray(value),
58
60
  'update(): expected target of %s to be an array; got %s.',
59
- directive,
61
+ command,
60
62
  value
61
63
  ) : invariant(Array.isArray(value)));
62
- var specValue = spec[directive];
64
+ var specValue = spec[command];
63
65
  ("production" !== process.env.NODE_ENV ? invariant(
64
66
  Array.isArray(specValue),
65
67
  'update(): expected spec of %s to be an array; got %s. ' +
66
68
  'Did you forget to wrap your parameter in an array?',
67
- directive,
69
+ command,
68
70
  specValue
69
71
  ) : invariant(Array.isArray(specValue)));
70
72
  }
@@ -74,81 +76,91 @@ function update(value, spec) {
74
76
  typeof spec === 'object',
75
77
  'update(): You provided a key path to update() that did not contain one ' +
76
78
  'of %s. Did you forget to include {%s: ...}?',
77
- ALL_DIRECTIVES_LIST.join(', '),
78
- DIRECTIVE_SET
79
+ ALL_COMMANDS_LIST.join(', '),
80
+ COMMAND_SET
79
81
  ) : invariant(typeof spec === 'object'));
80
82
 
81
- if (spec.hasOwnProperty(DIRECTIVE_SET)) {
83
+ if (spec.hasOwnProperty(COMMAND_SET)) {
82
84
  ("production" !== process.env.NODE_ENV ? invariant(
83
85
  Object.keys(spec).length === 1,
84
86
  'Cannot have more than one key in an object with %s',
85
- DIRECTIVE_SET
87
+ COMMAND_SET
86
88
  ) : invariant(Object.keys(spec).length === 1));
87
89
 
88
- return spec[DIRECTIVE_SET];
90
+ return spec[COMMAND_SET];
89
91
  }
90
92
 
91
93
  var nextValue = shallowCopy(value);
92
94
 
93
- if (spec.hasOwnProperty(DIRECTIVE_MERGE)) {
94
- var mergeObj = spec[DIRECTIVE_MERGE];
95
+ if (spec.hasOwnProperty(COMMAND_MERGE)) {
96
+ var mergeObj = spec[COMMAND_MERGE];
95
97
  ("production" !== process.env.NODE_ENV ? invariant(
96
98
  mergeObj && typeof mergeObj === 'object',
97
99
  'update(): %s expects a spec of type \'object\'; got %s',
98
- DIRECTIVE_MERGE,
100
+ COMMAND_MERGE,
99
101
  mergeObj
100
102
  ) : invariant(mergeObj && typeof mergeObj === 'object'));
101
103
  ("production" !== process.env.NODE_ENV ? invariant(
102
104
  nextValue && typeof nextValue === 'object',
103
105
  'update(): %s expects a target of type \'object\'; got %s',
104
- DIRECTIVE_MERGE,
106
+ COMMAND_MERGE,
105
107
  nextValue
106
108
  ) : invariant(nextValue && typeof nextValue === 'object'));
107
- copyProperties(nextValue, spec[DIRECTIVE_MERGE]);
109
+ copyProperties(nextValue, spec[COMMAND_MERGE]);
108
110
  }
109
111
 
110
- if (spec.hasOwnProperty(DIRECTIVE_PUSH)) {
111
- invariantArrayCase(value, spec, DIRECTIVE_PUSH);
112
- spec[DIRECTIVE_PUSH].forEach(function(item) {
112
+ if (spec.hasOwnProperty(COMMAND_PUSH)) {
113
+ invariantArrayCase(value, spec, COMMAND_PUSH);
114
+ spec[COMMAND_PUSH].forEach(function(item) {
113
115
  nextValue.push(item);
114
116
  });
115
117
  }
116
118
 
117
- if (spec.hasOwnProperty(DIRECTIVE_UNSHIFT)) {
118
- invariantArrayCase(value, spec, DIRECTIVE_UNSHIFT);
119
- spec[DIRECTIVE_UNSHIFT].forEach(function(item) {
119
+ if (spec.hasOwnProperty(COMMAND_UNSHIFT)) {
120
+ invariantArrayCase(value, spec, COMMAND_UNSHIFT);
121
+ spec[COMMAND_UNSHIFT].forEach(function(item) {
120
122
  nextValue.unshift(item);
121
123
  });
122
124
  }
123
125
 
124
- if (spec.hasOwnProperty(DIRECTIVE_SPLICE)) {
126
+ if (spec.hasOwnProperty(COMMAND_SPLICE)) {
125
127
  ("production" !== process.env.NODE_ENV ? invariant(
126
128
  Array.isArray(value),
127
129
  'Expected %s target to be an array; got %s',
128
- DIRECTIVE_SPLICE,
130
+ COMMAND_SPLICE,
129
131
  value
130
132
  ) : invariant(Array.isArray(value)));
131
133
  ("production" !== process.env.NODE_ENV ? invariant(
132
- Array.isArray(spec[DIRECTIVE_SPLICE]),
134
+ Array.isArray(spec[COMMAND_SPLICE]),
133
135
  'update(): expected spec of %s to be an array of arrays; got %s. ' +
134
136
  'Did you forget to wrap your parameters in an array?',
135
- DIRECTIVE_SPLICE,
136
- spec[DIRECTIVE_SPLICE]
137
- ) : invariant(Array.isArray(spec[DIRECTIVE_SPLICE])));
138
- spec[DIRECTIVE_SPLICE].forEach(function(args) {
137
+ COMMAND_SPLICE,
138
+ spec[COMMAND_SPLICE]
139
+ ) : invariant(Array.isArray(spec[COMMAND_SPLICE])));
140
+ spec[COMMAND_SPLICE].forEach(function(args) {
139
141
  ("production" !== process.env.NODE_ENV ? invariant(
140
142
  Array.isArray(args),
141
143
  'update(): expected spec of %s to be an array of arrays; got %s. ' +
142
144
  'Did you forget to wrap your parameters in an array?',
143
- DIRECTIVE_SPLICE,
144
- spec[DIRECTIVE_SPLICE]
145
+ COMMAND_SPLICE,
146
+ spec[COMMAND_SPLICE]
145
147
  ) : invariant(Array.isArray(args)));
146
148
  nextValue.splice.apply(nextValue, args);
147
149
  });
148
150
  }
149
151
 
152
+ if (spec.hasOwnProperty(COMMAND_APPLY)) {
153
+ ("production" !== process.env.NODE_ENV ? invariant(
154
+ typeof spec[COMMAND_APPLY] === 'function',
155
+ 'update(): expected spec of %s to be a function; got %s.',
156
+ COMMAND_APPLY,
157
+ spec[COMMAND_APPLY]
158
+ ) : invariant(typeof spec[COMMAND_APPLY] === 'function'));
159
+ nextValue = spec[COMMAND_APPLY](nextValue);
160
+ }
161
+
150
162
  for (var k in spec) {
151
- if (!ALL_DIRECTIVES_SET[k]) {
163
+ if (!(ALL_COMMANDS_SET.hasOwnProperty(k) && ALL_COMMANDS_SET[k])) {
152
164
  nextValue[k] = update(value[k], spec[k]);
153
165
  }
154
166
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react",
3
3
  "description": "React is a JavaScript library for building user interfaces.",
4
- "version": "0.10.0",
4
+ "version": "0.11.2",
5
5
  "keywords": [
6
6
  "react"
7
7
  ],
@@ -17,6 +17,7 @@
17
17
  "README.md",
18
18
  "addons.js",
19
19
  "react.js",
20
+ "dist/",
20
21
  "lib/"
21
22
  ],
22
23
  "main": "react.js",
@@ -27,8 +28,8 @@
27
28
  "engines": {
28
29
  "node": ">=0.10.0"
29
30
  },
30
- "peerDependencies": {
31
- "envify": "~1.2.0"
31
+ "dependencies": {
32
+ "envify": "^2.0.0"
32
33
  },
33
34
  "browserify": {
34
35
  "transform": [
@@ -1,149 +0,0 @@
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 ReactEventTopLevelCallback
17
- * @typechecks static-only
18
- */
19
-
20
- "use strict";
21
-
22
- var PooledClass = require("./PooledClass");
23
- var ReactEventEmitter = require("./ReactEventEmitter");
24
- var ReactInstanceHandles = require("./ReactInstanceHandles");
25
- var ReactMount = require("./ReactMount");
26
-
27
- var getEventTarget = require("./getEventTarget");
28
- var mixInto = require("./mixInto");
29
-
30
- /**
31
- * @type {boolean}
32
- * @private
33
- */
34
- var _topLevelListenersEnabled = true;
35
-
36
- /**
37
- * Finds the parent React component of `node`.
38
- *
39
- * @param {*} node
40
- * @return {?DOMEventTarget} Parent container, or `null` if the specified node
41
- * is not nested.
42
- */
43
- function findParent(node) {
44
- // TODO: It may be a good idea to cache this to prevent unnecessary DOM
45
- // traversal, but caching is difficult to do correctly without using a
46
- // mutation observer to listen for all DOM changes.
47
- var nodeID = ReactMount.getID(node);
48
- var rootID = ReactInstanceHandles.getReactRootIDFromNodeID(nodeID);
49
- var container = ReactMount.findReactContainerForID(rootID);
50
- var parent = ReactMount.getFirstReactDOM(container);
51
- return parent;
52
- }
53
-
54
- /**
55
- * Calls ReactEventEmitter.handleTopLevel for each node stored in bookKeeping's
56
- * ancestor list. Separated from createTopLevelCallback to avoid try/finally
57
- * deoptimization.
58
- *
59
- * @param {string} topLevelType
60
- * @param {DOMEvent} nativeEvent
61
- * @param {TopLevelCallbackBookKeeping} bookKeeping
62
- */
63
- function handleTopLevelImpl(topLevelType, nativeEvent, bookKeeping) {
64
- var topLevelTarget = ReactMount.getFirstReactDOM(
65
- getEventTarget(nativeEvent)
66
- ) || window;
67
-
68
- // Loop through the hierarchy, in case there's any nested components.
69
- // It's important that we build the array of ancestors before calling any
70
- // event handlers, because event handlers can modify the DOM, leading to
71
- // inconsistencies with ReactMount's node cache. See #1105.
72
- var ancestor = topLevelTarget;
73
- while (ancestor) {
74
- bookKeeping.ancestors.push(ancestor);
75
- ancestor = findParent(ancestor);
76
- }
77
-
78
- for (var i = 0, l = bookKeeping.ancestors.length; i < l; i++) {
79
- topLevelTarget = bookKeeping.ancestors[i];
80
- var topLevelTargetID = ReactMount.getID(topLevelTarget) || '';
81
- ReactEventEmitter.handleTopLevel(
82
- topLevelType,
83
- topLevelTarget,
84
- topLevelTargetID,
85
- nativeEvent
86
- );
87
- }
88
- }
89
-
90
- // Used to store ancestor hierarchy in top level callback
91
- function TopLevelCallbackBookKeeping() {
92
- this.ancestors = [];
93
- }
94
- mixInto(TopLevelCallbackBookKeeping, {
95
- destructor: function() {
96
- this.ancestors.length = 0;
97
- }
98
- });
99
- PooledClass.addPoolingTo(TopLevelCallbackBookKeeping);
100
-
101
- /**
102
- * Top-level callback creator used to implement event handling using delegation.
103
- * This is used via dependency injection.
104
- */
105
- var ReactEventTopLevelCallback = {
106
-
107
- /**
108
- * Sets whether or not any created callbacks should be enabled.
109
- *
110
- * @param {boolean} enabled True if callbacks should be enabled.
111
- */
112
- setEnabled: function(enabled) {
113
- _topLevelListenersEnabled = !!enabled;
114
- },
115
-
116
- /**
117
- * @return {boolean} True if callbacks are enabled.
118
- */
119
- isEnabled: function() {
120
- return _topLevelListenersEnabled;
121
- },
122
-
123
- /**
124
- * Creates a callback for the supplied `topLevelType` that could be added as
125
- * a listener to the document. The callback computes a `topLevelTarget` which
126
- * should be the root node of a mounted React component where the listener
127
- * is attached.
128
- *
129
- * @param {string} topLevelType Record from `EventConstants`.
130
- * @return {function} Callback for handling top-level events.
131
- */
132
- createTopLevelCallback: function(topLevelType) {
133
- return function(nativeEvent) {
134
- if (!_topLevelListenersEnabled) {
135
- return;
136
- }
137
-
138
- var bookKeeping = TopLevelCallbackBookKeeping.getPooled();
139
- try {
140
- handleTopLevelImpl(topLevelType, nativeEvent, bookKeeping);
141
- } finally {
142
- TopLevelCallbackBookKeeping.release(bookKeeping);
143
- }
144
- };
145
- }
146
-
147
- };
148
-
149
- module.exports = ReactEventTopLevelCallback;
@@ -1,61 +0,0 @@
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 createObjectFrom
17
- */
18
-
19
- /**
20
- * Construct an object from an array of keys
21
- * and optionally specified value or list of values.
22
- *
23
- * >>> createObjectFrom(['a','b','c']);
24
- * {a: true, b: true, c: true}
25
- *
26
- * >>> createObjectFrom(['a','b','c'], false);
27
- * {a: false, b: false, c: false}
28
- *
29
- * >>> createObjectFrom(['a','b','c'], 'monkey');
30
- * {c:'monkey', b:'monkey' c:'monkey'}
31
- *
32
- * >>> createObjectFrom(['a','b','c'], [1,2,3]);
33
- * {a: 1, b: 2, c: 3}
34
- *
35
- * >>> createObjectFrom(['women', 'men'], [true, false]);
36
- * {women: true, men: false}
37
- *
38
- * @param Array list of keys
39
- * @param mixed optional value or value array. defaults true.
40
- * @returns object
41
- */
42
- function createObjectFrom(keys, values /* = true */) {
43
- if ("production" !== process.env.NODE_ENV) {
44
- if (!Array.isArray(keys)) {
45
- throw new TypeError('Must pass an array of keys.');
46
- }
47
- }
48
-
49
- var object = {};
50
- var isArray = Array.isArray(values);
51
- if (typeof values == 'undefined') {
52
- values = true;
53
- }
54
-
55
- for (var ii = keys.length; ii--;) {
56
- object[keys[ii]] = isArray ? values[ii] : values;
57
- }
58
- return object;
59
- }
60
-
61
- module.exports = createObjectFrom;
@@ -1,47 +0,0 @@
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 objMapKeyVal
17
- */
18
-
19
- "use strict";
20
-
21
- /**
22
- * Behaves the same as `objMap` but invokes func with the key first, and value
23
- * second. Use `objMap` unless you need this special case.
24
- * Invokes func as:
25
- *
26
- * func(key, value, iteration)
27
- *
28
- * @param {?object} obj Object to map keys over
29
- * @param {!function} func Invoked for each key/val pair.
30
- * @param {?*} context
31
- * @return {?object} Result of mapping or null if obj is falsey
32
- */
33
- function objMapKeyVal(obj, func, context) {
34
- if (!obj) {
35
- return null;
36
- }
37
- var i = 0;
38
- var ret = {};
39
- for (var key in obj) {
40
- if (obj.hasOwnProperty(key)) {
41
- ret[key] = func.call(context, key, obj[key], i++);
42
- }
43
- }
44
- return ret;
45
- }
46
-
47
- module.exports = objMapKeyVal;