Simpler type for ol.events.Key
Instead of having `ol.events.Key` be a listener object or an array of listener objects, it should be less error prone to have it just be a single listener object. To avoid using too many functions with multiple return types, the `ol.events.*` functions for registering and unregistering listeners no longer accept an array of event types (and only a single key is returned when registering). To make it convenient for users to register multiple listeners at once, the `observable.on()` method accepts an array of event types. Internally in the library, we should use the less risky `ol.events.listen()`.
This commit is contained in:
committed by
Andreas Hocevar
parent
78f44dcc8a
commit
f10c90bdba
@@ -84,16 +84,9 @@ describe('ol.events', function() {
|
||||
ol.events.listen(target, 'foo', function() {});
|
||||
expect(add.callCount).to.be(1);
|
||||
});
|
||||
it('adds listeners for multiple types with a single call', function() {
|
||||
ol.events.listen(target, ['foo', 'bar'], function() {});
|
||||
expect(add.getCall(0).args[0]).to.be('foo');
|
||||
expect(add.getCall(1).args[0]).to.be('bar');
|
||||
});
|
||||
it('returns a key', function() {
|
||||
var key = ol.events.listen(target, 'foo', function() {});
|
||||
expect(key).to.be.a(Object);
|
||||
key = ol.events.listen(target, ['foo', 'bar'], function() {});
|
||||
expect(key).to.be.a(Array);
|
||||
});
|
||||
it('does not add the same listener twice', function() {
|
||||
var listener = function() {};
|
||||
@@ -173,12 +166,15 @@ describe('ol.events', function() {
|
||||
|
||||
describe('unlistenAll()', function() {
|
||||
it('unregisters all listeners registered for a target', function() {
|
||||
var key = ol.events.listen(target, ['foo', 'bar'], function() {});
|
||||
var keys = [
|
||||
ol.events.listen(target, 'foo', function() {}),
|
||||
ol.events.listen(target, 'bar', function() {})
|
||||
];
|
||||
ol.events.unlistenAll(target);
|
||||
expect(ol.events.getListeners(target, 'foo')).to.be(undefined);
|
||||
expect(ol.events.getListeners(target, 'bar')).to.be(undefined);
|
||||
expect(ol.events.LISTENER_MAP_PROP_ in target).to.be(false);
|
||||
expect(key).to.eql([{}, {}]);
|
||||
expect(keys).to.eql([{}, {}]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user