You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP

ic-ajax

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ic-ajax

ember friendly $.ajax wrapper

0.1.0
Version published
Weekly downloads
3.6K
34%
Maintainers
1
Weekly downloads
 
Created

ic-ajax

Ember-friendly jQuery.ajax wrapper.

  • returns RSVP promises
  • makes apps more testable (resolves promises with Ember.run)
  • makes testing ajax simpler with fixture support

Installation

bower install ic-ajax

npm install ic-ajax

... or download main.js and include it into your app however you want.

Module Support

  • AMD
  • Node.JS (CJS)
  • Globals

API

Ajax simply wraps jQuery.ajax with two exceptions:

  • success and error callbacks are not supported
  • does not resolve three arguments like $.ajax but instead an object with the three "arguments" as keys (real promises only resolve a single value and ic-ajax uses RSVP).

Other than that, use it exactly like $.ajax.

App.ApplicationRoute = Ember.Route.extend({
  model: function() {
    return ic.ajax('/foo').then(function(result) {
      // result.response
      // result.textStatus
      // result.jqXHR
      return result.response;
    });
  }
}

Simplified Testing

Adding fixtures with defineFixture tells ic-ajax to resolve the promise with the fixture matching a url instead of making a request. This allows you to test your app without creating fake servers with sinon, etc.

Example:

ic.ajax.defineFixture('api/v1/courses', {
  response: [{name: 'basket weaving'}],
  jqXHR: {},
  textStatus: 'success'
});

ic.ajax('api/v1/courses').then(function(result) {
  deepEqual(result, ic.ajax.lookupFixture('api/v1/courses'));
});

Contributing

bower install
npm install
npm test

Special Thanks

Inspired by discourse ajax.

MIT Style license

(c) 2013 Instructure, Inc.

Keywords

FAQs

Package last updated on 25 Nov 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts