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

backbone-localstorage

v0.3.2

Published

Backbone localStorage

Downloads

5

Readme

Backbone localStorage

Build Status

Installing Backbone localStorage

The package can be installed through npm or bower.

Using npm
npm install backbone-localstorage
Using bower
bower install backbone-localstorage

After installing the package, you can grab the backbone-localstorage.js or the minified version of it backbone-localstorage.min.js

Using Backbone localStorage

When data is fetched via Backbone.sync (models & collections), the reponse will be stored with JSON.stringify in localStorage (before any success method is called). The name under the data is stored is in the following format:

<prefix>:<url>

Where prefix is the value set by Backbone.LocalStorage.setPrefix (default unknown) and where url is the remote url from a model or collection.

Using Backbone.Model
var model = Backbone.Model.extend({
    urlRoot: '/api/pages',
    localStorage: true
});
Using Backbone.Collection
var collection = Backbone.Collection.extend({
    url: '/api/pages',
    localStorage: true
});
Using forceRefresh option
var collection = Backbone.Collection.extend({
    url: '/api/pages',
    localStorage: true
});

collection.fetch({forceRefresh:true});
Set a prefix
Backbone.LocalStorage.setPrefix('my-namespace');

Autoclear localStorage when new content is available

Since many web applications have managable content, it's hard to determine when to recognize new content. The only thing we know about our data is the url and it's timestamp when the data is strored in localStorage. With the method setVerion you can determine in which state of content the localStorage is set. At the point you call this method verions are compared (in strict mode). If the verion is not equal to it's, if present, previous version the localStorage will be cleared (only data set under prefix).

Backbone.LocalStorage.setVersion(100);

The value may be of any type (int, string, etc.).

Changelog

0.3.2

  • Fixed url property compatible as a function, not just as a string value

0.3.1

  • Fixed support of localStorage in case of iOS private mode
  • Added tests for storing objects and string (stringified or not)

0.3.0

  • Added forceRefresh option
  • Refactored id to url of model/collection

0.2.1

  • Fixed setVersion clear localStorage when verions differs

0.2.0

  • Fixed issue return null when no localStorage can be found
  • Added documentation

0.1.0 (released on friday, november 15, 2013)

  • Prototype