Dispatch a change event only if the value is different
This commit is contained in:
@@ -206,7 +206,9 @@ ol.Object.prototype.set = function(key, value, opt_silent) {
|
||||
} else {
|
||||
var oldValue = this.values_[key];
|
||||
this.values_[key] = value;
|
||||
this.notify(key, oldValue);
|
||||
if (oldValue !== value) {
|
||||
this.notify(key, oldValue);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -168,6 +168,13 @@ describe('ol.Object', function() {
|
||||
expect(event.key).to.be('k');
|
||||
});
|
||||
|
||||
it('dispatches events only if the value is different', function() {
|
||||
o.set('k', 1);
|
||||
o.set('k', 1);
|
||||
expect(listener1.calledOnce).to.be(true);
|
||||
expect(listener2.calledOnce).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('setter', function() {
|
||||
|
||||
Reference in New Issue
Block a user