Skip to content

Commit

Permalink
fix(stackPrefetch.js): Prevent undefined imageId prefetch
Browse files Browse the repository at this point in the history
Change the prefetch nearest range to always return valid indices
  • Loading branch information
wayfarer3130 committed Oct 22, 2021
1 parent 6f9887e commit 54aa7a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
24 changes: 6 additions & 18 deletions src/stackTools/stackPrefetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,20 @@ function range(lowEnd, highEnd) {
return arr;
}

const max = function(arr) {
return Math.max.apply(null, arr);
};

const min = function(arr) {
return Math.min.apply(null, arr);
};

function nearestIndex(arr, x) {
// Return index of nearest values in array
// http://stackoverflow.com/questions/25854212/return-index-of-nearest-values-in-an-array
const l = [];
const h = [];

arr.forEach(function(v) {
let low = 0;
let high = arr.length - 1;
arr.forEach((v, idx) => {
if (v < x) {
l.push(v);
low = Math.max(idx, low);
} else if (v > x) {
h.push(v);
high = Math.min(idx, high);
}
});

return {
low: arr.indexOf(max(l)),
high: arr.indexOf(min(h)),
};
return { low, high };
}

function prefetch(element) {
Expand Down
4 changes: 2 additions & 2 deletions src/util/uuidv4.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
let r = (Math.random() * 16) | 0,
v = c == 'x' ? r : (r & 0x3) | 0x8;
const r = (Math.random() * 16) | 0; // eslint-disable-line no-bitwise
const v = c === 'x' ? r : (r & 0x3) | 0x8; // eslint-disable-line no-bitwise

return v.toString(16);
});
Expand Down

0 comments on commit 54aa7a9

Please sign in to comment.