Explorar el Código

@uppy/utils: remove ponyfill for `Array#findIndex` (#3080)

The built-in method is supported everywhere.
Antoine du Hamel hace 3 años
padre
commit
9866fc1f5c

+ 1 - 1
packages/@uppy/provider-views/src/ProviderView/ProviderView.js

@@ -112,7 +112,7 @@ module.exports = class ProviderView {
         let updatedDirectories
 
         const state = this.plugin.getPluginState()
-        const index = findIndex(state.directories, (dir) => id === dir.id)
+        const index = state.directories.findIndex((dir) => id === dir.id)
 
         if (index !== -1) {
           updatedDirectories = state.directories.slice(0, index + 1)

+ 1 - 3
packages/@uppy/utils/src/RateLimitedQueue.js

@@ -1,5 +1,3 @@
-const findIndex = require('./findIndex')
-
 function createCancelError () {
   return new Error('Cancelled')
 }
@@ -84,7 +82,7 @@ class RateLimitedQueue {
       },
     }
 
-    const index = findIndex(this.#queuedHandlers, (other) => {
+    const index = this.#queuedHandlers.findIndex((other) => {
       return handler.priority > other.priority
     })
     if (index === -1) {

+ 1 - 8
packages/@uppy/utils/src/findIndex.js

@@ -1,13 +1,6 @@
 /**
- * Array.prototype.findIndex ponyfill for old browsers.
- *
  * @param {Array} array
  * @param {Function} predicate
  * @returns {number}
  */
-module.exports = function findIndex (array, predicate) {
-  for (let i = 0; i < array.length; i++) {
-    if (predicate(array[i])) return i
-  }
-  return -1
-}
+module.exports = Function.prototype.call.bind(Array.prototype.findIndex)