mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Fix OrderedMap.
Tim caught a bug. Squashing it so he can rebase on top of it.
This commit is contained in:
committed by
Paul O’Shannessy
parent
ddb0ef98f7
commit
492407bcc9
@@ -18,6 +18,7 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
var invariant = require('invariant');
|
||||
var mixInto = require('mixInto');
|
||||
var throwIf = require('throwIf');
|
||||
|
||||
@@ -349,6 +350,10 @@ var OrderedMapMethods = {
|
||||
mapKeyRange: function(cb, startKey, endKey, context) {
|
||||
var startIndex = this.indexOfKey(startKey);
|
||||
var endIndex = this.indexOfKey(endKey);
|
||||
invariant(
|
||||
startIndex !== undefined && endIndex !== undefined,
|
||||
'mapKeyRange must be given keys that are present.'
|
||||
);
|
||||
if (endIndex < startIndex) {
|
||||
throw new Error(RANGE_ARGS);
|
||||
}
|
||||
@@ -358,6 +363,10 @@ var OrderedMapMethods = {
|
||||
forEachKeyRange: function(cb, startKey, endKey, context) {
|
||||
var startIndex = this.indexOfKey(startKey);
|
||||
var endIndex = this.indexOfKey(endKey);
|
||||
invariant(
|
||||
startIndex !== undefined && endIndex !== undefined,
|
||||
'forEachKeyRange must be given keys that are present.'
|
||||
);
|
||||
if (endIndex < startIndex) {
|
||||
throw new Error(RANGE_ARGS);
|
||||
}
|
||||
|
||||
@@ -739,10 +739,16 @@ describe('OrderedMap', function() {
|
||||
}).not.toThrow();
|
||||
expect(function() {
|
||||
om.mapKeyRange(duplicate, 'x' , 3, scope);
|
||||
}).not.toThrow();
|
||||
}).toThrow(
|
||||
'Invariant Violation: mapKeyRange must be given keys ' +
|
||||
'that are present.'
|
||||
);
|
||||
expect(function() {
|
||||
om.forEachKeyRange(duplicate, 'x', 3, scope);
|
||||
}).not.toThrow();
|
||||
}).toThrow(
|
||||
'Invariant Violation: forEachKeyRange must be given keys ' +
|
||||
'that are present.'
|
||||
);
|
||||
|
||||
expect(function() {
|
||||
om.mapRange(duplicate, 0, 4, scope);
|
||||
|
||||
Reference in New Issue
Block a user