Skip to content

Commit

Permalink
refactor: Remove TimeRanges without an index deprecation warning (#3827)
Browse files Browse the repository at this point in the history
This aligns the methods with the spec.

BREAKING CHANGE: removing ability to use TimeRange methods without an index.
  • Loading branch information
misteroneill authored and gkatsev committed Jan 18, 2017
1 parent c340dbc commit e12bedb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/js/utils/time-ranges.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @file time-ranges.js
* @module time-ranges
*/
import log from './log.js';

/**
* Returns the time for the specified index at the start or end
Expand Down Expand Up @@ -51,8 +50,8 @@ import log from './log.js';
* @throws {Error} if the timeRanges provided are over the maxIndex
*/
function rangeCheck(fnName, index, maxIndex) {
if (index < 0 || index > maxIndex) {
throw new Error(`Failed to execute '${fnName}' on 'TimeRanges': The index provided (${index}) is greater than or equal to the maximum bound (${maxIndex}).`);
if (typeof index !== 'number' || index < 0 || index > maxIndex) {
throw new Error(`Failed to execute '${fnName}' on 'TimeRanges': The index provided (${index}) is non-numeric or out of bounds (0-${maxIndex}).`);
}
}

Expand All @@ -79,10 +78,6 @@ function rangeCheck(fnName, index, maxIndex) {
* @throws {Error} if rangeIndex is more than the length of ranges
*/
function getRange(fnName, valueIndex, ranges, rangeIndex) {
if (rangeIndex === undefined) {
log.warn(`DEPRECATED: Function '${fnName}' on 'TimeRanges' called without an index argument.`);
rangeIndex = 0;
}
rangeCheck(fnName, rangeIndex, ranges.length - 1);
return ranges[rangeIndex][valueIndex];
}
Expand Down
19 changes: 19 additions & 0 deletions test/unit/utils/time-ranges.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,22 @@ QUnit.test('should create a fake multiple timerange', function(assert) {
/Failed to execute 'end'/,
'fails if end is called with with an invalid index');
});

QUnit.test('should throw without being given an index', function(assert) {
const tr = createTimeRanges([
[0, 10],
[11, 20]
]);

assert.throws(
() => tr.start(),
/Failed to execute 'start'/,
'start throws if no index is given'
);

assert.throws(
() => tr.end(),
/Failed to execute 'end'/,
'end throws if no index is given'
);
});

0 comments on commit e12bedb

Please sign in to comment.