ariatemplates/noder-js — pull request #13 by divdavem (2014-06-10 17:21:29+00:00)
Title: Making promises more compliant with standards (non backward compatible change).

This pull request makes promises more compliant with standards, cf [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise):

* It adds support for the promise constructor:
```js
var Promise = require("noder-js/promise");
var promiseInstance = new Promise(function(fulfill, reject){
// ...
});
```

* It removes support for multiple arguments for handlers of `then` and `thenSync`. It adds the `spread` and `spreadSync` methods to pass the array fulfillment value to the handler as multiple arguments. This changes the API of `asyncRequire` and `request` in the following way:

Old usage:
```js
// For the request module:
var request = require("noder-js/request");
request("myFile.txt").then(function (content, xhr) {
// use content and xhr
});

// For the asyncRequire module:
var asyncRequire = require("noder-js/asyncRequire");
asyncRequire("moduleA","moduleB").then(function(moduleA, moduleB){
// use moduleA and moduleB
});
```

New usage:
```js
// For the request module:
var request = require("noder-js/request");
request("myFile.txt").then(function (xhr) {
// The given parameter is directly the xhr object.
// The content is now accessible with:
var content = xhr.responseText;
// use content and xhr
});

// For the asyncRequire module, it is possible to use either then or spread
var asyncRequire = require("noder-js/asyncRequire");
asyncRequire("moduleA","moduleB").then(function(array) {
// The given parameter is now an array.
var moduleA = array[0], moduleB = array[1];
// use moduleA and moduleB
});

// or

var asyncRequire = require("noder-js/asyncRequire");
asyncRequire("moduleA","moduleB").spread(function(moduleA, moduleB) {
// use moduleA and moduleB
});
```

* This pull request adds the following new methods (and removes the corresponding old ones):

New method (added) | Old method (removed)
------------- | --------------
`Promise.resolve` | *n/a*
`Promise.reject` | *n/a*
`Promise.all` | `Promise.when`
`Promise.allSettled` | `Promise.whenAll`
`promiseInstance.catch` | *n/a*
`promiseInstance.finally` | `promiseInstance.always`
`promiseInstance.done` | `promiseInstance.end`

Note that the `then`, `catch`, `finally` and `spread` methods have their equivalent `thenSync`, `catchSync`, `finallySync` and `spreadSync` methods, which call their handler synchronously if the promise is already either fulfilled or rejected at the time the `xSync` method is called.

* The promises implementation is now tested with the 2.0.4 (latest) version of [promises-aplus-tests](https://github.com/promises-aplus/promises-tests). This also means it is now possible to resolve a promise with another promise.