/backbone-null-store

Null storage engine for Backbone.js

Primary LanguageCoffeeScript

Backbone-Null-Store

A backbone.js store that doesn't store.

Purpose

If you have a collection/model that you want to be able to treat like any other collection/model (calling .fetch()/.save()/etc) but you don't want it to be stored (e.g. it may be transient data, or you may be using localStorage and not want to use up your valuable 5MB storing stuff you can easily re-fetch) then you can use backbone-null-store.

Installing: Browser

In a browser, simply include this script via a <script> tag.

<script src='/js/backbone-null-store.js'></script>

Installing: Node.JS

In Node.JS, simply require() this script, and then infect Backbone:

var backbone = require('backbone');
require('./backbone-null-store').infect(backbone);

Usage

Once the module has "infected" Backbone, you can simply tell your model or collection that it's a null store by adding nullStore:true to it's prototype:

var MyCollection = Backbone.Collection.extend({
  nullStore: true
});

CoffeeScript

Backbone-null-store was written in CoffeeScript; here's the equivalent usage:

class MyCollection extends Backbone.Collection
  nullStore: true

License

WTFPL v2 or later. (If you want a different license then just tweet me @benjiegillam)