kubetail-org / loadjs

A tiny async loader / dependency manager for modern browsers (899 bytes)
MIT License
2.57k stars 149 forks source link

added Promise support via returnPromise argument #86

Closed amorey closed 5 years ago

amorey commented 5 years ago

This PR adds Promise support via a returnPromise argument:

var prom = loadjs(['/path/to/file1.js', '/path/to/file2.js'], {returnPromise: true});

prom.then(
  function() { /* fulfilled */},
  function(pathsNotFound) { /* rejected */ }
);

It is backwards compatible and supports success/error callbacks and bundle load events simultaneously:

var prom = loadjs(['/path/to/file1.js', '/path/to/file2.js'], 'bundle1', {
  success: function() { /* success */ },
  error: function(pathsNotFound) { /* error */ },
  returnPromise: true
});

prom.then(
  function() { /* success */},
  function(pathsNotFound) { /* error */ }
);

loadjs.ready('bundle1', function() {
  /* success */
});