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

Commit

Permalink
Browse files Browse the repository at this point in the history
Use _.result instead of getValue where possible
  • Loading branch information
Ryan Eastridge committed Dec 31, 2012
1 parent cb9430e commit b1526bb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/collection.js
@@ -1,4 +1,4 @@
/*global createRegistryWrapper, dataObject, getEventCallback, getValue, modelCidAttributeName, viewCidAttributeName */
/*global createRegistryWrapper, dataObject, getEventCallback, modelCidAttributeName, viewCidAttributeName */
var _fetch = Backbone.Collection.prototype.fetch,
_reset = Backbone.Collection.prototype.reset,
collectionCidAttributeName = 'data-collection-cid',
Expand All @@ -17,7 +17,7 @@ Thorax.Collection = Backbone.Collection.extend({
}
},
isPopulated: function() {
return this._fetched || this.length > 0 || (!this.length && !getValue(this, 'url'));
return this._fetched || this.length > 0 || (!this.length && !_.result(this, 'url'));
},
fetch: function(options) {
options = options || {};
Expand Down
10 changes: 5 additions & 5 deletions src/data-object.js
@@ -1,4 +1,4 @@
/*global getValue, inheritVars, walkInheritTree */
/*global inheritVars, walkInheritTree */

function dataObject(type, spec) {
spec = inheritVars[type] = _.defaults({
Expand All @@ -19,7 +19,7 @@ function dataObject(type, spec) {

function setObject(dataObject, options) {
var old = this[type],
$el = getValue(this, spec.$el);
$el = _.result(this, spec.$el);

if (dataObject === old) {
return this;
Expand Down Expand Up @@ -149,9 +149,9 @@ Thorax.Util.shouldFetch = function(modelOrCollection, options) {

var isCollection = !modelOrCollection.collection && modelOrCollection._byCid && modelOrCollection._byId,
url = (
(!modelOrCollection.collection && getValue(modelOrCollection, 'urlRoot')) ||
(modelOrCollection.collection && getValue(modelOrCollection.collection, 'url')) ||
(isCollection && getValue(modelOrCollection, 'url'))
(!modelOrCollection.collection && _.result(modelOrCollection, 'urlRoot')) ||
(modelOrCollection.collection && _.result(modelOrCollection.collection, 'url')) ||
(isCollection && _.result(modelOrCollection, 'url'))
);

return url && !(
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/collection.js
Expand Up @@ -40,7 +40,7 @@ Thorax.CollectionHelperView = Thorax.View.extend({
},
// will be used by emptyView and emptyTemplate
_getContext: function(attributes) {
return _.extend({}, getValue(this.parent, 'context'), attributes || {});
return _.extend({}, _.result(this.parent, 'context'), attributes || {});
},
setAsPrimaryCollectionHelper: function(collection) {
this.$el.attr(primaryCollectionAttributeName, collection.cid);
Expand Down
4 changes: 2 additions & 2 deletions src/thorax.js
@@ -1,4 +1,4 @@
/*global cloneInheritVars, createInheritVars, createRegistryWrapper, getValue, inheritVars */
/*global cloneInheritVars, createInheritVars, createRegistryWrapper, inheritVars */

//support zepto.forEach on jQuery
if (!$.fn.forEach) {
Expand Down Expand Up @@ -147,7 +147,7 @@ Thorax.View = Backbone.View.extend({
},

_getContext: function(attributes) {
return _.extend({}, getValue(this, 'context'), attributes || {});
return _.extend({}, _.result(this, 'context'), attributes || {});
},

// Private variables in handlebars / options.data in template helpers
Expand Down

3 comments on commit b1526bb

@kpdecker
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is getValue still used? Can we simplify the implementation of that now?

@eastridge
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

walkInheritTree, but can't figure out how to simplify it =P

@kpdecker
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually thinking about it I wonder if it is better to revert this if we can't kill it all off. Basically getValue can be minimized and has to stick around for that one case so maybe it should be there for all of them.

Please sign in to comment.