@@ -12,30 +12,30 @@ declare global {
12
12
export interface ResizeDefaults {
13
13
widthSensitive ?: boolean ;
14
14
heightSensitive ?: boolean ;
15
- debounceTimeout ?: number ;
15
+ debounceTimeout ?: number ;
16
16
injectionFactories ?: string [ ] ;
17
17
}
18
18
19
19
class ResizeService extends Service . extend ( Evented , {
20
- debounceTimeout : computed . oneWay ( 'defaultDebounceTimeout' ) ,
21
- heightSensitive : computed . oneWay ( 'defaultHeightSensitive' ) ,
22
- screenHeight : computed . readOnly ( '_oldHeight' ) ,
23
- screenWidth : computed . readOnly ( '_oldWidth' ) ,
24
- widthSensitive : computed . oneWay ( 'defaultWidthSensitive' ) ,
20
+ debounceTimeout : computed . oneWay ( 'defaultDebounceTimeout' ) ,
21
+ heightSensitive : computed . oneWay ( 'defaultHeightSensitive' ) ,
22
+ screenHeight : computed . readOnly ( '_oldHeight' ) ,
23
+ screenWidth : computed . readOnly ( '_oldWidth' ) ,
24
+ widthSensitive : computed . oneWay ( 'defaultWidthSensitive' )
25
25
} ) {
26
26
public _oldWidth = window . innerWidth ;
27
27
public _oldHeight = window . innerHeight ;
28
28
public _oldWidthDebounced = window . innerWidth ;
29
29
public _oldHeightDebounced = window . innerHeight ;
30
30
31
- public resizeServiceDefaults ! : ResizeDefaults ;
31
+ public resizeServiceDefaults ! : Partial < ResizeDefaults > ;
32
32
33
33
public _onResizeHandler ?: ( this : Window , evt : UIEvent ) => void ;
34
34
public _scheduledDebounce ?: ReturnType < typeof debounce > ;
35
35
constructor ( ) {
36
36
super ( ...arguments ) ;
37
37
this . _setDefaults ( ) ;
38
- this . _onResizeHandler = ( evt ) => {
38
+ this . _onResizeHandler = evt => {
39
39
this . _fireResizeNotification ( evt ) ;
40
40
const scheduledDebounce = debounce ( this , this . _fireDebouncedResizeNotification , evt , this . get ( 'debounceTimeout' ) ) ;
41
41
this . _scheduledDebounce = scheduledDebounce ;
@@ -55,9 +55,9 @@ class ResizeService extends Service.extend(Evented, {
55
55
}
56
56
57
57
public _setDefaults ( ) {
58
- const defaults = getWithDefault ( this , 'resizeServiceDefaults' , { } ) ;
58
+ const defaults = getWithDefault ( this , 'resizeServiceDefaults' , { } as any ) ;
59
59
60
- Object . keys ( defaults ) . map ( ( key : keyof ResizeDefaults ) => {
60
+ Object . keys ( defaults ) . map ( ( key : keyof ResizeDefaults ) => {
61
61
const classifiedKey = classify ( key ) ;
62
62
const defaultKey = `default${ classifiedKey } ` ;
63
63
return set ( this as any , defaultKey , defaults [ key ] ) ;
@@ -68,8 +68,7 @@ class ResizeService extends Service.extend(Evented, {
68
68
const wKey = debounced ? '_oldWidthDebounced' : '_oldWidth' ;
69
69
const hKey = debounced ? '_oldHeightDebounced' : '_oldHeight' ;
70
70
return (
71
- ( this . get ( 'widthSensitive' ) && w !== this . get ( wKey ) ) ||
72
- ( this . get ( 'heightSensitive' ) && h !== this . get ( hKey ) )
71
+ ( this . get ( 'widthSensitive' ) && w !== this . get ( wKey ) ) || ( this . get ( 'heightSensitive' ) && h !== this . get ( hKey ) )
73
72
) ;
74
73
}
75
74
@@ -81,17 +80,23 @@ class ResizeService extends Service.extend(Evented, {
81
80
}
82
81
83
82
public _installResizeListener ( ) {
84
- if ( ! this . _onResizeHandler ) { return ; }
83
+ if ( ! this . _onResizeHandler ) {
84
+ return ;
85
+ }
85
86
window . addEventListener ( 'resize' , this . _onResizeHandler ) ;
86
87
}
87
88
88
89
public _uninstallResizeListener ( ) {
89
- if ( ! this . _onResizeHandler ) { return ; }
90
+ if ( ! this . _onResizeHandler ) {
91
+ return ;
92
+ }
90
93
window . removeEventListener ( 'resize' , this . _onResizeHandler ) ;
91
94
}
92
95
93
96
public _cancelScheduledDebounce ( ) {
94
- if ( ! this . _scheduledDebounce ) { return ; }
97
+ if ( ! this . _scheduledDebounce ) {
98
+ return ;
99
+ }
95
100
cancel ( this . _scheduledDebounce ) ;
96
101
}
97
102
0 commit comments