1
1
import * as d from '../declarations' ;
2
2
import { BUILD } from '@build-conditionals' ;
3
- import { consoleError , doc , plt , supportsListenerOptions , win } from '@platform' ;
4
- import { LISTENER_FLAGS } from '@utils' ;
3
+ import { doc , plt , supportsListenerOptions , win } from '@platform' ;
4
+ import { HOST_FLAGS , LISTENER_FLAGS } from '@utils' ;
5
5
6
6
7
7
export const addEventListeners = ( elm : d . HostElement , hostRef : d . HostRef , listeners : d . ComponentRuntimeHostListener [ ] ) => {
8
+ hostRef . $queuedListeners$ = hostRef . $queuedListeners$ || [ ] ;
8
9
const removeFns = listeners . map ( ( [ flags , name , method ] ) => {
9
10
const target = ( BUILD . hostListenerTarget ? getHostListenerTarget ( elm , flags ) : elm ) ;
10
11
const handler = hostListenerProxy ( hostRef , method ) ;
@@ -18,15 +19,15 @@ export const addEventListeners = (elm: d.HostElement, hostRef: d.HostRef, listen
18
19
const hostListenerProxy = ( hostRef : d . HostRef , methodName : string ) => {
19
20
return ( ev : Event ) => {
20
21
if ( BUILD . lazyLoad ) {
21
- if ( hostRef . $lazyInstance$ ) {
22
+ if ( hostRef . $flags$ & HOST_FLAGS . isMethodsCallable ) {
22
23
// instance is ready, let's call it's member method for this event
23
- return hostRef . $lazyInstance$ [ methodName ] ( ev ) ;
24
+ hostRef . $lazyInstance$ [ methodName ] ( ev ) ;
24
25
25
26
} else {
26
- return hostRef . $onReadyPromise$ . then ( ( ) => hostRef . $lazyInstance$ [ methodName ] ( ev ) ) . catch ( consoleError ) ;
27
+ hostRef . $queuedListeners$ . push ( [ methodName , ev ] ) ;
27
28
}
28
29
} else {
29
- return ( hostRef . $hostElement$ as any ) [ methodName ] ( ev ) ;
30
+ ( hostRef . $hostElement$ as any ) [ methodName ] ( ev ) ;
30
31
}
31
32
} ;
32
33
} ;
0 commit comments