Commit f5708865 by Иван Кубота

Fix Store bug: function subscribed to multiple bind values was called with…

Fix Store bug: function subscribed to multiple bind values was called with incorrect arguments. Added test case for it.
parent 43a6cfe2
...@@ -360,23 +360,30 @@ Store.prototype = { ...@@ -360,23 +360,30 @@ Store.prototype = {
}; };
}; };
var uns = []; var uns = [], keyI;
for( var i = 0, _i = key.length; i < _i; i++ ){ for( var i = 0, _i = key.length; i < _i; i++ ){
if(key[i] instanceof StoreBinding){ keyI = key[i];
if(keyI instanceof StoreBinding){
args[i] = keyI.get();
}else if(keyI instanceof HookPrototype){
args[i] = keyI.get();
}else{
args[i] = this.get(keyI);
}
}
for( i = 0; i < _i; i++ ){
keyI = key[i];
if(keyI instanceof StoreBinding){
// TODO add suppressFirstCall // TODO add suppressFirstCall
uns.push(key[i].sub(wrap(i))); uns.push(keyI.sub(wrap(i)));
args[i] = key[i].get(); }else if(keyI instanceof HookPrototype){
}else if(key[i] instanceof HookPrototype){ uns.push(keyI.hook(wrap(i), suppressFirstCall));
uns.push(key[i].hook(wrap(i), suppressFirstCall));
args[i] = key[i].get();
}else{ }else{
uns.push(this.on( key[ i ], wrap(i) )); uns.push(this.on( keyI, wrap(i) ));
args[i] = this.get(key[ i ]);
} }
} }
!suppressFirstCall && caller(); !suppressFirstCall && caller();
return function() { return function() {
for( var i = 0, _i = uns.length; i < _i; i++ ){ for( var i = 0, _i = uns.length; i < _i; i++ ){
......
...@@ -357,3 +357,16 @@ describe('array events', function() { ...@@ -357,3 +357,16 @@ describe('array events', function() {
assert.equal(changeFiredInner, 1); assert.equal(changeFiredInner, 1);
}); });
}); });
describe('Bug with subscribing to multiple bindings', function() {
it('should call fn with both values setted', function(){
const s = new Store( { a: '1', b: '2' } ),
bind1 = s.bind( 'a' ),
bind2 = s.bind( 'b' );
s.sub( [ bind1, bind2 ], function( a, b ){
assert.equal( a, '1' );
assert.equal( b, '2' );
} );
});
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment