react 15.0.2-alpha.1 → 15.0.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.
@@ -152,9 +152,6 @@ var ReactTestUtils = {
152
152
  * @return {array} an array of all the matches.
153
153
  */
154
154
  scryRenderedDOMComponentsWithClass: function (root, classNames) {
155
- if (!Array.isArray(classNames)) {
156
- classNames = classNames.split(/\s+/);
157
- }
158
155
  return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
159
156
  if (ReactTestUtils.isDOMComponent(inst)) {
160
157
  var className = inst.className;
@@ -163,6 +160,11 @@ var ReactTestUtils = {
163
160
  className = inst.getAttribute('class') || '';
164
161
  }
165
162
  var classList = className.split(/\s+/);
163
+
164
+ if (!Array.isArray(classNames)) {
165
+ !(classNames !== undefined) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'TestUtils.scryRenderedDOMComponentsWithClass expects a ' + 'className as a second argument.') : invariant(false) : void 0;
166
+ classNames = classNames.split(/\s+/);
167
+ }
166
168
  return classNames.every(function (name) {
167
169
  return classList.indexOf(name) !== -1;
168
170
  });
@@ -334,6 +336,7 @@ var ShallowComponentWrapper = function (element) {
334
336
  this.construct(element);
335
337
  };
336
338
  _assign(ShallowComponentWrapper.prototype, ReactCompositeComponent.Mixin, {
339
+ _constructComponent: ReactCompositeComponent.Mixin._constructComponentWithoutOwner,
337
340
  _instantiateReactComponent: function (element) {
338
341
  return new NoopInternalComponent(element);
339
342
  },
@@ -11,4 +11,4 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- module.exports = '15.0.2-alpha.1';
14
+ module.exports = '15.0.2';
@@ -290,7 +290,7 @@ var SVGDOMPropertyConfig = {
290
290
  DOMAttributeNames: {}
291
291
  };
292
292
 
293
- Object.keys(ATTRS).map(function (key) {
293
+ Object.keys(ATTRS).forEach(function (key) {
294
294
  SVGDOMPropertyConfig.Properties[key] = 0;
295
295
  if (ATTRS[key]) {
296
296
  SVGDOMPropertyConfig.DOMAttributeNames[key] = ATTRS[key];
@@ -11,6 +11,7 @@
11
11
 
12
12
  'use strict';
13
13
 
14
+ var KeyEscapeUtils = require('./KeyEscapeUtils');
14
15
  var traverseAllChildren = require('./traverseAllChildren');
15
16
  var warning = require('fbjs/lib/warning');
16
17
 
@@ -24,7 +25,7 @@ function flattenSingleChildIntoContext(traverseContext, child, name) {
24
25
  var result = traverseContext;
25
26
  var keyUnique = result[name] === undefined;
26
27
  if (process.env.NODE_ENV !== 'production') {
27
- process.env.NODE_ENV !== 'production' ? warning(keyUnique, 'flattenChildren(...): Encountered two children with the same key, ' + '`%s`. Child keys must be unique; when two children share a key, only ' + 'the first child will be used.', name) : void 0;
28
+ process.env.NODE_ENV !== 'production' ? warning(keyUnique, 'flattenChildren(...): Encountered two children with the same key, ' + '`%s`. Child keys must be unique; when two children share a key, only ' + 'the first child will be used.', KeyEscapeUtils.unescape(name)) : void 0;
28
29
  }
29
30
  if (keyUnique && child != null) {
30
31
  result[name] = child;
package/lib/onlyChild.js CHANGED
@@ -22,7 +22,7 @@ var invariant = require('fbjs/lib/invariant');
22
22
  * of children.
23
23
  *
24
24
  * @param {?object} children Child collection structure.
25
- * @return {ReactComponent} The first and only `ReactComponent` contained in the
25
+ * @return {ReactElement} The first and only `ReactElement` contained in the
26
26
  * structure.
27
27
  */
28
28
  function onlyChild(children) {
@@ -16,6 +16,7 @@ var ReactElement = require('./ReactElement');
16
16
 
17
17
  var getIteratorFn = require('./getIteratorFn');
18
18
  var invariant = require('fbjs/lib/invariant');
19
+ var KeyEscapeUtils = require('./KeyEscapeUtils');
19
20
  var warning = require('fbjs/lib/warning');
20
21
 
21
22
  var SEPARATOR = '.';
@@ -26,19 +27,8 @@ var SUBSEPARATOR = ':';
26
27
  * pattern.
27
28
  */
28
29
 
29
- var userProvidedKeyEscaperLookup = {
30
- '=': '=0',
31
- ':': '=2'
32
- };
33
-
34
- var userProvidedKeyEscapeRegex = /[=:]/g;
35
-
36
30
  var didWarnAboutMaps = false;
37
31
 
38
- function userProvidedKeyEscaper(match) {
39
- return userProvidedKeyEscaperLookup[match];
40
- }
41
-
42
32
  /**
43
33
  * Generate a key string that identifies a component within a set.
44
34
  *
@@ -51,33 +41,12 @@ function getComponentKey(component, index) {
51
41
  // that we don't block potential future ES APIs.
52
42
  if (component && typeof component === 'object' && component.key != null) {
53
43
  // Explicit key
54
- return wrapUserProvidedKey(component.key);
44
+ return KeyEscapeUtils.escape(component.key);
55
45
  }
56
46
  // Implicit key determined by the index in the set
57
47
  return index.toString(36);
58
48
  }
59
49
 
60
- /**
61
- * Escape a component key so that it is safe to use in a reactid.
62
- *
63
- * @param {*} text Component key to be escaped.
64
- * @return {string} An escaped string.
65
- */
66
- function escapeUserProvidedKey(text) {
67
- return ('' + text).replace(userProvidedKeyEscapeRegex, userProvidedKeyEscaper);
68
- }
69
-
70
- /**
71
- * Wrap a `key` value explicitly provided by the user to distinguish it from
72
- * implicitly-generated keys generated by a component's index in its parent.
73
- *
74
- * @param {string} key Value of a user-provided `key` attribute
75
- * @return {string}
76
- */
77
- function wrapUserProvidedKey(key) {
78
- return '$' + escapeUserProvidedKey(key);
79
- }
80
-
81
50
  /**
82
51
  * @param {?*} children Children tree container.
83
52
  * @param {!string} nameSoFar Name of the key path so far.
@@ -135,7 +104,7 @@ function traverseAllChildrenImpl(children, nameSoFar, callback, traverseContext)
135
104
  var entry = step.value;
136
105
  if (entry) {
137
106
  child = entry[1];
138
- nextName = nextNamePrefix + wrapUserProvidedKey(entry[0]) + SUBSEPARATOR + getComponentKey(child, 0);
107
+ nextName = nextNamePrefix + KeyEscapeUtils.escape(entry[0]) + SUBSEPARATOR + getComponentKey(child, 0);
139
108
  subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
140
109
  }
141
110
  }
@@ -173,6 +173,7 @@ if (process.env.NODE_ENV !== 'production') {
173
173
  case 'rt':
174
174
  return impliedEndTags.indexOf(parentTag) === -1;
175
175
 
176
+ case 'body':
176
177
  case 'caption':
177
178
  case 'col':
178
179
  case 'colgroup':
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": "15.0.2-alpha.1",
4
+ "version": "15.0.2",
5
5
  "keywords": [
6
6
  "react"
7
7
  ],
package/lib/OrderedMap.js DELETED
@@ -1,454 +0,0 @@
1
- /**
2
- * Copyright 2013-present, 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 OrderedMap
10
- */
11
-
12
- 'use strict';
13
-
14
- var _assign = require('object-assign');
15
-
16
- var invariant = require('fbjs/lib/invariant');
17
-
18
- var PREFIX = 'key:';
19
-
20
- /**
21
- * Utility to extract a backing object from an initialization `Array`, allowing
22
- * the caller to assist in resolving the unique ID for each entry via the
23
- * `keyExtractor` callback. The `keyExtractor` must extract non-empty strings or
24
- * numbers.
25
- * @param {Array<Object!>} arr Array of items.
26
- * @param {function} keyExtractor Extracts a unique key from each item.
27
- * @return {Object} Map from unique key to originating value that the key was
28
- * extracted from.
29
- * @throws Exception if the initialization array has duplicate extracted keys.
30
- */
31
- function extractObjectFromArray(arr, keyExtractor) {
32
- var normalizedObj = {};
33
- for (var i = 0; i < arr.length; i++) {
34
- var item = arr[i];
35
- var key = keyExtractor(item);
36
- assertValidPublicKey(key);
37
- var normalizedKey = PREFIX + key;
38
- !!(normalizedKey in normalizedObj) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'OrderedMap: IDs returned by the key extraction function must be unique.') : invariant(false) : void 0;
39
- normalizedObj[normalizedKey] = item;
40
- }
41
- return normalizedObj;
42
- }
43
-
44
- /**
45
- * Utility class for mappings with ordering. This class is to be used in an
46
- * immutable manner. A `OrderedMap` is very much like the native JavaScript
47
- * object, where keys map to values via the `get()` function. Also, like the
48
- * native JavaScript object, there is an ordering associated with the mapping.
49
- * This class is helpful because it eliminates many of the pitfalls that come
50
- * with the native JavaScript ordered mappings. Specifically, there are
51
- * inconsistencies with numeric keys in some JavaScript implementations
52
- * (enumeration ordering). This class protects against those pitfalls and
53
- * provides functional utilities for dealing with these `OrderedMap`s.
54
- *
55
- * - TODO:
56
- * - orderedMergeExclusive: Merges mutually exclusive `OrderedMap`s.
57
- * - mapReverse().
58
- *
59
- * @class {OrderedMap}
60
- * @constructor {OrderedMap}
61
- * @param {Object} normalizedObj Object that is known to be a defensive copy of
62
- * caller supplied data. We require a defensive copy to guard against callers
63
- * mutating. It is also assumed that the keys of `normalizedObj` have been
64
- * normalized and do not contain any numeric-appearing strings.
65
- * @param {number} computedLength The precomputed length of `_normalizedObj`
66
- * keys.
67
- * @private
68
- */
69
- function OrderedMapImpl(normalizedObj, computedLength) {
70
- this._normalizedObj = normalizedObj;
71
- this._computedPositions = null;
72
- this.length = computedLength;
73
- }
74
-
75
- /**
76
- * Validates a "public" key - that is, one that the public facing API supplies.
77
- * The key is then normalized for internal storage. In order to be considered
78
- * valid, all keys must be non-empty, defined, non-null strings or numbers.
79
- *
80
- * @param {string?} key Validates that the key is suitable for use in a
81
- * `OrderedMap`.
82
- * @throws Error if key is not appropriate for use in `OrderedMap`.
83
- */
84
- function assertValidPublicKey(key) {
85
- !(key !== '' && (typeof key === 'string' || typeof key === 'number')) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'OrderedMap: Key must be non-empty, non-null string or number.') : invariant(false) : void 0;
86
- }
87
-
88
- /**
89
- * Validates that arguments to range operations are within the correct limits.
90
- *
91
- * @param {number} start Start of range.
92
- * @param {number} length Length of range.
93
- * @param {number} actualLen Actual length of range that should not be
94
- * exceeded.
95
- * @throws Error if range arguments are out of bounds.
96
- */
97
- function assertValidRangeIndices(start, length, actualLen) {
98
- !(typeof start === 'number' && typeof length === 'number' && length >= 0 && start >= 0 && start + length <= actualLen) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'OrderedMap: `mapRange` and `forEachRange` expect non-negative start and ' + 'length arguments within the bounds of the instance.') : invariant(false) : void 0;
99
- }
100
-
101
- /**
102
- * Merges two "normalized" objects (objects who's key have been normalized) into
103
- * a `OrderedMap`.
104
- *
105
- * @param {Object} a Object of key value pairs.
106
- * @param {Object} b Object of key value pairs.
107
- * @return {OrderedMap} new `OrderedMap` that results in merging `a` and `b`.
108
- */
109
- function _fromNormalizedObjects(a, b) {
110
- // Second optional, both must be plain JavaScript objects.
111
- !(a && a.constructor === Object && (!b || b.constructor === Object)) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'OrderedMap: Corrupted instance of OrderedMap detected.') : invariant(false) : void 0;
112
-
113
- var newSet = {};
114
- var length = 0;
115
- var key;
116
- for (key in a) {
117
- if (a.hasOwnProperty(key)) {
118
- newSet[key] = a[key];
119
- length++;
120
- }
121
- }
122
-
123
- for (key in b) {
124
- if (b.hasOwnProperty(key)) {
125
- // Increment length if not already added via first object (a)
126
- if (!(key in newSet)) {
127
- length++;
128
- }
129
- newSet[key] = b[key];
130
- }
131
- }
132
- return new OrderedMapImpl(newSet, length);
133
- }
134
-
135
- /**
136
- * Methods for `OrderedMap` instances.
137
- *
138
- * @lends OrderedMap.prototype
139
- * TODO: Make this data structure lazy, unify with LazyArray.
140
- * TODO: Unify this with ImmutableObject - it is to be used immutably.
141
- * TODO: If so, consider providing `fromObject` API.
142
- * TODO: Create faster implementation of merging/mapping from original Array,
143
- * without having to first create an object - simply for the sake of merging.
144
- */
145
- var OrderedMapMethods = {
146
-
147
- /**
148
- * Returns whether or not a given key is present in the map.
149
- *
150
- * @param {string} key Valid string key to lookup membership for.
151
- * @return {boolean} Whether or not `key` is a member of the map.
152
- * @throws Error if provided known invalid key.
153
- */
154
- has: function (key) {
155
- assertValidPublicKey(key);
156
- var normalizedKey = PREFIX + key;
157
- return normalizedKey in this._normalizedObj;
158
- },
159
-
160
- /**
161
- * Returns the object for a given key, or `undefined` if not present. To
162
- * distinguish an undefined entry vs not being in the set, use `has()`.
163
- *
164
- * @param {string} key String key to lookup the value for.
165
- * @return {Object?} Object at key `key`, or undefined if not in map.
166
- * @throws Error if provided known invalid key.
167
- */
168
- get: function (key) {
169
- assertValidPublicKey(key);
170
- var normalizedKey = PREFIX + key;
171
- return this.has(key) ? this._normalizedObj[normalizedKey] : undefined;
172
- },
173
-
174
- /**
175
- * Merges, appending new keys to the end of the ordering. Keys in `orderedMap`
176
- * that are redundant with `this`, maintain the same ordering index that they
177
- * had in `this`. This is how standard JavaScript object merging would work.
178
- * If you wish to prepend a `OrderedMap` to the beginning of another
179
- * `OrderedMap` then simply reverse the order of operation. This is the analog
180
- * to `merge(x, y)`.
181
- *
182
- * @param {OrderedMap} orderedMap OrderedMap to merge onto the end.
183
- * @return {OrderedMap} New OrderedMap that represents the result of the
184
- * merge.
185
- */
186
- merge: function (orderedMap) {
187
- !(orderedMap instanceof OrderedMapImpl) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'OrderedMap.merge(...): Expected an OrderedMap instance.') : invariant(false) : void 0;
188
- return _fromNormalizedObjects(this._normalizedObj, orderedMap._normalizedObj);
189
- },
190
-
191
- /**
192
- * Functional map API. Returns a new `OrderedMap`.
193
- *
194
- * @param {Function} cb Callback to invoke for each item.
195
- * @param {Object?=} context Context to invoke callback from.
196
- * @return {OrderedMap} OrderedMap that results from mapping.
197
- */
198
- map: function (cb, context) {
199
- return this.mapRange(cb, 0, this.length, context);
200
- },
201
-
202
- /**
203
- * The callback `cb` is invoked with the arguments (item, key,
204
- * indexInOriginal).
205
- *
206
- * @param {Function} cb Determines result for each item.
207
- * @param {number} start Start index of map range.
208
- * @param {end} length End index of map range.
209
- * @param {*!?} context Context of callback invocation.
210
- * @return {OrderedMap} OrderedMap resulting from mapping the range.
211
- */
212
- mapRange: function (cb, start, length, context) {
213
- var thisSet = this._normalizedObj;
214
- var newSet = {};
215
- var i = 0;
216
- assertValidRangeIndices(start, length, this.length);
217
- var end = start + length - 1;
218
- for (var key in thisSet) {
219
- if (thisSet.hasOwnProperty(key)) {
220
- if (i >= start) {
221
- if (i > end) {
222
- break;
223
- }
224
- var item = thisSet[key];
225
- newSet[key] = cb.call(context, item, key.substr(PREFIX.length), i);
226
- }
227
- i++;
228
- }
229
- }
230
- return new OrderedMapImpl(newSet, length);
231
- },
232
-
233
- /**
234
- * Function filter API. Returns new `OrderedMap`.
235
- *
236
- * @param {Function} cb Callback to invoke for each item.
237
- * @param {Object?=} context Context to invoke callback from.
238
- * @return {OrderedMap} OrderedMap that results from filtering.
239
- */
240
- filter: function (cb, context) {
241
- return this.filterRange(cb, 0, this.length, context);
242
- },
243
-
244
- /**
245
- * The callback `cb` is invoked with the arguments (item, key,
246
- * indexInOriginal).
247
- *
248
- * @param {Function} cb Returns true if item should be in result.
249
- * @param {number} start Start index of filter range.
250
- * @param {number} length End index of map range.
251
- * @param {*!?} context Context of callback invocation.
252
- * @return {OrderedMap} OrderedMap resulting from filtering the range.
253
- */
254
- filterRange: function (cb, start, length, context) {
255
- var newSet = {};
256
- var newSetLength = 0;
257
- this.forEachRange(function (item, key, originalIndex) {
258
- if (cb.call(context, item, key, originalIndex)) {
259
- var normalizedKey = PREFIX + key;
260
- newSet[normalizedKey] = item;
261
- newSetLength++;
262
- }
263
- }, start, length);
264
- return new OrderedMapImpl(newSet, newSetLength);
265
- },
266
-
267
- forEach: function (cb, context) {
268
- this.forEachRange(cb, 0, this.length, context);
269
- },
270
-
271
- forEachRange: function (cb, start, length, context) {
272
- assertValidRangeIndices(start, length, this.length);
273
- var thisSet = this._normalizedObj;
274
- var i = 0;
275
- var end = start + length - 1;
276
- for (var key in thisSet) {
277
- if (thisSet.hasOwnProperty(key)) {
278
- if (i >= start) {
279
- if (i > end) {
280
- break;
281
- }
282
- var item = thisSet[key];
283
- cb.call(context, item, key.substr(PREFIX.length), i);
284
- }
285
- i++;
286
- }
287
- }
288
- },
289
-
290
- /**
291
- * Even though `mapRange`/`forEachKeyRange` allow zero length mappings, we'll
292
- * impose an additional restriction here that the length of mapping be greater
293
- * than zero - the only reason is that there are many ways to express length
294
- * zero in terms of two keys and that is confusing.
295
- */
296
- mapKeyRange: function (cb, startKey, endKey, context) {
297
- var startIndex = this.indexOfKey(startKey);
298
- var endIndex = this.indexOfKey(endKey);
299
- !(startIndex !== undefined && endIndex !== undefined) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'mapKeyRange must be given keys that are present.') : invariant(false) : void 0;
300
- !(endIndex >= startIndex) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'OrderedMap.mapKeyRange(...): `endKey` must not come before `startIndex`.') : invariant(false) : void 0;
301
- return this.mapRange(cb, startIndex, endIndex - startIndex + 1, context);
302
- },
303
-
304
- forEachKeyRange: function (cb, startKey, endKey, context) {
305
- var startIndex = this.indexOfKey(startKey);
306
- var endIndex = this.indexOfKey(endKey);
307
- !(startIndex !== undefined && endIndex !== undefined) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'forEachKeyRange must be given keys that are present.') : invariant(false) : void 0;
308
- !(endIndex >= startIndex) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'OrderedMap.forEachKeyRange(...): `endKey` must not come before ' + '`startIndex`.') : invariant(false) : void 0;
309
- this.forEachRange(cb, startIndex, endIndex - startIndex + 1, context);
310
- },
311
-
312
- /**
313
- * @param {number} pos Index to search for key at.
314
- * @return {string|undefined} Either the key at index `pos` or undefined if
315
- * not in map.
316
- */
317
- keyAtIndex: function (pos) {
318
- var computedPositions = this._getOrComputePositions();
319
- var keyAtPos = computedPositions.keyByIndex[pos];
320
- return keyAtPos ? keyAtPos.substr(PREFIX.length) : undefined;
321
- },
322
-
323
- /**
324
- * @param {string} key String key from which to find the next key.
325
- * @return {string|undefined} Either the next key, or undefined if there is no
326
- * next key.
327
- * @throws Error if `key` is not in this `OrderedMap`.
328
- */
329
- keyAfter: function (key) {
330
- return this.nthKeyAfter(key, 1);
331
- },
332
-
333
- /**
334
- * @param {string} key String key from which to find the preceding key.
335
- * @return {string|undefined} Either the preceding key, or undefined if there
336
- * is no preceding.key.
337
- * @throws Error if `key` is not in this `OrderedMap`.
338
- */
339
- keyBefore: function (key) {
340
- return this.nthKeyBefore(key, 1);
341
- },
342
-
343
- /**
344
- * @param {string} key String key from which to find a following key.
345
- * @param {number} n Distance to scan forward after `key`.
346
- * @return {string|undefined} Either the nth key after `key`, or undefined if
347
- * there is no next key.
348
- * @throws Error if `key` is not in this `OrderedMap`.
349
- */
350
- nthKeyAfter: function (key, n) {
351
- var curIndex = this.indexOfKey(key);
352
- !(curIndex !== undefined) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'OrderedMap.nthKeyAfter: The key `%s` does not exist in this instance.', key) : invariant(false) : void 0;
353
- return this.keyAtIndex(curIndex + n);
354
- },
355
-
356
- /**
357
- * @param {string} key String key from which to find a preceding key.
358
- * @param {number} n Distance to scan backwards before `key`.
359
- * @return {string|undefined} Either the nth key before `key`, or undefined if
360
- * there is no previous key.
361
- * @throws Error if `key` is not in this `OrderedMap`.
362
- */
363
- nthKeyBefore: function (key, n) {
364
- return this.nthKeyAfter(key, -n);
365
- },
366
-
367
- /**
368
- * @param {string} key Key to find the index of.
369
- * @return {number|undefined} Index of the provided key, or `undefined` if the
370
- * key is not found.
371
- */
372
- indexOfKey: function (key) {
373
- assertValidPublicKey(key);
374
- var normalizedKey = PREFIX + key;
375
- var computedPositions = this._getOrComputePositions();
376
- var computedPosition = computedPositions.indexByKey[normalizedKey];
377
- // Just writing it this way to make it clear this is intentional.
378
- return computedPosition === undefined ? undefined : computedPosition;
379
- },
380
-
381
- /**
382
- * @return {Array} An ordered array of this object's values.
383
- */
384
- toArray: function () {
385
- var result = [];
386
- var thisSet = this._normalizedObj;
387
- for (var key in thisSet) {
388
- if (thisSet.hasOwnProperty(key)) {
389
- result.push(thisSet[key]);
390
- }
391
- }
392
- return result;
393
- },
394
-
395
- /**
396
- * Finds the key at a given position, or indicates via `undefined` that that
397
- * position does not exist in the `OrderedMap`. It is appropriate to return
398
- * undefined, indicating that the key doesn't exist in the `OrderedMap`
399
- * because `undefined` is not ever a valid `OrderedMap` key.
400
- *
401
- * @private
402
- * @return {string?} Name of the item at position `pos`, or `undefined` if
403
- * there is no item at that position.
404
- */
405
- _getOrComputePositions: function () {
406
- // TODO: Entertain computing this at construction time in some less
407
- // performance critical paths.
408
- var computedPositions = this._computedPositions;
409
- if (!computedPositions) {
410
- this._computePositions();
411
- }
412
- return this._computedPositions;
413
- },
414
-
415
- /**
416
- * Precomputes the index/key mapping for future lookup. Since `OrderedMap`s
417
- * are immutable, there is only ever a need to perform this once.
418
- * @private
419
- */
420
- _computePositions: function () {
421
- this._computedPositions = {
422
- keyByIndex: {},
423
- indexByKey: {}
424
- };
425
- var keyByIndex = this._computedPositions.keyByIndex;
426
- var indexByKey = this._computedPositions.indexByKey;
427
- var index = 0;
428
- var thisSet = this._normalizedObj;
429
- for (var key in thisSet) {
430
- if (thisSet.hasOwnProperty(key)) {
431
- keyByIndex[index] = key;
432
- indexByKey[key] = index;
433
- index++;
434
- }
435
- }
436
- }
437
- };
438
-
439
- _assign(OrderedMapImpl.prototype, OrderedMapMethods);
440
-
441
- var OrderedMap = {
442
- from: function (orderedMap) {
443
- !(orderedMap instanceof OrderedMapImpl) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'OrderedMap.from(...): Expected an OrderedMap instance.') : invariant(false) : void 0;
444
- return _fromNormalizedObjects(orderedMap._normalizedObj, null);
445
- },
446
-
447
- fromArray: function (arr, keyExtractor) {
448
- !Array.isArray(arr) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'OrderedMap.fromArray(...): First argument must be an array.') : invariant(false) : void 0;
449
- !(typeof keyExtractor === 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'OrderedMap.fromArray(...): Second argument must be a function used ' + 'to determine the unique key for each entry.') : invariant(false) : void 0;
450
- return new OrderedMapImpl(extractObjectFromArray(arr, keyExtractor), arr.length);
451
- }
452
- };
453
-
454
- module.exports = OrderedMap;