diff --git a/vendor/backbone/backbone.js b/vendor/backbone/backbone.js index f0812fd31..d10b4fe4a 100644 --- a/vendor/backbone/backbone.js +++ b/vendor/backbone/backbone.js @@ -561,7 +561,10 @@ if (options.comparator !== void 0) this.comparator = options.comparator; this._reset(); this.initialize.apply(this, arguments); - if (models) this.reset(models, {silent: true, parse: options.parse}); + if (models) { + if (options.parse) models = this.parse(models); + this.reset(models, {silent: true, parse: options.parse}); + } }; // Define the Collection's inheritable methods. @@ -864,11 +867,12 @@ }); // Underscore methods that we want to implement on the Collection. - var methods = ['forEach', 'each', 'map', 'reduce', 'reduceRight', 'find', - 'detect', 'filter', 'select', 'reject', 'every', 'all', 'some', 'any', - 'include', 'contains', 'invoke', 'max', 'min', 'sortBy', 'sortedIndex', - 'toArray', 'size', 'first', 'initial', 'rest', 'last', 'without', 'indexOf', - 'shuffle', 'lastIndexOf', 'isEmpty', 'groupBy']; + var methods = ['forEach', 'each', 'map', 'collect', 'reduce', 'foldl', + 'inject', 'reduceRight', 'foldr', 'find', 'detect', 'filter', 'select', + 'reject', 'every', 'all', 'some', 'any', 'include', 'contains', 'invoke', + 'max', 'min', 'sortBy', 'sortedIndex', 'toArray', 'size', 'first', 'head', + 'take', 'initial', 'rest', 'tail', 'last', 'without', 'indexOf', 'shuffle', + 'lastIndexOf', 'isEmpty', 'groupBy']; // Mix in each Underscore method as a proxy to `Collection#models`. _.each(methods, function(method) { @@ -1201,9 +1205,19 @@ return this; }, + // Clean up references to this view in order to prevent latent effects and + // memory leaks. + dispose: function() { + this.undelegateEvents(); + if (this.model) this.model.off(null, null, this); + if (this.collection) this.collection.off(null, null, this); + return this; + }, + // Remove this view from the DOM. Note that the view isn't present in the // DOM by default, so calling this method may be a no-op. remove: function() { + this.dispose(); this.$el.remove(); return this; }, diff --git a/vendor/backbone/test/collection.js b/vendor/backbone/test/collection.js index 91c0b11db..4752d1dcb 100644 --- a/vendor/backbone/test/collection.js +++ b/vendor/backbone/test/collection.js @@ -47,6 +47,29 @@ $(document).ready(function() { equal(col.length, 4); }); + test("Collection: new and parse", 3, function() { + var MyCol = Backbone.Collection.extend({ + // only save the models that have an even value. + parse : function(data) { + var onlyEven = []; + _.each(data, function(datum) { + if (datum.a % 2 === 0) { + onlyEven.push(datum); + } + }); + + return onlyEven; + } + }); + anotherCol = new MyCol([ + { a : 1 },{ a : 2 },{ a : 3 },{ a : 4 } + ], { parse : true }); + + equal(anotherCol.length, 2); + equal(anotherCol.first().get('a'), 2) + equal(anotherCol.last().get('a'), 4); + }); + test("Collection: get, getByCid", 3, function() { equal(col.get(0), d); equal(col.get(2), b); diff --git a/vendor/backbone/test/view.js b/vendor/backbone/test/view.js index 88490804a..6f9351194 100644 --- a/vendor/backbone/test/view.js +++ b/vendor/backbone/test/view.js @@ -241,4 +241,28 @@ $(document).ready(function() { ok(new View().$el.is('p')); }); + test("dispose", 0, function() { + var View = Backbone.View.extend({ + events: {click: function(){ ok(false); }}, + initialize: function() { + this.model.on('all x', function(){ ok(false); }, this); + this.collection.on('all x', function(){ ok(false); }, this); + } + }); + var view = new View({ + model: new Backbone.Model, + collection: new Backbone.Collection + }); + view.dispose(); + view.model.trigger('x'); + view.collection.trigger('x'); + view.$el.click(); + }); + + test("view#remove calls dispose.", 1, function() { + var view = new Backbone.View(); + view.dispose = function() { ok(true); }; + view.remove(); + }); + }); diff --git a/vendor/benchmark.js/README.md b/vendor/benchmark.js/README.md index 62a2d1ae3..26e8d582a 100644 --- a/vendor/benchmark.js/README.md +++ b/vendor/benchmark.js/README.md @@ -14,7 +14,7 @@ For a list of upcoming features, check out our [roadmap](https://github.com/best ## Support -Benchmark.js has been tested in at least Adobe AIR 3.1, Chrome 5-21, Firefox 1.5-13, IE 6-9, Opera 9.25-12.01, Safari 3-6, Node.js 0.8.6, Narwhal 0.3.2, RingoJS 0.8, and Rhino 1.7RC5. +Benchmark.js has been tested in at least Adobe AIR 3.1, Chrome 5-21, Firefox 1.5-13, IE 6-9, Opera 9.25-12.01, Safari 3-6, Node.js 0.8.7, Narwhal 0.3.2, RingoJS 0.8, and Rhino 1.7RC5. ## Installation and usage diff --git a/vendor/requirejs/require.js b/vendor/requirejs/require.js index 34cfe231a..b592d5f22 100644 --- a/vendor/requirejs/require.js +++ b/vendor/requirejs/require.js @@ -1,5 +1,5 @@ /** vim: et:ts=4:sw=4:sts=4 - * @license RequireJS 2.0.5 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved. + * @license RequireJS 2.0.6 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved. * Available via the MIT or new BSD license. * see: http://github.com/jrburke/requirejs for details */ @@ -12,7 +12,7 @@ var requirejs, require, define; (function (global) { var req, s, head, baseElement, dataMain, src, interactiveScript, currentlyAddingScript, mainScript, subPath, - version = '2.0.5', + version = '2.0.6', commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg, cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g, jsSuffixRegExp = /\.js$/, @@ -612,7 +612,7 @@ var requirejs, require, define; }); } - function findCycle(mod, traced) { + function findCycle(mod, traced, processed) { var id = mod.map.id, depArray = mod.depMaps, foundModule; @@ -635,28 +635,16 @@ var requirejs, require, define; var depId = depMap.id, depMod = registry[depId]; - if (!depMod) { + if (!depMod || processed[depId] || + !depMod.inited || !depMod.enabled) { return; } - if (!depMod.inited || !depMod.enabled) { - //Dependency is not inited, so this cannot - //be used to determine a cycle. - foundModule = null; - delete traced[id]; - return true; - } - - //mixin traced to a new object for each dependency, so that - //sibling dependencies in this object to not generate a - //false positive match on a cycle. Ideally an Object.create - //type of prototype delegation would be used here, but - //optimizing for file size vs. execution speed since hopefully - //the trees are small for circular dependency scans relative - //to the full app perf. - return (foundModule = findCycle(depMod, mixin({}, traced))); + return (foundModule = findCycle(depMod, traced, processed)); }); + processed[id] = true; + return foundModule; } @@ -779,7 +767,7 @@ var requirejs, require, define; return; } - var cycleMod = findCycle(mod, {}), + var cycleMod = findCycle(mod, {}, {}), traced = {}; if (cycleMod) { diff --git a/vendor/underscore/underscore-min.js b/vendor/underscore/underscore-min.js index f2ca264ba..96e96dc89 100644 --- a/vendor/underscore/underscore-min.js +++ b/vendor/underscore/underscore-min.js @@ -1,6 +1,6 @@ // Underscore.js 1.3.3 // (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. -// Underscore is freely distributable under the MIT license. +// Underscore may be freely distributed under the MIT license. // Portions of Underscore are inspired or borrowed from Prototype, // Oliver Steele's Functional, and John Resig's Micro-Templating. // For all details and documentation: @@ -12,16 +12,16 @@ a;return true}});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(F&&a.some===F)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return p});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(r&&a.indexOf===r)return a.indexOf(c)!=-1;return b=H(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c:a[c]).apply(a,d)})};b.pluck=function(a,c){return b.map(a,function(a){return a[c]})}; b.max=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;bd?1:0}),"value")};var I=function(a,c){return b.isFunction(c)?c:function(a){return a[c]}},J=function(a,c,b){var e={},f=I(a,c);j(a,function(a,c){var i=f(a,c);b(e, -i,a)});return e};b.groupBy=function(a,c){return J(a,c,function(a,c,b){(a[c]||(a[c]=[])).push(b)})};b.countBy=function(a,c){return J(a,c,function(a,c){a[c]||(a[c]=0);a[c]++})};b.sortedIndex=function(a,c,d){d||(d=b.identity);for(var c=d(c),e=0,f=a.length;e>1;d(a[g])=0})})};b.difference=function(a){var c=n(i.call(arguments, -1),true,[]);return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=P||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a, -d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.pick=function(a){var b={};j(n(i.call(arguments,1),true,[]),function(d){d in a&&(b[d]=a[d])});return b};b.defaults=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)? -a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};var u=function(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=m.call(a);if(e!=m.call(c))return false;switch(e){case "[object String]":return a==""+c;case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a== +i,a)});return e};b.groupBy=function(a,c){return J(a,c,function(a,c,b){(a[c]||(a[c]=[])).push(b)})};b.countBy=function(a,c){return J(a,c,function(a,c){a[c]||(a[c]=0);a[c]++})};b.sortedIndex=function(a,c,d){d||(d=b.identity);for(var c=d(c),e=0,f=a.length;e>1;d(a[g])=0})})};b.difference=function(a){var c=n(i.call(arguments,1),true,[]); +return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=P||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values= +function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.pick=function(a){var b={};j(n(i.call(arguments,1),true,[]),function(d){d in a&&(b[d]=a[d])});return b};b.defaults=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)? +a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};var u=function(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=m.call(a);if(e!=m.call(c))return false;switch(e){case "[object String]":return a==""+c;case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a== +c;case "[object RegExp]":return a.source==c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return true;d.push(a);var f=0,g=true;if(e=="[object Array]"){f=a.length;if(g=f==c.length)for(;f--;)if(!(g=f in a==f in c&&u(a[f],c[f],d)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(b.has(a,h)){f++;if(!(g=b.has(c,h)&& u(a[h],c[h],d)))break}if(g){for(h in c)if(b.has(c,h)&&!f--)break;g=!f}}d.pop();return g};b.isEqual=function(a,b){return u(a,b,[])};b.isEmpty=function(a){if(a==null)return true;if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=q||function(a){return m.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};j("Arguments,Function,String,Number,Date,RegExp".split(","),function(a){b["is"+ a]=function(b){return m.call(b)=="[object "+a+"]"}});b.isArguments(arguments)||(b.isArguments=function(a){return!(!a||!b.has(a,"callee"))});b.isFinite=function(a){return b.isNumber(a)&&isFinite(a)};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||m.call(a)=="[object Boolean]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return O.call(a,b)};b.noConflict=function(){s._=L;return this};b.identity=function(a){return a}; diff --git a/vendor/underscore/underscore.js b/vendor/underscore/underscore.js index 88141d168..00b2f3d1c 100644 --- a/vendor/underscore/underscore.js +++ b/vendor/underscore/underscore.js @@ -1,6 +1,6 @@ // Underscore.js 1.3.3 // (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. -// Underscore is freely distributable under the MIT license. +// Underscore may be freely distributed under the MIT license. // Portions of Underscore are inspired or borrowed from Prototype, // Oliver Steele's Functional, and John Resig's Micro-Templating. // For all details and documentation: @@ -330,10 +330,9 @@ // Safely convert anything iterable into a real, live array. _.toArray = function(obj) { - if (!obj) return []; - if (_.isArray(obj)) return slice.call(obj); - if (_.isArguments(obj)) return slice.call(obj); - if (obj.toArray && _.isFunction(obj.toArray)) return obj.toArray(); + if (!obj) return []; + if (_.isArray(obj) || _.isArguments(obj)) return slice.call(obj); + if (_.isFunction(obj.toArray)) return obj.toArray(); return _.values(obj); };