Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Optimize CollectionBinder::getManagerForModel to use keyed values already stored internally.

defaultBindings was generating a js error; this did not cause any test cases to fail because it occurred after test cases completed. However, since the checkboxes return boolean values, there is no .replace value available; corrected.
  • Loading branch information
katowulf committed Apr 28, 2013
1 parent 5432d50 commit 129be43
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
12 changes: 1 addition & 11 deletions Backbone.CollectionBinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,7 @@
},

getManagerForModel: function(model){
var i, elManager, elManagers = _.values(this._elManagers);

for(i = 0; i < elManagers.length; i++){
elManager = elManagers[i];

if(elManager.getModel() === model){
return elManager;
}
}

return undefined;
return this._elManagers[_.isObject(model)? model.cid : model];
},

_onCollectionAdd: function(model){
Expand Down
6 changes: 3 additions & 3 deletions spec/javascripts/defaultBindings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ describe('default bindings', function(){
});

it('converter bindings', function(){
var defaultConverter = function(direction, value){
var defaultConverter = function(direction, value, key){
if(direction === Backbone.ModelBinder.Constants.ModelToView){
return 'XXX' + value;
return key === 'isActive'? value : 'XXX' + value;
}
else {
return value.replace('XXX');

This comment has been minimized.

Copy link
@katowulf

katowulf Apr 29, 2013

Author Owner

value.replace doesn't work with booleans; probably never did; it didn't fire until after the test unit was resolved so it never got caught

return _.isString(value)? value.replace('XXX') : value;
}
};

Expand Down

0 comments on commit 129be43

Please sign in to comment.