The library for web and native user interfaces.
Fix OrderedMap.
Tim caught a bug. Squashing it so he can rebase on top of it.
Jordan Walke committed
Jul 24, 2013 at 17:19 UTC
492407bcc98745577a68c0813c8cf529fa3d4da4
2 files changed
+17
-2
src/utils/OrderedMap.js
+9
@@ -18,6 +18,7 @@
18
19
"use strict";
20
21
+var invariant = require('invariant');
22
var mixInto = require('mixInto');
23
var throwIf = require('throwIf');
24
@@ -349,6 +350,10 @@ var OrderedMapMethods = {
350
mapKeyRange: function(cb, startKey, endKey, context) {
351
var startIndex = this.indexOfKey(startKey);
352
var endIndex = this.indexOfKey(endKey);
353
+ invariant(
354
+ startIndex !== undefined && endIndex !== undefined,
355
+ 'mapKeyRange must be given keys that are present.'
356
+ );
357
if (endIndex < startIndex) {
358
throw new Error(RANGE_ARGS);
359
}
@@ -358,6 +363,10 @@ var OrderedMapMethods = {
363
forEachKeyRange: function(cb, startKey, endKey, context) {
364
var startIndex = this.indexOfKey(startKey);
365
var endIndex = this.indexOfKey(endKey);
366
+ invariant(
367
+ startIndex !== undefined && endIndex !== undefined,
368
+ 'forEachKeyRange must be given keys that are present.'
369
+ );
370
if (endIndex < startIndex) {
371
throw new Error(RANGE_ARGS);
372
}
src/utils/__tests__/OrderedMap-test.js
+8
-2
@@ -739,10 +739,16 @@ describe('OrderedMap', function() {
739
}).not.toThrow();
740
expect(function() {
741
om.mapKeyRange(duplicate, 'x' , 3, scope);
742
- }).not.toThrow();
742
+ }).toThrow(
743
+ 'Invariant Violation: mapKeyRange must be given keys ' +
744
+ 'that are present.'
745
+ );
746
expect(function() {
747
om.forEachKeyRange(duplicate, 'x', 3, scope);
745
- }).not.toThrow();
748
+ }).toThrow(
749
+ 'Invariant Violation: forEachKeyRange must be given keys ' +
750
+ 'that are present.'
751
+ );
752
753
expect(function() {
754
om.mapRange(duplicate, 0, 4, scope);