Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Use only single references to Backbone models across registered collections
branch: master


latest commit cd1124142c
Rhys authored
Failed to load latest commit information.
lib initial commit
test testacular -> karma
.jshintrc change the constructor
LICENSE initial commit versioning
karma.conf.js testacular -> karma
modelRegistry.js versioning
test.html testacular -> karma


this is a place where you can register collections that you want to share a pool of models. Most model stores have a reference to the models that can be called later. In a long running application this means that objects may hang around longer than needed and so people have come up with complicated solutions for figuring out when to dispose of old objects. ModelRegistry is different, it doesn't ever hold a reference to a single model. Instead you register your collections (which are probably going to be there for the life of your page anyway) and the model register will look through those for an existing model with the same id to reuse. Problem solved.

First you need to register your collection:

var registry = new Backbone.ModelStore();

You can then retrieve models from the store using:


if you are using Backbone.Advice there is a mixin that you can use to register a collection and get it to reuse model objects if one is found automagically:

Mixin.collection.modelStore = function(options) {

        idAttribute: 'id',
        modelStore: options.modelStore || { getModel: function() {} }

    this.before('initialize', function(models, options) {
        if (options && options.modelStore)
            this.modelStore = options.modelStore;

    this.around('_prepareModel', function(fn, model, options) {
        var a = model;
        if (!(model instanceof Backbone.Model)) {
            model = this.modelStore.getModel(model[this.idAttribute]) || model;
        var mod = fn(model, options);
        return mod;


You can use this like so:

var RegisteredCollection = Backbone.Collection.extend().mixin([
], {
    modelStore: registry



  • initial versionning
Something went wrong with that request. Please try again.