File tree 1 file changed +5
-8
lines changed
1 file changed +5
-8
lines changed Original file line number Diff line number Diff line change 14
14
* limitations under the License.
15
15
*/
16
16
17
+ import { removeItem } from '../types/array' ;
18
+
17
19
/**
18
20
* This class helps to manage observers. Observers can be added, removed or
19
21
* fired through and instance of this class.
@@ -51,10 +53,7 @@ export class Observable {
51
53
if ( ! this . handlers_ ) {
52
54
return ;
53
55
}
54
- const index = this . handlers_ . indexOf ( handler ) ;
55
- if ( index > - 1 ) {
56
- this . handlers_ . splice ( index , 1 ) ;
57
- }
56
+ removeItem ( this . handlers , handler ) ;
58
57
}
59
58
60
59
/**
@@ -75,9 +74,7 @@ export class Observable {
75
74
if ( ! this . handlers_ ) {
76
75
return ;
77
76
}
78
- const handlers = this . handlers_ ;
79
- for ( let i = 0 ; i < handlers . length ; i ++ ) {
80
- const handler = handlers [ i ] ;
77
+ for ( const handler of this . handlers_ ) {
81
78
handler ( opt_event ) ;
82
79
}
83
80
}
@@ -87,6 +84,6 @@ export class Observable {
87
84
* @return {number }
88
85
*/
89
86
getHandlerCount ( ) {
90
- return this . handlers_ ?. length || 0 ;
87
+ return this . handlers_ ?. length ?? 0 ;
91
88
}
92
89
}
You can’t perform that action at this time.
0 commit comments