Comparing changes
Open a pull request
- 15 commits
- 11 files changed
- 7 commit comments
- 3 contributors
|
|
jashkenas |
7e363df
|
|
|
jashkenas |
99fbc08
|
|||
|
|
jashkenas |
11dcf24
|
|
|
samuelclay |
52c460b
|
|
|
jashkenas |
327ba8c
|
|||
|
|
jashkenas |
f63c995
|
|
|
jashkenas |
70e6cd6
|
|||
|
|
jashkenas |
d574c9f
|
|||
|
|
jashkenas |
f3e961d
|
|||
|
|
jashkenas |
a969d67
|
|||
|
|
jashkenas |
94c77e8
|
|||
|
|
jashkenas |
9e1fcfa
|
|
|
mkelly12 |
57194be
|
|||
|
|
jashkenas |
33232f5
|
|||
|
|
jashkenas |
356664a
|
- +23 −22 backbone-min.js
- +35 −17 backbone.js
- +106 −100 docs/backbone.html
- +4 −4 docs/docco.css
- BIN docs/images/backbone-mobile.png
- BIN docs/images/dc-workspace.png
- +1 −1 docs/jsl.conf
- +74 −5 index.html
- +1 −1 package.json
- +41 −17 test/collection.js
- +23 −0 test/model.js
| @@ -1,4 +1,4 @@ | ||
| -// Backbone.js 0.3.1 | ||
| +// Backbone.js 0.3.2 | ||
| // (c) 2010 Jeremy Ashkenas, DocumentCloud Inc. | ||
| // Backbone may be freely distributed under the MIT license. | ||
| // For all details and documentation: | ||
| @@ -19,7 +19,7 @@ | ||
| } | ||
| // Current version of the library. Keep in sync with `package.json`. | ||
| - Backbone.VERSION = '0.3.1'; | ||
| + Backbone.VERSION = '0.3.2'; | ||
| // Require Underscore, if we're on the server, and it's not already present. | ||
| var _ = this._; | ||
| @@ -113,12 +113,14 @@ | ||
| // Create a new model, with defined attributes. A client id (`cid`) | ||
| // is automatically generated and assigned for you. | ||
| Backbone.Model = function(attributes, options) { | ||
| + attributes || (attributes = {}); | ||
| + if (this.defaults) attributes = _.extend({}, this.defaults, attributes); | ||
| this.attributes = {}; | ||
| this.cid = _.uniqueId('c'); | ||
| - this.set(attributes || {}, {silent : true}); | ||
| + this.set(attributes, {silent : true}); | ||
| this._previousAttributes = _.clone(this.attributes); | ||
| if (options && options.collection) this.collection = options.collection; | ||
| - if (this.initialize) this.initialize(attributes, options); | ||
| + this.initialize(attributes, options); | ||
| }; | ||
| // Attach all inheritable methods to the Model prototype. | ||
| @@ -131,6 +133,10 @@ | ||
| // Has the item been changed since the last `"change"` event? | ||
| _changed : false, | ||
| + // Initialize is an empty function by default. Override it with your own | ||
| + // initialization logic. | ||
| + initialize : function(){}, | ||
| + | ||
| // Return a copy of the model's `attributes` object. | ||
| toJSON : function() { | ||
| return _.clone(this.attributes); | ||
| @@ -228,25 +234,24 @@ | ||
| if (options.success) options.success(model, resp); | ||
| }; | ||
| var error = options.error && _.bind(options.error, null, model); | ||
| - Backbone.sync('read', this, success, error); | ||
| + (this.sync || Backbone.sync)('read', this, success, error); | ||
| return this; | ||
| }, | ||
| // Set a hash of model attributes, and sync the model to the server. | ||
| // If the server returns an attributes hash that differs, the model's | ||
| // state will be `set` again. | ||
| save : function(attrs, options) { | ||
| - attrs || (attrs = {}); | ||
| options || (options = {}); | ||
| - if (!this.set(attrs, options)) return false; | ||
| + if (attrs && !this.set(attrs, options)) return false; | ||
| var model = this; | ||
| var success = function(resp) { | ||
| if (!model.set(model.parse(resp), options)) return false; | ||
| if (options.success) options.success(model, resp); | ||
| }; | ||
| var error = options.error && _.bind(options.error, null, model); | ||
| var method = this.isNew() ? 'create' : 'update'; | ||
| - Backbone.sync(method, this, success, error); | ||
| + (this.sync || Backbone.sync)(method, this, success, error); | ||
| return this; | ||
| }, | ||
| @@ -260,7 +265,7 @@ | ||
| if (options.success) options.success(model, resp); | ||
| }; | ||
| var error = options.error && _.bind(options.error, null, model); | ||
| - Backbone.sync('delete', this, success, error); | ||
| + (this.sync || Backbone.sync)('delete', this, success, error); | ||
| return this; | ||
| }, | ||
| @@ -270,7 +275,7 @@ | ||
| url : function() { | ||
| var base = getUrl(this.collection); | ||
| if (this.isNew()) return base; | ||
| - return base + '/' + this.id; | ||
| + return base + (base.charAt(base.length - 1) == '/' ? '' : '/') + this.id; | ||
| }, | ||
| // **parse** converts a response into the hash of attributes to be `set` on | ||
| @@ -368,7 +373,7 @@ | ||
| this._boundOnModelEvent = _.bind(this._onModelEvent, this); | ||
| this._reset(); | ||
| if (models) this.refresh(models, {silent: true}); | ||
| - if (this.initialize) this.initialize(models, options); | ||
| + this.initialize(models, options); | ||
| }; | ||
| // Define the Collection's inheritable methods. | ||
| @@ -378,6 +383,10 @@ | ||
| // This should be overridden in most cases. | ||
| model : Backbone.Model, | ||
| + // Initialize is an empty function by default. Override it with your own | ||
| + // initialization logic. | ||
| + initialize : function(){}, | ||
| + | ||
| // The JSON representation of a Collection is an array of the | ||
| // models' attributes. | ||
| toJSON : function() { | ||
| @@ -412,7 +421,8 @@ | ||
| // Get a model from the set by id. | ||
| get : function(id) { | ||
| - return id && this._byId[id.id != null ? id.id : id]; | ||
| + if (id == null) return null; | ||
| + return this._byId[id.id != null ? id.id : id]; | ||
| }, | ||
| // Get a model from the set by client id. | ||
| @@ -462,7 +472,7 @@ | ||
| if (options.success) options.success(collection, resp); | ||
| }; | ||
| var error = options.error && _.bind(options.error, null, collection); | ||
| - Backbone.sync('read', this, success, error); | ||
| + (this.sync || Backbone.sync)('read', this, success, error); | ||
| return this; | ||
| }, | ||
| @@ -528,7 +538,7 @@ | ||
| // hash indexes for `id` and `cid` lookups. | ||
| _remove : function(model, options) { | ||
| options || (options = {}); | ||
| - model = this.getByCid(model); | ||
| + model = this.getByCid(model) || this.get(model); | ||
| if (!model) return null; | ||
| delete this._byId[model.id]; | ||
| delete this._byCid[model.cid]; | ||
| @@ -575,7 +585,7 @@ | ||
| options || (options = {}); | ||
| if (options.routes) this.routes = options.routes; | ||
| this._bindRoutes(); | ||
| - if (this.initialize) this.initialize(options); | ||
| + this.initialize(options); | ||
| }; | ||
| // Cached regular expressions for matching named param parts and splatted | ||
| @@ -586,6 +596,10 @@ | ||
| // Set up all inheritable **Backbone.Controller** properties and methods. | ||
| _.extend(Backbone.Controller.prototype, Backbone.Events, { | ||
| + // Initialize is an empty function by default. Override it with your own | ||
| + // initialization logic. | ||
| + initialize : function(){}, | ||
| + | ||
| // Manually bind a single named route to a callback. For example: | ||
| // | ||
| // this.route('search/:query/p:num', 'search', function(query, num) { | ||
| @@ -662,7 +676,7 @@ | ||
| // an existing route, and `false` otherwise. | ||
| start : function() { | ||
| var docMode = document.documentMode; | ||
| - var oldIE = ($.browser.msie && docMode < 7); | ||
| + var oldIE = ($.browser.msie && (!docMode || docMode <= 7)); | ||
| if (oldIE) { | ||
| this.iframe = $('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo('body')[0].contentWindow; | ||
| } | ||
| @@ -733,7 +747,7 @@ | ||
| this._configure(options || {}); | ||
| this._ensureElement(); | ||
| this.delegateEvents(); | ||
| - if (this.initialize) this.initialize(options); | ||
| + this.initialize(options); | ||
| }; | ||
| // jQuery lookup, scoped to DOM elements within the current view. | ||
| @@ -756,6 +770,10 @@ | ||
| $ : jQueryDelegate, | ||
| jQuery : jQueryDelegate, | ||
| + // Initialize is an empty function by default. Override it with your own | ||
| + // initialization logic. | ||
| + initialize : function(){}, | ||
| + | ||
| // **render** is the core function that your view should override, in order | ||
| // to populate its element (`this.el`), with the appropriate HTML. The | ||
| // convention is for **render** to always return `this`. | ||
Showing you all comments on commits in this comparison.
|
This commit seems to cause other scenarios to regress. Specifically, because Examples here: https://gist.github.com/813138 On further inspection of |
|
I just went through blame to comment on this style. For readability, you could do if (!attributes) {
attributes = {};
}and both Closure Compiler and UglifyJS will compile it to attributes||(attributes={}); |