This project is read-only.

There are APIs like the datajs cache API that will return deferred objects. Deferred objects are similar to the jQuery Deferred objects as described here and the Promises objects as described here.

There are a number of incompatibilities between these deferred/promise implementations, and there is some work in implementing the full specification for either one, so datajs behaves as follows.

  1. If jQuery with Deferred support is available when an API is used, the deferred objects returned are jQuery deferred objects.
  2. Otherwise, a very lightweight internal implementation is used. This implementation does not support adding handlers after a deferred value has been resolved or rejected.

In practice, this means that web applications that already use jQuery can use the more advanced features of jQuery Deferred objects, while applications that use other frameworks can still use .then to add a pair of handlers, which the most common pattern in any case.

For example, the following code will always run and behave the same, regardless of whether the jQuery or the lightweight implementation is used.

var cache = datajs.createDataCache({ /* options */ });
cache.readRange(0, 10).then(function (data) {
  // ...
}, function (error) {
  // ...

Last edited Apr 6, 2011 at 6:40 AM by marcelolr, version 1


No comments yet.