Permalink
Browse files

Fixes theironcook/Backbone.ModelBinder#131

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...
1 parent 5432d50 commit 129be43c9761b008d60ad4a69fa519d3bc3899d9 @katowulf katowulf committed Apr 28, 2013
Showing with 4 additions and 14 deletions.
  1. +1 −11 Backbone.CollectionBinder.js
  2. +3 −3 spec/javascripts/defaultBindings.spec.js
@@ -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){
@@ -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');
+ return _.isString(value)? value.replace('XXX') : value;
}
};

0 comments on commit 129be43

Please sign in to comment.