Commit 3b2575a3 by Иван Кубота

Store Feature: Binding.valEqual +test

parent 3a185893
...@@ -678,6 +678,19 @@ HookPrototype.prototype = { ...@@ -678,6 +678,19 @@ HookPrototype.prototype = {
for( var i = 0, _i = subscribers.length; i < _i; i++ ){ for( var i = 0, _i = subscribers.length; i < _i; i++ ){
subscribers[ i ](val); subscribers[ i ](val);
} }
},
valEqual: function(compareTo) {
var me = this;
return function backwardCallback(update) {
var cache;
me.hook(function(val) {
var result = me.equal(val, compareTo);
if(result !== cache){
cache = result;
update(cache);
}
});
}
} }
}; };
var HookFactory = function(accessor, baseObjectCtor) { var HookFactory = function(accessor, baseObjectCtor) {
......
...@@ -369,4 +369,66 @@ describe('Bug with subscribing to multiple bindings', function() { ...@@ -369,4 +369,66 @@ describe('Bug with subscribing to multiple bindings', function() {
assert.equal( b, '2' ); assert.equal( b, '2' );
} ); } );
}); });
});
describe('Feature. Binding.valEqual', function() {
it('Should trigger fn when value is changed', function() {
var str = new Store.Value.String('123');
var changes = [];
str.valEqual('16')(changes.push.bind(changes));
//false +init
str.set('17');
//false
str.set('123')
//false
str.set('17');
//false
str.set('16');
//true +change
str.set('88')
//false +change
str.set('16');
//true +change
str.set('16');
//true
assert.deepEqual(changes, [false, true, false, true]);
var str = new Store.Value.String('123');
var changes = [];
str.valEqual('123')(changes.push.bind(changes));
//true +init
str.set('17');
//false +change
str.set('123')
//true +change
str.set('17');
//false +change
str.set('16');
//false
str.set('88')
//false
str.set('16');
//false
str.set('16');
//false
assert.deepEqual(changes, [true, false, true, false]);
})
}); });
\ 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