The new Dojo 1.8 has some really nice features. One in particular is the dojo/request.

The new dojo/request object returns a Promise object which makes a promise to your code that an eventual value will be returned. Promises have the following characteristics:

  • Can be in one of three states: unfulfilled, resolved, rejected
  • May only change from unfulfilled to resolved or unfulfilled to rejected
  • Implements a then method for registering callbacks for notification of state change
  • Callbacks cannot change the value produced by the promise
  • A promise's then method returns a new promise, to provide chaining while keeping the original promise's value unchanged

Another new feature of dojo/request is the dojo/request/registry. It allows you to register providers against a URL pattern or other criteria. The provider can be one of the existing dojo providers or your own custom provider. With this in mind, you can register a custom provider that will serve simulated data to your code.

You can code your application to make the necessary ajax requests and use the data provided by the registered provider. When you are ready to provide actual data, you can simply remove the request registration and your application will continue to function. Below is a example of how this provider can be created and used. The example uses a timeout to simulate server delay.