UNPKG

backbone.projections

Version:
67 lines (53 loc) 2 kB
// Generated by CoffeeScript 1.6.2 var Collection, extend, __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; }; Collection = ((typeof window !== "undefined" && window !== null ? window.Backbone : void 0) || require('backbone')).Collection; extend = ((typeof window !== "undefined" && window !== null ? window._ : void 0) || require('underscore')).extend; exports.Sorted = (function(_super) { __extends(Sorted, _super); function Sorted(underlying, options) { var _this = this; if (options == null) { options = {}; } if (!options.comparator) { throw new Error("provide a comparator"); } this.underlying = underlying; this.model = underlying.model; this.comparator = options.comparator; this.options = extend({}, underlying.options, options); Sorted.__super__.constructor.call(this, this.underlying.models, options); this.listenTo(this.underlying, { reset: function() { return _this.reset(_this.underlying.models); }, remove: function(model) { return _this.remove(model); }, add: function(model) { return _this.add(model); } }); } return Sorted; })(Collection); exports.Reversed = (function(_super) { __extends(Reversed, _super); function Reversed(underlying, options) { if (options == null) { options = {}; } options.comparator = function(model) { return -underlying.indexOf(model); }; Reversed.__super__.constructor.call(this, underlying, options); this.listenTo(this.underlying, { sort: this.sort }); } return Reversed; })(exports.Sorted); exports.SortedCollection = exports.Sorted; exports.ReversedCollection = exports.Reversed;