Implementation of Promises/A+ specification

The promise() function

The promise() function returns callable object(function) that has method .then(onFulfilled, onRejected)

The promise is created as:

var prom = promise();

To fulfill/satisfy the promise

call it as prom(true, params). Where the params is an array of values that will be applied to onFulfilled callback functions registered by .then() method.

To reject the promise

call it as prom(false, params). Where the params is an array of values that will be applied to onRejected callbacks registered by .then() method.

Redefined Element.request() function

The promise.tis also redefines the Element.request() method - http get/post/put/delete call. So with this module included the Element.request() can be called in one of three forms:

  1. element.request( callback: function, httpcmd , url: string [, params: object [, headers: object] ] ) : true | false
    - asynchronous request with server response delivered to callback function.
  2. element.request( timeout: integer, httpcmd , url: string [, params: object [, headers: object] ] ) : (data, status)
    - synchronous request with server response delivered as first return value and http status code as second.
  3. element.request( httpcmd , url: string [, params: object [, headers: object] ] ) : promise,
    - asynchronous request, server response is delivered to the onsuccess callback registered by .then(onsuccess,onfailure) call of the promise.