Skip to content
This repository has been archived by the owner on Mar 20, 2021. It is now read-only.

Commit

Permalink
Use getValue instead of _.result, remove extra args from getValue
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Eastridge committed Jan 3, 2013
1 parent e4a3868 commit 9624f73
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/collection.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Thorax.Collection = Backbone.Collection.extend({
return this._fetched || this.length > 0 || (!this.length && !getValue(this, 'url')); return this._fetched || this.length > 0 || (!this.length && !getValue(this, 'url'));
}, },
shouldFetch: function(options) { shouldFetch: function(options) {
return options.fetch && !!_.result(this, 'url') && !this.isPopulated(); return options.fetch && !!getValue(this, 'url') && !this.isPopulated();
}, },
fetch: function(options) { fetch: function(options) {
options = options || {}; options = options || {};
Expand Down
5 changes: 4 additions & 1 deletion src/util.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ function registryGet(object, type, name, ignoreErrors) {
} }
} }


// getValue is used instead of _.result because we
// need an extra scope parameter, and will minify
// better than _.result
function getValue(object, prop, scope) { function getValue(object, prop, scope) {
if (!(object && object[prop])) { if (!(object && object[prop])) {
return null; return null;
} }
return _.isFunction(object[prop]) return _.isFunction(object[prop])
? object[prop].apply(scope || object, Array.prototype.slice.call(arguments, 2)) ? object[prop].call(scope || object)
: object[prop]; : object[prop];
} }


Expand Down

0 comments on commit 9624f73

Please sign in to comment.