function lazyLoad (file, opts) {
  var fn = null
  return function _lazyLoad (params, options, callback) {
    if (fn === null) {
      fn = require(`./api/${file}.js`)(opts)
    }
    return fn(params, options, callback)
  }
}
function lazyLoad (file, opts) {
  var fn = null
  return function _lazyLoad (params, options, callback) {
    if (fn === null) {
      fn = require(`./api/${file}.js`)(opts)
    }
    return fn(params, options, callback)
  }
}
function lazyLoad ( file , opts ) { var fn = null return function _lazyLoad ( params , options , callback ) { if ( fn === null ) { fn = require ( ` ${ file } ` ) ( opts ) } return fn ( params , options , callback ) } }
It's unlikely that a user needs all of our APIs, and since require is a sync operation that takes time (given the amount of APIs we have), let's lazy load them, so a given API file will be required only if the user actually needs that API. The following implementation takes advantage of js closures to have a simple cache with the least overhead.
It s unlikely that a user needs all of our APIs and since require is a sync operation that takes time ( given the amount of APIs we have ) let s lazy load them so a given API file will be required only if the user actually needs that API . The following implementation takes advantage of js closures to have a simple cache with the least overhead .
lazyLoad function