diff --git a/vendor/backbone/backbone.js b/vendor/backbone/backbone.js index 18acf663d..2ca5cd53b 100644 --- a/vendor/backbone/backbone.js +++ b/vendor/backbone/backbone.js @@ -1,4 +1,4 @@ -// Backbone.js 1.2.3 +// Backbone.js 1.3.2 // (c) 2010-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors // Backbone may be freely distributed under the MIT license. @@ -44,7 +44,7 @@ var slice = Array.prototype.slice; // Current version of the library. Keep in sync with `package.json`. - Backbone.VERSION = '1.2.3'; + Backbone.VERSION = '1.3.2'; // For Backbone's purposes, jQuery, Zepto, Ender, or My Library (kidding) owns // the `$` variable. @@ -242,7 +242,6 @@ listening.obj.off(name, callback, this); } - if (_.isEmpty(listeningTo)) this._listeningTo = void 0; return this; }; @@ -299,7 +298,7 @@ delete events[name]; } } - if (_.size(events)) return events; + return events; }; // Bind an event to only be triggered a single time. After the first time @@ -309,7 +308,8 @@ Events.once = function(name, callback, context) { // Map the event into a `{event: once}` object. var events = eventsApi(onceMap, {}, name, callback, _.bind(this.off, this)); - return this.on(events, void 0, context); + if (typeof name === 'string' && context == null) callback = void 0; + return this.on(events, callback, context); }; // Inversion-of-control versions of `once`. @@ -398,7 +398,8 @@ this.attributes = {}; if (options.collection) this.collection = options.collection; if (options.parse) attrs = this.parse(attrs, options) || {}; - attrs = _.defaults({}, attrs, _.result(this, 'defaults')); + var defaults = _.result(this, 'defaults'); + attrs = _.defaults(_.extend({}, defaults, attrs), defaults); this.set(attrs, options); this.changed = {}; this.initialize.apply(this, arguments); @@ -714,7 +715,7 @@ // Check if the model is currently in a valid state. isValid: function(options) { - return this._validate({}, _.defaults({validate: true}, options)); + return this._validate({}, _.extend({}, options, {validate: true})); }, // Run validation against the next complete set of model attributes, @@ -824,7 +825,7 @@ set: function(models, options) { if (models == null) return; - options = _.defaults({}, options, setOptions); + options = _.extend({}, setOptions, options); if (options.parse && !this._isModel(models)) { models = this.parse(models, options) || []; } @@ -834,6 +835,7 @@ var at = options.at; if (at != null) at = +at; + if (at > this.length) at = this.length; if (at < 0) at += this.length + 1; var set = []; @@ -978,11 +980,13 @@ return slice.apply(this.models, arguments); }, - // Get a model from the set by id. + // Get a model from the set by id, cid, model object with id or cid + // properties, or an attributes object that is transformed through modelId. get: function(obj) { if (obj == null) return void 0; - var id = this.modelId(this._isModel(obj) ? obj.attributes : obj); - return this._byId[obj] || this._byId[id] || this._byId[obj.cid]; + return this._byId[obj] || + this._byId[this.modelId(obj.attributes || obj)] || + obj.cid && this._byId[obj.cid]; }, // Returns `true` if the model is in the collection. @@ -1913,5 +1917,4 @@ }; return Backbone; - }); diff --git a/vendor/backbone/test/collection.js b/vendor/backbone/test/collection.js index 40a08f15f..a0f6bf662 100644 --- a/vendor/backbone/test/collection.js +++ b/vendor/backbone/test/collection.js @@ -101,11 +101,6 @@ assert.equal(collection2.get(model.clone()), collection2.first()); }); - QUnit.test('get with "undefined" id', function(assert) { - var collection = new Backbone.Collection([{id: 1}, {id: 'undefined'}]); - assert.equal(collection.get(1).id, 1); - }); - QUnit.test('has', function(assert) { assert.expect(15); assert.ok(col.has(a)); @@ -1583,7 +1578,7 @@ }); QUnit.test('_addReference binds all collection events & adds to the lookup hashes', function(assert) { - assert.expect(9); + assert.expect(8); var calls = {add: 0, remove: 0}; @@ -1603,7 +1598,6 @@ assert.equal(this._byId[model.id], void 0); assert.equal(this._byId[model.cid], void 0); assert.equal(model.collection, void 0); - assert.equal(model._events, void 0); } }); @@ -1739,13 +1733,14 @@ assert.equal(c2.modelId(m.attributes), void 0); }); - QUnit.test('#3039: adding at index fires with correct at', function(assert) { - assert.expect(3); - var collection = new Backbone.Collection([{at: 0}, {at: 4}]); + QUnit.test('#3039 #3951: adding at index fires with correct at', function(assert) { + assert.expect(4); + var collection = new Backbone.Collection([{val: 0}, {val: 4}]); collection.on('add', function(model, coll, options) { - assert.equal(model.get('at'), options.index); + assert.equal(model.get('val'), options.index); }); - collection.add([{at: 1}, {at: 2}, {at: 3}], {at: 1}); + collection.add([{val: 1}, {val: 2}, {val: 3}], {at: 1}); + collection.add({val: 5}, {at: 10}); }); QUnit.test('#3039: index is not sent when at is not specified', function(assert) { diff --git a/vendor/backbone/test/events.js b/vendor/backbone/test/events.js index b9b5053fe..544b39a19 100644 --- a/vendor/backbone/test/events.js +++ b/vendor/backbone/test/events.js @@ -417,6 +417,18 @@ assert.equal(obj.counterB, 1, 'counterB should have only been incremented once.'); }); + QUnit.test('bind a callback with a default context when none supplied', function(assert) { + assert.expect(1); + var obj = _.extend({ + assertTrue: function() { + assert.equal(this, obj, '`this` was bound to the callback'); + } + }, Backbone.Events); + + obj.once('event', obj.assertTrue); + obj.trigger('event'); + }); + QUnit.test('bind a callback with a supplied context', function(assert) { assert.expect(1); var TestClass = function() { @@ -587,6 +599,19 @@ assert.equal(obj.counter, 3); }); + QUnit.test('bind a callback with a supplied context using once with object notation', function(assert) { + assert.expect(1); + var obj = {counter: 0}; + var context = {}; + _.extend(obj, Backbone.Events); + + obj.once({ + a: function() { + assert.strictEqual(this, context, 'defaults `context` to `callback` param'); + } + }, context).trigger('a'); + }); + QUnit.test('once with off only by context', function(assert) { assert.expect(0); var context = {}; diff --git a/vendor/backbone/test/model.js b/vendor/backbone/test/model.js index 5022a3957..b73a1c794 100644 --- a/vendor/backbone/test/model.js +++ b/vendor/backbone/test/model.js @@ -34,6 +34,12 @@ assert.equal(model.collection, collection); }); + QUnit.test('Object.prototype properties are overridden by attributes', function(assert) { + assert.expect(1); + var model = new Backbone.Model({hasOwnProperty: true}); + assert.equal(model.get('hasOwnProperty'), true); + }); + QUnit.test('initialize with attributes and options', function(assert) { assert.expect(1); var Model = Backbone.Model.extend({ @@ -57,19 +63,6 @@ assert.equal(model.get('value'), 2); }); - QUnit.test('initialize with defaults', function(assert) { - assert.expect(2); - var Model = Backbone.Model.extend({ - defaults: { - firstName: 'Unknown', - lastName: 'Unknown' - } - }); - var model = new Model({'firstName': 'John'}); - assert.equal(model.get('firstName'), 'John'); - assert.equal(model.get('lastName'), 'Unknown'); - }); - QUnit.test('parse can return null', function(assert) { assert.expect(1); var Model = Backbone.Model.extend({ @@ -428,7 +421,7 @@ }); QUnit.test('defaults', function(assert) { - assert.expect(4); + assert.expect(9); var Defaulted = Backbone.Model.extend({ defaults: { one: 1, @@ -438,6 +431,9 @@ var model = new Defaulted({two: undefined}); assert.equal(model.get('one'), 1); assert.equal(model.get('two'), 2); + model = new Defaulted({two: 3}); + assert.equal(model.get('one'), 1); + assert.equal(model.get('two'), 3); Defaulted = Backbone.Model.extend({ defaults: function() { return { @@ -449,6 +445,15 @@ model = new Defaulted({two: undefined}); assert.equal(model.get('one'), 3); assert.equal(model.get('two'), 4); + Defaulted = Backbone.Model.extend({ + defaults: {hasOwnProperty: true} + }); + model = new Defaulted(); + assert.equal(model.get('hasOwnProperty'), true); + model = new Defaulted({hasOwnProperty: undefined}); + assert.equal(model.get('hasOwnProperty'), true); + model = new Defaulted({hasOwnProperty: false}); + assert.equal(model.get('hasOwnProperty'), false); }); QUnit.test('change, hasChanged, changedAttributes, previous, previousAttributes', function(assert) { @@ -989,8 +994,8 @@ QUnit.test('`previous` for falsey keys', function(assert) { assert.expect(2); - var model = new Backbone.Model({0: true, '': true}); - model.set({0: false, '': false}, {silent: true}); + var model = new Backbone.Model({'0': true, '': true}); + model.set({'0': false, '': false}, {silent: true}); assert.equal(model.previous(0), true); assert.equal(model.previous(''), true); });