npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ampersand-optimistic-sync

v3.1.1

Published

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

Downloads

74

Readme

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.