Update Backbone/Underscore vendor folders.

Former-commit-id: 3317d501fe535d91eefab8a5dcb3a88a791e20ac
This commit is contained in:
John-David Dalton
2012-10-06 20:56:42 -07:00
parent b3d68893df
commit b07ef98c8f
6 changed files with 53 additions and 9 deletions

View File

@@ -1234,8 +1234,8 @@
// memory leaks. // memory leaks.
dispose: function() { dispose: function() {
this.undelegateEvents(); this.undelegateEvents();
if (this.model) this.model.off(null, null, this); if (this.model && this.model.off) this.model.off(null, null, this);
if (this.collection) this.collection.off(null, null, this); if (this.collection && this.collection.off) this.collection.off(null, null, this);
return this; return this;
}, },

View File

@@ -286,11 +286,11 @@ $(document).ready(function() {
test("dispose", 0, function() { test("dispose", 0, function() {
var View = Backbone.View.extend({ var View = Backbone.View.extend({
events: { events: {
click: function() { ok(false); } click: function() { fail(); }
}, },
initialize: function() { initialize: function() {
this.model.on('all x', function(){ ok(false); }, this); this.model.on('all x', function(){ fail(); }, this);
this.collection.on('all x', function(){ ok(false); }, this); this.collection.on('all x', function(){ fail(); }, this);
} }
}); });
@@ -305,6 +305,11 @@ $(document).ready(function() {
view.$el.click(); view.$el.click();
}); });
test("dispose with non Backbone objects", 0, function() {
var view = new Backbone.View({model: {}, collection: {}});
view.dispose();
});
test("view#remove calls dispose.", 1, function() { test("view#remove calls dispose.", 1, function() {
var view = new Backbone.View(); var view = new Backbone.View();

View File

@@ -144,6 +144,7 @@ $(document).ready(function() {
equal(_.indexOf(numbers, 2), 1, 'can compute indexOf, even without the native function'); equal(_.indexOf(numbers, 2), 1, 'can compute indexOf, even without the native function');
var result = (function(){ return _.indexOf(arguments, 2); })(1, 2, 3); var result = (function(){ return _.indexOf(arguments, 2); })(1, 2, 3);
equal(result, 1, 'works on an arguments object'); equal(result, 1, 'works on an arguments object');
equal(_.indexOf(null, 2), -1, 'handles nulls properly');
var numbers = [10, 20, 30, 40, 50], num = 35; var numbers = [10, 20, 30, 40, 50], num = 35;
var index = _.indexOf(numbers, num, true); var index = _.indexOf(numbers, num, true);
@@ -172,6 +173,7 @@ $(document).ready(function() {
equal(_.lastIndexOf(numbers, 0), 8, 'lastIndexOf the other element'); equal(_.lastIndexOf(numbers, 0), 8, 'lastIndexOf the other element');
var result = (function(){ return _.lastIndexOf(arguments, 1); })(1, 0, 1, 0, 0, 1, 0, 0, 0); var result = (function(){ return _.lastIndexOf(arguments, 1); })(1, 0, 1, 0, 0, 1, 0, 0, 0);
equal(result, 5, 'works on an arguments object'); equal(result, 5, 'works on an arguments object');
equal(_.indexOf(null, 2), -1, 'handles nulls properly');
numbers = [1, 2, 3, 1, 2, 3, 1, 2, 3]; numbers = [1, 2, 3, 1, 2, 3, 1, 2, 3];
index = _.lastIndexOf(numbers, 2, 2); index = _.lastIndexOf(numbers, 2, 2);

View File

@@ -25,6 +25,10 @@ $(document).ready(function() {
answer = null; answer = null;
_.each([1, 2, 3], function(num, index, arr){ if (_.include(arr, num)) answer = true; }); _.each([1, 2, 3], function(num, index, arr){ if (_.include(arr, num)) answer = true; });
ok(answer, 'can reference the original collection from inside the iterator'); ok(answer, 'can reference the original collection from inside the iterator');
answers = 0;
_.each(null, function(){ ++answers; });
equal(answers, 0, 'handles a null properly');
}); });
test('map', function() { test('map', function() {
@@ -50,6 +54,9 @@ $(document).ready(function() {
var ids = _.map(document.images, function(n){ return n.id; }); var ids = _.map(document.images, function(n){ return n.id; });
ok(ids[0] == 'chart_image', 'can use collection methods on HTMLCollections'); ok(ids[0] == 'chart_image', 'can use collection methods on HTMLCollections');
var ifnull = _.map(null, function(){});
ok(_.isArray(ifnull) && ifnull.length === 0, 'handles a null properly');
}); });
test('reduce', function() { test('reduce', function() {
@@ -69,6 +76,15 @@ $(document).ready(function() {
var sum = _.reduce([1, 2, 3], function(sum, num){ return sum + num; }); var sum = _.reduce([1, 2, 3], function(sum, num){ return sum + num; });
equal(sum, 6, 'default initial value'); equal(sum, 6, 'default initial value');
var ifnull;
try {
_.reduce(null, function(){});
} catch (ex) {
ifnull = ex;
}
ok(ifnull instanceof TypeError, 'handles a null (without inital value) properly');
ok(_.reduce(null, function(){}, 138) === 138, 'handles a null (with initial value) properly');
equal(_.reduce([], function(){}, undefined), undefined, 'undefined can be passed as a special case'); equal(_.reduce([], function(){}, undefined), undefined, 'undefined can be passed as a special case');
raises(function() { _.reduce([], function(){}); }, TypeError, 'throws an error for empty arrays with no initial value'); raises(function() { _.reduce([], function(){}); }, TypeError, 'throws an error for empty arrays with no initial value');
}); });
@@ -83,9 +99,19 @@ $(document).ready(function() {
var list = _.foldr(["foo", "bar", "baz"], function(memo, str){ return memo + str; }); var list = _.foldr(["foo", "bar", "baz"], function(memo, str){ return memo + str; });
equal(list, 'bazbarfoo', 'default initial value'); equal(list, 'bazbarfoo', 'default initial value');
var ifnull;
try {
_.reduceRight(null, function(){});
} catch (ex) {
ifnull = ex;
}
ok(ifnull instanceof TypeError, 'handles a null (without inital value) properly');
var sum = _.reduceRight({a: 1, b: 2, c: 3}, function(sum, num){ return sum + num; }); var sum = _.reduceRight({a: 1, b: 2, c: 3}, function(sum, num){ return sum + num; });
equal(sum, 6, 'default initial value on object'); equal(sum, 6, 'default initial value on object');
ok(_.reduceRight(null, function(){}, 138) === 138, 'handles a null (with initial value) properly');
equal(_.reduceRight([], function(){}, undefined), undefined, 'undefined can be passed as a special case'); equal(_.reduceRight([], function(){}, undefined), undefined, 'undefined can be passed as a special case');
raises(function() { _.reduceRight([], function(){}); }, TypeError, 'throws an error for empty arrays with no initial value'); raises(function() { _.reduceRight([], function(){}); }, TypeError, 'throws an error for empty arrays with no initial value');

File diff suppressed because one or more lines are too long

View File

@@ -1,4 +1,4 @@
// Underscore.js 1.4.1 // Underscore.js 1.4.2
// http://underscorejs.org // http://underscorejs.org
// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. // (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
// Underscore may be freely distributed under the MIT license. // Underscore may be freely distributed under the MIT license.
@@ -65,7 +65,7 @@
} }
// Current version. // Current version.
_.VERSION = '1.4.1'; _.VERSION = '1.4.2';
// Collection Functions // Collection Functions
// -------------------- // --------------------
@@ -74,6 +74,7 @@
// Handles objects with the built-in `forEach`, arrays, and raw objects. // Handles objects with the built-in `forEach`, arrays, and raw objects.
// Delegates to **ECMAScript 5**'s native `forEach` if available. // Delegates to **ECMAScript 5**'s native `forEach` if available.
var each = _.each = _.forEach = function(obj, iterator, context) { var each = _.each = _.forEach = function(obj, iterator, context) {
if (obj == null) return;
if (nativeForEach && obj.forEach === nativeForEach) { if (nativeForEach && obj.forEach === nativeForEach) {
obj.forEach(iterator, context); obj.forEach(iterator, context);
} else if (obj.length === +obj.length) { } else if (obj.length === +obj.length) {
@@ -93,6 +94,7 @@
// Delegates to **ECMAScript 5**'s native `map` if available. // Delegates to **ECMAScript 5**'s native `map` if available.
_.map = _.collect = function(obj, iterator, context) { _.map = _.collect = function(obj, iterator, context) {
var results = []; var results = [];
if (obj == null) return results;
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context); if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
each(obj, function(value, index, list) { each(obj, function(value, index, list) {
results[results.length] = iterator.call(context, value, index, list); results[results.length] = iterator.call(context, value, index, list);
@@ -104,6 +106,7 @@
// or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available. // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
_.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) { _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
var initial = arguments.length > 2; var initial = arguments.length > 2;
if (obj == null) obj = [];
if (nativeReduce && obj.reduce === nativeReduce) { if (nativeReduce && obj.reduce === nativeReduce) {
if (context) iterator = _.bind(iterator, context); if (context) iterator = _.bind(iterator, context);
return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator); return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
@@ -124,6 +127,7 @@
// Delegates to **ECMAScript 5**'s native `reduceRight` if available. // Delegates to **ECMAScript 5**'s native `reduceRight` if available.
_.reduceRight = _.foldr = function(obj, iterator, memo, context) { _.reduceRight = _.foldr = function(obj, iterator, memo, context) {
var initial = arguments.length > 2; var initial = arguments.length > 2;
if (obj == null) obj = [];
if (nativeReduceRight && obj.reduceRight === nativeReduceRight) { if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
if (context) iterator = _.bind(iterator, context); if (context) iterator = _.bind(iterator, context);
return arguments.length > 2 ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator); return arguments.length > 2 ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
@@ -163,6 +167,7 @@
// Aliased as `select`. // Aliased as `select`.
_.filter = _.select = function(obj, iterator, context) { _.filter = _.select = function(obj, iterator, context) {
var results = []; var results = [];
if (obj == null) return results;
if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context); if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context);
each(obj, function(value, index, list) { each(obj, function(value, index, list) {
if (iterator.call(context, value, index, list)) results[results.length] = value; if (iterator.call(context, value, index, list)) results[results.length] = value;
@@ -173,6 +178,7 @@
// Return all the elements for which a truth test fails. // Return all the elements for which a truth test fails.
_.reject = function(obj, iterator, context) { _.reject = function(obj, iterator, context) {
var results = []; var results = [];
if (obj == null) return results;
each(obj, function(value, index, list) { each(obj, function(value, index, list) {
if (!iterator.call(context, value, index, list)) results[results.length] = value; if (!iterator.call(context, value, index, list)) results[results.length] = value;
}); });
@@ -185,6 +191,7 @@
_.every = _.all = function(obj, iterator, context) { _.every = _.all = function(obj, iterator, context) {
iterator || (iterator = _.identity); iterator || (iterator = _.identity);
var result = true; var result = true;
if (obj == null) return result;
if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context); if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context);
each(obj, function(value, index, list) { each(obj, function(value, index, list) {
if (!(result = result && iterator.call(context, value, index, list))) return breaker; if (!(result = result && iterator.call(context, value, index, list))) return breaker;
@@ -198,6 +205,7 @@
var any = _.some = _.any = function(obj, iterator, context) { var any = _.some = _.any = function(obj, iterator, context) {
iterator || (iterator = _.identity); iterator || (iterator = _.identity);
var result = false; var result = false;
if (obj == null) return result;
if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context); if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
each(obj, function(value, index, list) { each(obj, function(value, index, list) {
if (result || (result = iterator.call(context, value, index, list))) return breaker; if (result || (result = iterator.call(context, value, index, list))) return breaker;
@@ -209,6 +217,7 @@
// Aliased as `include`. // Aliased as `include`.
_.contains = _.include = function(obj, target) { _.contains = _.include = function(obj, target) {
var found = false; var found = false;
if (obj == null) return found;
if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1; if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
found = any(obj, function(value) { found = any(obj, function(value) {
return value === target; return value === target;
@@ -500,6 +509,7 @@
// If the array is large and already in sort order, pass `true` // If the array is large and already in sort order, pass `true`
// for **isSorted** to use binary search. // for **isSorted** to use binary search.
_.indexOf = function(array, item, isSorted) { _.indexOf = function(array, item, isSorted) {
if (array == null) return -1;
var i = 0, l = array.length; var i = 0, l = array.length;
if (isSorted) { if (isSorted) {
if (typeof isSorted == 'number') { if (typeof isSorted == 'number') {
@@ -516,6 +526,7 @@
// Delegates to **ECMAScript 5**'s native `lastIndexOf` if available. // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available.
_.lastIndexOf = function(array, item, from) { _.lastIndexOf = function(array, item, from) {
if (array == null) return -1;
var hasIndex = from != null; var hasIndex = from != null;
if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) { if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) {
return hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item); return hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item);