Browse Source

added optional scope to Observable.removeCallback

Adam Bowman 7 năm trước cách đây
mục cha
commit
c71f2af843
1 tập tin đã thay đổi với 8 bổ sung2 xóa
  1. 8 2
      src/Tools/babylon.observable.ts

+ 8 - 2
src/Tools/babylon.observable.ts

@@ -157,11 +157,17 @@
         /**
          * Remove a callback from the Observable object
          * @param callback the callback to remove. If it doesn't belong to this Observable, false will be returned.
+         * @param scope optional scope.  If used only the callbacks with this scope will be removed.
         */
-        public removeCallback(callback: (eventData: T, eventState: EventState) => void): boolean {
+        public removeCallback(callback: (eventData: T, eventState: EventState) => void, scope?: any): boolean {
 
             for (var index = 0; index < this._observers.length; index++) {
-                if (this._observers[index].callback === callback) {
+                if(scope){
+                    if (this._observers[index].callback === callback && scope === this._observers[index].scope) {
+                        this._observers.splice(index, 1);
+                        return true;
+                    }
+                } else if (this._observers[index].callback === callback) {
                     this._observers.splice(index, 1);
                     return true;
                 }