1
- import Mixin from '@ember/object/mixin' ;
2
1
import { readOnly } from '@ember/object/computed' ;
2
+ import Mixin from '@ember/object/mixin' ;
3
+ import ResizeService from 'dummy/services/resize' ;
3
4
const { floor } = Math ;
4
5
5
- export default Mixin . create ( {
6
- resizeEventsEnabled : true ,
6
+ // tslint:disable-next-line:variable-name
7
+ const ResizeAwareMixin = Mixin . create ( {
7
8
resizeDebouncedEventsEnabled : true ,
9
+ resizeEventsEnabled : true ,
8
10
9
- screenWidth : readOnly ( 'resizeService.screenWidth' ) ,
10
11
screenHeight : readOnly ( 'resizeService.screenHeight' ) ,
12
+ screenWidth : readOnly ( 'resizeService.screenWidth' ) ,
11
13
12
- _oldViewWidth : null ,
13
- _oldViewHeight : null ,
14
- _oldViewWidthDebounced : null ,
15
- _oldViewHeightDebounced : null ,
16
- resizeWidthSensitive : true ,
14
+ _oldViewHeight : null as number | null ,
15
+ _oldViewHeightDebounced : null as number | null ,
16
+ _oldViewWidth : null as number | null ,
17
+ _oldViewWidthDebounced : null as number | null ,
17
18
resizeHeightSensitive : true ,
19
+ resizeWidthSensitive : true ,
18
20
19
21
didInsertElement ( ) {
20
22
this . _super ( ...arguments ) ;
23
+ const resizeService : ResizeService = ( this as any ) . get ( 'resizeService' ) ;
21
24
if ( this . get ( 'resizeEventsEnabled' ) ) {
22
- this . get ( ' resizeService' ) . on ( 'didResize' , this , this . _handleResizeEvent ) ;
25
+ resizeService . on ( 'didResize' , this , this . _handleResizeEvent ) ;
23
26
}
24
27
if ( this . get ( 'resizeDebouncedEventsEnabled' ) ) {
25
- this . get ( ' resizeService' ) . on ( 'debouncedDidResize' , this , this . _handleDebouncedResizeEvent ) ;
28
+ resizeService . on ( 'debouncedDidResize' , this , this . _handleDebouncedResizeEvent ) ;
26
29
}
27
30
} ,
28
31
29
32
willDestroyElement ( ) {
30
33
this . _super ( ...arguments ) ;
34
+ const resizeService : ResizeService = ( this as any ) . get ( 'resizeService' ) ;
31
35
if ( this . get ( 'resizeEventsEnabled' ) ) {
32
- this . get ( ' resizeService' ) . off ( 'didResize' , this , this . _handleResizeEvent ) ;
36
+ resizeService . off ( 'didResize' , this , this . _handleResizeEvent ) ;
33
37
}
34
38
if ( this . get ( 'resizeDebouncedEventsEnabled' ) ) {
35
- this . get ( ' resizeService' ) . off ( 'debouncedDidResize' , this , this . _handleDebouncedResizeEvent ) ;
39
+ resizeService . off ( 'debouncedDidResize' , this , this . _handleDebouncedResizeEvent ) ;
36
40
}
37
41
} ,
38
42
39
- didResize ( /*width, height, evt*/ ) { } , // Overridden in subclass
40
- debouncedDidResize ( /*width, height, evt*/ ) { } , // Overridden in subclass
43
+ // tslint:disable-next-line:no-empty
44
+ didResize ( _width : number , _height : number , _evt : UIEvent ) { } , // Overridden in subclass
45
+ // tslint:disable-next-line:no-empty
46
+ debouncedDidResize ( _width : number , _height : number , _evt : UIEvent ) { } , // Overridden in subclass
41
47
42
- _getComponentSize ( ) {
48
+ _getComponentSize ( this : any ) {
43
49
return this . element . getClientRects ( ) [ 0 ] ;
44
50
} ,
45
51
46
- _handleResizeEvent ( evt ) {
52
+ _handleResizeEvent ( evt : UIEvent ) {
47
53
const w = floor ( this . _getComponentSize ( ) . width ) ;
48
54
const h = floor ( this . _getComponentSize ( ) . height ) ;
49
55
if (
@@ -52,13 +58,13 @@ export default Mixin.create({
52
58
) {
53
59
this . didResize ( w , h , evt ) ;
54
60
this . setProperties ( {
61
+ _oldViewHeight : h ,
55
62
_oldViewWidth : w ,
56
- _oldViewHeight : h
57
63
} ) ;
58
64
}
59
65
} ,
60
66
61
- _handleDebouncedResizeEvent ( evt ) {
67
+ _handleDebouncedResizeEvent ( evt : UIEvent ) {
62
68
const w = floor ( this . _getComponentSize ( ) . width ) ;
63
69
const h = floor ( this . _getComponentSize ( ) . height ) ;
64
70
if (
@@ -67,9 +73,11 @@ export default Mixin.create({
67
73
) {
68
74
this . debouncedDidResize ( w , h , evt ) ;
69
75
this . setProperties ( {
76
+ _oldViewHeightDebounced : h ,
70
77
_oldViewWidthDebounced : w ,
71
- _oldViewHeightDebounced : h
72
78
} ) ;
73
79
}
74
- }
80
+ } ,
75
81
} ) ;
82
+
83
+ export default ResizeAwareMixin ;
0 commit comments