A backbone.js store that doesn't store.
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.
In a browser, simply include this script via a <script>
tag.
<script src='/js/backbone-null-store.js'></script>
In Node.JS, simply require()
this script, and then infect
Backbone:
var backbone = require('backbone');
require('./backbone-null-store').infect(backbone);
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
});
Backbone-null-store was written in CoffeeScript; here's the equivalent usage:
class MyCollection extends Backbone.Collection
nullStore: true
WTFPL v2 or later. (If you want a different license then just tweet me @benjiegillam)