Allow once listeners to dispatch events of same type
This commit is contained in:
@@ -33,6 +33,12 @@ ol.events.EventTarget = function() {
|
||||
*/
|
||||
this.pendingRemovals_ = {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!Object.<string, number>}
|
||||
*/
|
||||
this.dispatching_ = {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!Object.<string, Array.<ol.events.ListenerFunctionType>>}
|
||||
@@ -72,19 +78,25 @@ ol.events.EventTarget.prototype.dispatchEvent = function(event) {
|
||||
var listeners = this.listeners_[type];
|
||||
var propagate;
|
||||
if (listeners) {
|
||||
if (!(type in this.pendingRemovals_)) {
|
||||
if (!(type in this.dispatching_)) {
|
||||
this.dispatching_[type] = 0;
|
||||
this.pendingRemovals_[type] = 0;
|
||||
}
|
||||
++this.dispatching_[type];
|
||||
for (var i = 0, ii = listeners.length; i < ii; ++i) {
|
||||
if (listeners[i].call(this, evt) === false || evt.propagationStopped) {
|
||||
propagate = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var pendingRemovals = this.pendingRemovals_[type];
|
||||
delete this.pendingRemovals_[type];
|
||||
while (pendingRemovals--) {
|
||||
this.removeEventListener(type, ol.nullFunction);
|
||||
--this.dispatching_[type];
|
||||
if (this.dispatching_[type] === 0) {
|
||||
var pendingRemovals = this.pendingRemovals_[type];
|
||||
delete this.pendingRemovals_[type];
|
||||
while (pendingRemovals--) {
|
||||
this.removeEventListener(type, ol.nullFunction);
|
||||
}
|
||||
delete this.dispatching_[type];
|
||||
}
|
||||
return propagate;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user