Comparing version 1.0.0 to 1.1.0
143
backbone.js
@@ -1,2 +0,2 @@ | ||
// Backbone.js 1.0.0 | ||
// Backbone.js 1.1.0 | ||
@@ -38,3 +38,3 @@ // (c) 2010-2011 Jeremy Ashkenas, DocumentCloud Inc. | ||
// Current version of the library. Keep in sync with `package.json`. | ||
Backbone.VERSION = '1.0.0'; | ||
Backbone.VERSION = '1.1.0'; | ||
@@ -116,3 +116,2 @@ // Require Underscore, if we're on the server, and it's not already present. | ||
} | ||
names = name ? [name] : _.keys(this._events); | ||
@@ -157,10 +156,11 @@ for (i = 0, l = names.length; i < l; i++) { | ||
stopListening: function(obj, name, callback) { | ||
var listeners = this._listeners; | ||
if (!listeners) return this; | ||
var deleteListener = !name && !callback; | ||
if (typeof name === 'object') callback = this; | ||
if (obj) (listeners = {})[obj._listenerId] = obj; | ||
for (var id in listeners) { | ||
listeners[id].off(name, callback, this); | ||
if (deleteListener) delete this._listeners[id]; | ||
var listeningTo = this._listeningTo; | ||
if (!listeningTo) return this; | ||
var remove = !name && !callback; | ||
if (!callback && typeof name === 'object') callback = this; | ||
if (obj) (listeningTo = {})[obj._listenId] = obj; | ||
for (var id in listeningTo) { | ||
obj = listeningTo[id]; | ||
obj.off(name, callback, this); | ||
if (remove || _.isEmpty(obj._events)) delete this._listeningTo[id]; | ||
} | ||
@@ -222,6 +222,6 @@ return this; | ||
Events[method] = function(obj, name, callback) { | ||
var listeners = this._listeners || (this._listeners = {}); | ||
var id = obj._listenerId || (obj._listenerId = _.uniqueId('l')); | ||
listeners[id] = obj; | ||
if (typeof name === 'object') callback = this; | ||
var listeningTo = this._listeningTo || (this._listeningTo = {}); | ||
var id = obj._listenId || (obj._listenId = _.uniqueId('l')); | ||
listeningTo[id] = obj; | ||
if (!callback && typeof name === 'object') callback = this; | ||
obj[implementation](name, callback, this); | ||
@@ -251,3 +251,2 @@ return this; | ||
var Model = Backbone.Model = function(attributes, options) { | ||
var defaults; | ||
var attrs = attributes || {}; | ||
@@ -259,6 +258,3 @@ options || (options = {}); | ||
if (options.parse) attrs = this.parse(attrs, options) || {}; | ||
options._attrs || (options._attrs = attrs); | ||
if (defaults = _.result(this, 'defaults')) { | ||
attrs = _.defaults({}, attrs, defaults); | ||
} | ||
attrs = _.defaults({}, attrs, _.result(this, 'defaults')); | ||
this.set(attrs, options); | ||
@@ -647,7 +643,8 @@ this.changed = {}; | ||
remove: function(models, options) { | ||
models = _.isArray(models) ? models.slice() : [models]; | ||
var singular = !_.isArray(models); | ||
models = singular ? [models] : _.clone(models); | ||
options || (options = {}); | ||
var i, l, index, model; | ||
for (i = 0, l = models.length; i < l; i++) { | ||
model = this.get(models[i]); | ||
model = models[i] = this.get(models[i]); | ||
if (!model) continue; | ||
@@ -665,3 +662,3 @@ delete this._byId[model.id]; | ||
} | ||
return this; | ||
return singular ? models[0] : models; | ||
}, | ||
@@ -676,5 +673,7 @@ | ||
if (options.parse) models = this.parse(models, options); | ||
if (!_.isArray(models)) models = models ? [models] : []; | ||
var i, l, model, attrs, existing, sort; | ||
var singular = !_.isArray(models); | ||
models = singular ? (models ? [models] : []) : _.clone(models); | ||
var i, l, id, model, attrs, existing, sort; | ||
var at = options.at; | ||
var targetModel = this.model; | ||
var sortable = this.comparator && (at == null) && options.sort !== false; | ||
@@ -689,16 +688,25 @@ var sortAttr = _.isString(this.comparator) ? this.comparator : null; | ||
for (i = 0, l = models.length; i < l; i++) { | ||
if (!(model = this._prepareModel(attrs = models[i], options))) continue; | ||
attrs = models[i]; | ||
if (attrs instanceof Model) { | ||
id = model = attrs; | ||
} else { | ||
id = attrs[targetModel.prototype.idAttribute]; | ||
} | ||
// If a duplicate is found, prevent it from being added and | ||
// optionally merge it into the existing model. | ||
if (existing = this.get(model)) { | ||
if (existing = this.get(id)) { | ||
if (remove) modelMap[existing.cid] = true; | ||
if (merge) { | ||
attrs = attrs === model ? model.attributes : options._attrs; | ||
attrs = attrs === model ? model.attributes : attrs; | ||
if (options.parse) attrs = existing.parse(attrs, options); | ||
existing.set(attrs, options); | ||
if (sortable && !sort && existing.hasChanged(sortAttr)) sort = true; | ||
} | ||
models[i] = existing; | ||
// This is a new model, push it to the `toAdd` list. | ||
// If this is a new, valid model, push it to the `toAdd` list. | ||
} else if (add) { | ||
model = models[i] = this._prepareModel(attrs, options); | ||
if (!model) continue; | ||
toAdd.push(model); | ||
@@ -713,3 +721,2 @@ | ||
if (order) order.push(existing || model); | ||
delete options._attrs; | ||
} | ||
@@ -730,6 +737,11 @@ | ||
if (at != null) { | ||
splice.apply(this.models, [at, 0].concat(toAdd)); | ||
for (i = 0, l = toAdd.length; i < l; i++) { | ||
this.models.splice(at + i, 0, toAdd[i]); | ||
} | ||
} else { | ||
if (order) this.models.length = 0; | ||
push.apply(this.models, order || toAdd); | ||
var orderedModels = order || toAdd; | ||
for (i = 0, l = orderedModels.length; i < l; i++) { | ||
this.models.push(orderedModels[i]); | ||
} | ||
} | ||
@@ -741,12 +753,12 @@ } | ||
if (options.silent) return this; | ||
// Trigger `add` events. | ||
for (i = 0, l = toAdd.length; i < l; i++) { | ||
(model = toAdd[i]).trigger('add', model, this, options); | ||
// Unless silenced, it's time to fire all appropriate add/sort events. | ||
if (!options.silent) { | ||
for (i = 0, l = toAdd.length; i < l; i++) { | ||
(model = toAdd[i]).trigger('add', model, this, options); | ||
} | ||
if (sort || (order && order.length)) this.trigger('sort', this, options); | ||
} | ||
// Trigger `sort` if the collection was sorted. | ||
if (sort || (order && order.length)) this.trigger('sort', this, options); | ||
return this; | ||
// Return the added (or merged) model (or models). | ||
return singular ? models[0] : models; | ||
}, | ||
@@ -765,5 +777,5 @@ | ||
this._reset(); | ||
this.add(models, _.extend({silent: true}, options)); | ||
models = this.add(models, _.extend({silent: true}, options)); | ||
if (!options.silent) this.trigger('reset', this, options); | ||
return this; | ||
return models; | ||
}, | ||
@@ -773,5 +785,3 @@ | ||
push: function(model, options) { | ||
model = this._prepareModel(model, options); | ||
this.add(model, _.extend({at: this.length}, options)); | ||
return model; | ||
return this.add(model, _.extend({at: this.length}, options)); | ||
}, | ||
@@ -788,5 +798,3 @@ | ||
unshift: function(model, options) { | ||
model = this._prepareModel(model, options); | ||
this.add(model, _.extend({at: 0}, options)); | ||
return model; | ||
return this.add(model, _.extend({at: 0}, options)); | ||
}, | ||
@@ -853,12 +861,2 @@ | ||
// Figure out the smallest index at which a model should be inserted so as | ||
// to maintain order. | ||
sortedIndex: function(model, value, context) { | ||
value || (value = this.comparator); | ||
var iterator = _.isFunction(value) ? value : function(model) { | ||
return model.get(value); | ||
}; | ||
return _.sortedIndex(this.models, model, iterator, context); | ||
}, | ||
// Pluck an attribute from each model in the collection. | ||
@@ -930,7 +928,7 @@ pluck: function(attr) { | ||
} | ||
options || (options = {}); | ||
options = options ? _.clone(options) : {}; | ||
options.collection = this; | ||
var model = new this.model(attrs, options); | ||
if (!model.validationError) return model; | ||
this.trigger('invalid', this, attrs, options); | ||
this.trigger('invalid', this, model.validationError, options); | ||
return false; | ||
@@ -1004,6 +1002,2 @@ }, | ||
// Options with special meaning *(e.g. model, collection, id, className)* are | ||
// attached directly to the view. See `viewOptions` for an exhaustive | ||
// list. | ||
// Creating a Backbone.View creates its initial element outside of the DOM, | ||
@@ -1348,2 +1342,5 @@ // if an existing element is not provided... | ||
// Cached regex for stripping urls of hash and query. | ||
var pathStripper = /[?#].*$/; | ||
// Has the history handling already been started? | ||
@@ -1389,3 +1386,3 @@ History.started = false; | ||
// Is pushState desired ... is it available? | ||
this.options = _.extend({}, {root: '/'}, this.options, options); | ||
this.options = _.extend({root: '/'}, this.options, options); | ||
this.root = this.options.root; | ||
@@ -1476,4 +1473,4 @@ this._wantsHashChange = this.options.hashChange !== false; | ||
// returns `false`. | ||
loadUrl: function(fragmentOverride) { | ||
var fragment = this.fragment = this.getFragment(fragmentOverride); | ||
loadUrl: function(fragment) { | ||
fragment = this.fragment = this.getFragment(fragment); | ||
return _.any(this.handlers, function(handler) { | ||
@@ -1498,8 +1495,10 @@ if (handler.route.test(fragment)) { | ||
fragment = this.getFragment(fragment || ''); | ||
var url = this.root + (fragment = this.getFragment(fragment || '')); | ||
// Strip the fragment of the query and hash for matching. | ||
fragment = fragment.replace(pathStripper, ''); | ||
if (this.fragment === fragment) return; | ||
this.fragment = fragment; | ||
var url = this.root + fragment; | ||
// Don't include a trailing slash on the root. | ||
@@ -1605,2 +1604,2 @@ if (fragment === '' && url !== '/') url = url.slice(0, -1); | ||
}).call(this); | ||
}).call(this); |
@@ -16,6 +16,9 @@ { | ||
"scripts": { | ||
"test": "phantomjs test/vendor/runner.js test/index.html?noglobals=true && coffee test/model.coffee" | ||
"test": "phantomjs test/vendor/runner.js test/index.html?noglobals=true && coffee test/model.coffee", | ||
"build": "uglifyjs backbone.js --mangle --source-map backbone-min.map -o backbone-min.js", | ||
"doc": "docco backbone.js && docco examples/todos/todos.js examples/backbone.localstorage.js", | ||
"lint": "jsl -nofilelisting -nologo -conf docs/jsl.conf -process backbone.js" | ||
}, | ||
"main" : "backbone.js", | ||
"version" : "1.0.0", | ||
"version" : "1.1.0", | ||
"license" : "MIT", | ||
@@ -22,0 +25,0 @@ "repository": { |
@@ -18,3 +18,3 @@ backdash | ||
[Line 42](https://github.com/jashkenas/backbone/blob/master/backbone.js#L42) changed from: | ||
[Line 42](https://github.com/jashkenas/backbone/blob/1.1.0/backbone.js#L42) changed from: | ||
@@ -48,3 +48,3 @@ ```javascript | ||
This version of backdash is based on Backbone 1.0.0 and Lodash 1.3.1 | ||
This version of backdash is based on Backbone 1.1.0 and Lodash 1.3.1 | ||
@@ -51,0 +51,0 @@ Use those versions explicitly in any other module that will build into the target project. Multiple versions of lodash in the dependency tree will cause multiple versions to appear in the built browserify bundle. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
74507
12
1377