|
@@ -217,8 +217,7 @@
|
|
var index = this._observers.indexOf(observer);
|
|
var index = this._observers.indexOf(observer);
|
|
|
|
|
|
if (index !== -1) {
|
|
if (index !== -1) {
|
|
-
|
|
|
|
- this._observers.splice(index, 1);
|
|
|
|
|
|
+ this._deferUnregister(observer);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -236,7 +235,7 @@
|
|
|
|
|
|
for (var index = 0; index < this._observers.length; index++) {
|
|
for (var index = 0; index < this._observers.length; index++) {
|
|
if (this._observers[index].callback === callback && (!scope || scope === this._observers[index].scope)) {
|
|
if (this._observers[index].callback === callback && (!scope || scope === this._observers[index].scope)) {
|
|
- this._observers.splice(index, 1);
|
|
|
|
|
|
+ this._deferUnregister(this._observers[index]);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -248,10 +247,27 @@
|
|
observer.unregisterOnNextCall = false;
|
|
observer.unregisterOnNextCall = false;
|
|
observer._willBeUnregistered = true;
|
|
observer._willBeUnregistered = true;
|
|
Tools.SetImmediate(() => {
|
|
Tools.SetImmediate(() => {
|
|
- this.remove(observer);
|
|
|
|
|
|
+ this._remove(observer);
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // This should only be called when not iterating over _observers to avoid callback skipping.
|
|
|
|
+ // Removes an observer from the _observer Array.
|
|
|
|
+ private _remove(observer: Nullable<Observer<T>>): boolean {
|
|
|
|
+ if (!observer) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var index = this._observers.indexOf(observer);
|
|
|
|
+
|
|
|
|
+ if (index !== -1) {
|
|
|
|
+ this._observers.splice(index, 1);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Notify all Observers by calling their respective callback with the given data
|
|
* Notify all Observers by calling their respective callback with the given data
|
|
* Will return true if all observers were executed, false if an observer set skipNextObservers to true, then prevent the subsequent ones to execute
|
|
* Will return true if all observers were executed, false if an observer set skipNextObservers to true, then prevent the subsequent ones to execute
|