New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

backbone-promised

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backbone-promised

Wraps up Backbone's XHR methods into a consistent promisable API

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

backbone-promised

browser support Build Status Build Status

Wraps up Backbone's sync/XHR functions (Backbone.Model's save, fetch, destroy and Backbone.Collection's fetch) as promises. If using the native response from these methods, on success, they return a jQuery XHR promisable, on failure a falsy value. This eliminates the need to check to see if it's thennable. Another advantage is these promises return on options.success or options.error, rather than just the XHR response, so when the modified promises resolve, you can be sure that the collection or model is also updated by that time.

Install

npm install backbone-promised

Usage

BackbonePromised(prototype, resolver)

BackbonePromised takes two arguments; first a prototype (or object) with the methods that should be extended (save, fetch, destroy). Generally this will be Backbone.Model.prototype, but can be any object. The second argument is a Promise resolver so you can use any promise library, as long as you pass in a function that is called with a resolver function, like when.promise.

var Backbone = require("backbone");
var BackbonePromised = require("backbone-promised");
var when = require("when");
var Model = Backbone.Model.extend(BackbonePromised(Backbone.model.prototype, when.promise));

var user = new Model({ name: "Dash Rendar" });
user.save().then(({ model, options, response }) => {
  console.log("success!", response);
}, ({ model, options, response }) => {
  console.error("rejected!", response);
});

License

MIT License

Keywords

FAQs

Package last updated on 14 Jan 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc