Git Product home page Git Product logo

simply-deferred's Introduction

#Simply Deferred ###jQuery-like Deferred API for Node and the browser

##Installation npm install simply-deferred

##Usage var Deferred = require('simply-deferred').Deferred; var rendering = new Deferred(); rendering.done(function(){ console.log('Finished rendering'); });

//...

rendering.resolve();

##API Simply Deferred is fullly compatible with jQuery's API, so the docs and usage are the same. Like the jQuery deferred API, it provides the following methods:

  • Deferred()
  • deferred.state()
  • deferred.done()
  • deferred.fail()
  • deferred.progress()
  • deferred.always()
  • deferred.promise()
  • deferred.notify()
  • deferred.notifyWith()
  • deferred.resolve()
  • deferred.resolveWith()
  • deferred.rejectWith()
  • deferred.reject()
  • deferred.pipe()
  • deferred.then()
  • when()

###Collaborating Please feel free to raise issues on github.com/sudhirj/simply-deferred/issues - both obvious bugs or incompatibilities with jQuery are welcome.

If you'd like contribute a fix or a feature, that would be even better. Please make sure all pull requests are accompanied by tests, though.

If you'd like to start work on a feature that is not part of the jQuery library, just raise an empty pull request and let's talk about it first - the goal here for this library to be a drop-in replacement for jQuery, with the same docs and API.

###Support If you'd like to financially support the development of this library or just say thanks, you can send Bitcoin to 18TAaTamWaiv7cMK6FdbYeRzJUqBnECEah. I'm also available to consult on how promises can improve your codebase - mail me at [email protected]

###Usage with Zepto

Zepto now has a deferred module available, so you might want to use that if Zepto is your primary reason for using Simply Deferred.

Simply Deffered also acts as a plugin to Zepto. The absence of a Deferred library was one of the biggest reasons I've been holding back, so I thought it made sense to write one. Once you have both Zepto and Simply Deferred on your page, just do Deferred.installInto(Zepto) to set it up. The installation makes the following changes to bring it closer to jQuery:

  • Aliases the Deferred constructor to $.Deferred.
  • Aliases the when method to $.when.
  • Wraps $.ajax to return a promise, which has only the following methods: state(), done(), fail() and always(). The arguments passed to the done and fail callbacks are the same ones passed to the success and error options.

simply-deferred's People

Contributors

ericmatthys avatar fukamachi avatar rraval avatar sudhirj avatar therabidbanana avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.