@jokeyrhyme/promised-requirejs

1.0.0 • Public • Published

promised-requirejs

a Promise interface for loading AMD modules via Require.js

npm module travis-ci

API

dist/index.js exports a CommonJS module, an AMD module, or a global promisedRequire variable.

promisedRequire(name, retries=0)

  • @param {(String|String[])} name - module(s) that you wish to load
  • @param {Number} [retries=0] - number of extra attempts in case of error
  • @returns {Promise}

The Promise resolve-handler has the value of the module as its first argument.

If requesting an Array of modules, then the Promise resolve-handler has an Array of the modules' values as its first argument.

Examples

Require.js:

require([
  'bacon', 'moment'
], function (Bacon, Moment) {
  /* TODO: ... */
}, function (err) {
  /* TODO: ... */  
});

promisedRequire (ES5):

promisedRequire(['bacon', 'moment'])
.then(function (results) {
  var Bacon = results[0];
  var Moment = results[1];
  /* TODO: ... */
})
.catch(function (err) {
  /* TODO: ... */  
});

promisedRequire (ES2015):

promisedRequire(['bacon', 'moment'])
.then(([ Bacon, Moment ]) => {
  /* TODO: ... */
})
.catch(function (err) {
  /* TODO: ... */  
});

Package Sidebar

Install

npm i @jokeyrhyme/promised-requirejs

Weekly Downloads

0

Version

1.0.0

License

BSD-2-Clause

Last publish

Collaborators

  • jokeyrhyme