export function memoise()

in src/lib/components/molecules/canvas-map/lib/util/memoise.js [12:33]


export function memoise(fn) {
  let called = false

  /** @type {ReturnType} */
  let lastResult

  /** @type {Array<any>} */
  let lastArgs

  let lastThis

  return function (...args) {
    const nextArgs = Array.prototype.slice.call(args)
    if (!called || this !== lastThis || !arrayEquals(nextArgs, lastArgs)) {
      called = true
      lastThis = this
      lastArgs = nextArgs
      lastResult = fn.apply(this, args)
    }
    return lastResult
  }
}