Skip to content

Commit ae36fba

Browse files
committed
fix(common): implementing IE-safe array search
Fixes #625
1 parent 723cfc5 commit ae36fba

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/common.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@ function ancestors(first, second) {
4444
return path;
4545
}
4646

47+
/**
48+
* IE8-safe wrapper for `Array.prototype.indexOf()`.
49+
*
50+
* @param {Array} array A JavaScript array.
51+
* @param {*} value A value to search the array for.
52+
* @return {Number} Returns the array index value of `value`, or `-1` if not present.
53+
*/
54+
function arraySearch(array, value) {
55+
if (Array.prototype.indexOf) {
56+
return array.indexOf(value, Number(arguments[2]) || 0);
57+
}
58+
var len = array.length >>> 0, from = Number(arguments[2]) || 0;
59+
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
60+
61+
if (from < 0) from += len;
62+
63+
for (; from < len; from++) {
64+
if (from in array && array[from] === value) return from;
65+
}
66+
return -1;
67+
}
68+
4769
/**
4870
* Merges a set of parameters with all parameters inherited between the common parents of the
4971
* current state and a given destination state.
@@ -61,7 +83,7 @@ function inheritParams(currentParams, newParams, $current, $to) {
6183
parentParams = parents[i].params;
6284

6385
for (var j in parentParams) {
64-
if (inheritList.indexOf(parentParams[j]) >= 0) continue;
86+
if (arraySearch(inheritList, parentParams[j]) >= 0) continue;
6587
inheritList.push(parentParams[j]);
6688
inherited[parentParams[j]] = currentParams[parentParams[j]];
6789
}

0 commit comments

Comments
 (0)