Skip to content

Commit

Permalink
GH-2082: Replacing usage of Array.prototype.find/findIndex (#2117)
Browse files Browse the repository at this point in the history
* GH-2082: Replacing usage of Array.prototype.find and Array.protoype.findIndex with alternate solutions

* GH-2082: Adding eslint rule for restricting usage of findIndex/find methods
  • Loading branch information
michaelcunningham19 authored and johnBartos committed Feb 14, 2019
1 parent 4b4a067 commit 2e9f2de
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.js
Expand Up @@ -76,6 +76,11 @@ module.exports = {
'never'
],

'no-restricted-properties': [2,
{ 'property': 'findIndex' }, // Intended to block usage of Array.prototype.findIndex
{ 'property': 'find' } // Intended to block usage of Array.prototype.find
],

'standard/no-callback-literal': 1,
'import/first': 1,
'no-var': 1,
Expand Down
10 changes: 9 additions & 1 deletion src/controller/level-controller.js
Expand Up @@ -427,7 +427,15 @@ export default class LevelController extends EventHandler {
}

if (currentLevel.audioGroupIds) {
const urlId = currentLevel.audioGroupIds.findIndex((groupId) => groupId === audioGroupId);
let urlId = -1;

for (let i = 0; i < currentLevel.audioGroupIds.length; i++) {
if (currentLevel.audioGroupIds[i] === audioGroupId) {
urlId = i;
break;
}
}

if (urlId !== currentLevel.urlId) {
currentLevel.urlId = urlId;
this.startLoad();
Expand Down
10 changes: 9 additions & 1 deletion src/controller/timeline-controller.js
Expand Up @@ -197,7 +197,15 @@ class TimelineController extends EventHandler {
this.tracks.forEach((track, index) => {
let textTrack;
if (index < inUseTracks.length) {
const inUseTrack = [].slice.call(inUseTracks).find(inUseTrack => canReuseVttTextTrack(inUseTrack, track));
let inUseTrack = null;

for (let i = 0; i < inUseTracks.length; i++) {
if (canReuseVttTextTrack(inUseTracks[i], track)) {
inUseTrack = inUseTracks[i];
break;
}
}

// Reuse tracks with the same label, but do not reuse 608/708 tracks
if (inUseTrack) {
textTrack = inUseTrack;
Expand Down

0 comments on commit 2e9f2de

Please sign in to comment.