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

ampersand-optimistic-sync

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ampersand-optimistic-sync

A sync wrapper for Backbone.sync and ampersand-sync that implements optimistic concurrency in HTTP.

  • 3.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

ampersand-optimistic-sync

A wrapper for Backbone.sync and ampersand-sync that implements optimistic concurrency over HTTP.

Not sure what optimistic concurrency is? You can read a bit more about it and implementing it in HTTP here.

How do I use it?

Default Behavior

For the default behavior, just extend like so:

var Model = require('ampersand-model'); // or require('backbone').Model;
var syncMixin = require('ampersand-optimistic-sync');

module.exports = Model.extend(syncMixin(Model));

Now your model will check for the ETag header on every request to the server.

If it exists, the ETag will be set on the model as _version and a sync:version (args: model, version) event will fire.

On updates, sync will now automatically include the _version value as an If-Match header.

If the update is successful, the new ETag that the server sends will be set as _version.

If the update request returns a 412 error, a sync:invalid-version (args: model, version, data) event is fired.

Customizing Behavior

The mixin takes an optional second config argument that can be used to modify behavior.

config.type

Allowed values; etag (default), last-modified

When config.type is changed to last-modified like so:

var Model = require('ampersand-model'); // or require('backbone').Model;
var syncMixin = require('ampersand-optimistic-sync');

module.exports = Model.extend(syncMixin(Model, {type: 'last-modified'}));

The model will now store Last-Modified header values as _version and send _version as an If-Unmodified-Since header.

config.invalidHandler

If config.invalidHandler is a function, it will be registered as a sync:invalid-version handler before your first update request is sent.

Keywords

FAQs

Package last updated on 27 Aug 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