GithubHelp home page GithubHelp logo

zaach / backbone-events-promises Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shoptology/backbone-events-promises

0.0 3.0 0.0 491 KB

Plugin to backbone.js that adds promise functionality to Backbone.Events

License: MIT License

backbone-events-promises's Introduction

backbone-events-promises

BuildStatus

This plugin to backbone.js adds promise functionality to Backbone.Events, as well as any object that extends Backbone.Events - which is pretty much all of them.

Installation

npm i -D backbone-events-promises

Dependencies

Promises are implemented by using $.Deferred and $.when. This can be provided via jQuery or Zepto*. Potentially other sources such as when.js could be used if a shim was provided to apply it's functions to $.Deferred and $.when.

Additionally, it also depends on Underscore's _.extend(). Underscore is already a hard dependency of Backbone, so no harm done there.

*requires including Zepto's deferred plugin.

Usage

API:

Backbone.Events.promises(enable, [context], [options]);

Enables the backbone-promises functionality for events.

To enable on all Backbone objects, use the following code before creating any Backbone objects in your application.

var objs = ['Model', 'Collection', 'Router', 'View', 'History'];
Backbone.Events.promises(true);
for (var i = 0, l = objs.length; i < l; i++) {
    Backbone.Events.promises(true, Backbone[objs[i]].prototype);
}

Backbone.Events.trigger now returns a promise.

var promise = Backbone.Events.trigger( "event name" [, arg1] [, arg2] );

Each callback assigned to the event can return a promise. If a promise is returned, it will be added to the list of promises to resolve.

$.when API reference

backbone-events-promises's People

Contributors

defiantbidet avatar rmarscher avatar

Watchers

 avatar  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.