bamjs
Version:
Backbone with modifications. Adds heirarchy to Views, derived properties on Models and general utility.
71 lines (52 loc) • 1.93 kB
JavaScript
// Generated by CoffeeScript 1.8.0
(function() {
var Backbone, Collection, Model,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Backbone = require('./backbone');
Model = require('./model');
Collection = (function(_super) {
__extends(Collection, _super);
function Collection() {
return Collection.__super__.constructor.apply(this, arguments);
}
Collection.prototype.model = Model;
/*
Returns the model at the index immediately before the passed in model
instance. If the model instance is the first model in the collection, or
the model instance does not exist in the collection, this will return
null.
*/
Collection.prototype.before = function(model) {
var index;
index = this.indexOf(model);
if (index === -1 || index === 0) {
return null;
}
return this.at(index - 1);
};
/*
Returns the model at the index immediately after the passed in model
instance. If the model instance is the last model in the collection, or
the model instance does not exist in the collection, this will return
null.
*/
Collection.prototype.after = function(model) {
var index;
index = this.indexOf(model);
if (index === -1 || index === this.length - 1) {
return null;
}
return this.at(index + 1);
};
/*
Convenience function for getting an array of all the models in a
collection
*/
Collection.prototype.all = function() {
return this.models.slice();
};
return Collection;
})(Backbone.Collection);
module.exports = Collection;
}).call(this);