Skip to content

Commit

Permalink
Take on-board some JSLint suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
benpickles committed Mar 29, 2010
1 parent 578d0c1 commit d07dc89
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 27 deletions.
10 changes: 5 additions & 5 deletions src/model_collection_methods.js
Expand Up @@ -5,14 +5,14 @@ Model.CollectionMethods = {
for (var i = 0; i < arguments.length; i++) {
var model = arguments[i];
var existing_elem = this.detect(function() {
return this.id() != null && this.id() == model.id();
return this.id() !== null && this.id() == model.id();
});

if (!existing_elem) {
this.collection.push(model);
added.push(model);
}
};
}

if (added.length > 0) this.trigger("add", added);

Expand Down Expand Up @@ -75,7 +75,7 @@ Model.CollectionMethods = {
return true;
} else {
return false;
};
}
},

select: function(func) {
Expand All @@ -99,8 +99,8 @@ Model.CollectionMethods = {
if (callbacks) {
for (var i = 0; i < callbacks.length; i++) {
callbacks[i].apply(this, data || []);
};
};
}
}

return this;
}
Expand Down
4 changes: 1 addition & 3 deletions src/model_errors.js
Expand Up @@ -18,8 +18,6 @@ Model.Errors.prototype = {
},

each: function(func) {
var self = this;

for (var attribute in this.errors) {
for (var i = 0; i < this.errors[attribute].length; i++) {
func.call(this, attribute, this.errors[attribute][i]);
Expand All @@ -36,4 +34,4 @@ Model.Errors.prototype = {
this.each(function() { count++; });
return count;
}
}
};
30 changes: 15 additions & 15 deletions src/model_instance_methods.js
@@ -1,29 +1,29 @@
Model.InstanceMethods = {
attr: function(name, value) {
if (arguments.length == 0) {
if (arguments.length === 0) {
// Combined attributes/changes object.
return jQuery.extend({}, this.attributes, this.changes);
} else if (arguments.length == 2) {
} else if (arguments.length === 2) {
// Don't write to attributes yet, store in changes for now.
if (_.isEqual(this.attributes[name], value)) {
// Clean up any stale changes.
delete this.changes[name];
} else {
this.changes[name] = value;
};
}
return this;
} else if (typeof name == "object") {
} else if (typeof name === "object") {
// Mass-assign attributes.
for (var key in name) {
this.attr(key, name[key]);
};
}
return this;
} else {
// Changes take precedent over attributes.
return (name in this.changes) ?
this.changes[name] :
this.attributes[name];
};
}
},

bind: function(event, callback) {
Expand All @@ -37,11 +37,11 @@ Model.InstanceMethods = {

// Automatically manage adding and removing from the model's Collection.
var manageCollection = function() {
if (method == "create") {
if (method === "create") {
self.constructor.add(self);
} else if (method == "destroy") {
} else if (method === "destroy") {
self.constructor.remove(self.id());
};
}
};

// Wrap the existing callback in this function so we always manage the
Expand All @@ -60,7 +60,7 @@ Model.InstanceMethods = {

// Trigger the event before executing the callback.
self.trigger(method);
};
}

// Store the return value of the callback.
var value;
Expand All @@ -75,7 +75,7 @@ Model.InstanceMethods = {
this.constructor.persistence[method](this, wrappedCallback);
} else {
wrappedCallback.call(this, true);
};
}
},

destroy: function(callback) {
Expand All @@ -93,7 +93,7 @@ Model.InstanceMethods = {
},

newRecord: function() {
return this.id() == null;
return this.id() === null;
},

reset: function() {
Expand All @@ -119,8 +119,8 @@ Model.InstanceMethods = {
if (callbacks) {
for (var i = 0; i < callbacks.length; i++) {
callbacks[i].apply(this, data || []);
};
};
}
}

return this;
},
Expand All @@ -133,7 +133,7 @@ Model.InstanceMethods = {
valid: function() {
this.errors.clear();
this.validate();
return this.errors.size() == 0;
return this.errors.size() === 0;
},

validate: function() {
Expand Down
8 changes: 4 additions & 4 deletions src/model_rest_persistence.js
Expand Up @@ -38,7 +38,7 @@ Model.RestPersistence = function(resource, methods) {
return jQuery.parseJSON(xhr.responseText);
} catch(e) {
Model.Log(e);
};
}
},

update: function(model, callback) {
Expand All @@ -51,7 +51,7 @@ Model.RestPersistence = function(resource, methods) {

xhr: function(method, url, model, callback) {
var self = this;
var data = method == "DELETE" ? null : this.params(model);
var data = method === "DELETE" ? null : this.params(model);

return jQuery.ajax({
type: method,
Expand All @@ -66,13 +66,13 @@ Model.RestPersistence = function(resource, methods) {

xhrComplete: function(xhr, textStatus, model, callback) {
var data = this.parseResponseData(xhr);
var success = textStatus == "success";
var success = textStatus === "success";

if (data) {
if (success) {
// Remote data is the definitive source, update model.
model.attr(data);
} else if (xhr.status == 422) {
} else if (xhr.status === 422) {
// Rails' preferred failed validation response code, assume these
// are errors and replace current model errors with them.
model.errors.clear();
Expand Down

0 comments on commit d07dc89

Please sign in to comment.