JSPM

lazy-async

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 976
  • Score
    100M100P100Q100050F
  • License MIT

Generate a lazy-execution API by queueing requests

Package Exports

  • lazy-async

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lazy-async) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

lazy-async Build Status

Generate a lazy-execution API by queueing requests

Install

$ npm install --save lazy-async

Usage

var Lazy = require('lazy-async')

var maps = Lazy(['autocomplete.places'], loadGoogleMaps)

maps.autocomplete.places({input: 'SF'}, function (err, results) {
  //=> handle err/results
})

Lazy will call loadGoogleMaps immediately. It passes a callback to loadGoogleMaps that expects an error if the library failed to load or the JS API upon success (err, api).

Before the library loads, you can call the methods you define. The calls will be queued up until the library loads. If the library loads, all calls will be executed in call-order. If the library fails to load, all callbacks will be called with the error generated by your load function.

All subsequent calls are either routed to the loaded API or fulfilled with the original error.

API

Lazy(methods, load) -> object

methods

Required
Type: array[string]

An array of methods in dot property syntax, e.g. users.fetch. These methods should exist on the remote API once loaded. Methods may accept a callback as their last argument.

load

Required
Type: function
Arguments: callback

A function that will load the remote API and call the callback with err, api once ready.

License

MIT © Ben Drucker