@@ -22,7 +22,7 @@ import {inject} from '../di/injector_compatibility';
22
22
import { Provider } from '../di/interface/provider' ;
23
23
import { setDisableEventReplayImpl } from '../render3/instructions/listener' ;
24
24
import { TNode , TNodeType } from '../render3/interfaces/node' ;
25
- import { RNode } from '../render3/interfaces/renderer_dom' ;
25
+ import { RElement , RNode } from '../render3/interfaces/renderer_dom' ;
26
26
import { CLEANUP , LView , TView } from '../render3/interfaces/view' ;
27
27
import { isPlatformBrowser } from '../render3/util/misc_utils' ;
28
28
import { unwrapRNode } from '../render3/util/view_utils' ;
@@ -42,6 +42,11 @@ function getJsactionData(container: EarlyJsactionDataContainer) {
42
42
}
43
43
44
44
const JSACTION_ATTRIBUTE = 'jsaction' ;
45
+
46
+ /**
47
+ * Associates a DOM element with `jsaction` attribute to a map that contains info about all event
48
+ * types (event names) and corresponding listeners.
49
+ */
45
50
const jsactionMap : Map < Element , Map < string , Function [ ] > > = new Map ( ) ;
46
51
47
52
/**
@@ -57,18 +62,19 @@ export function withEventReplay(): Provider[] {
57
62
{
58
63
provide : ENVIRONMENT_INITIALIZER ,
59
64
useValue : ( ) => {
60
- setDisableEventReplayImpl ( ( rEl , eventName , listenerFn ) => {
65
+ setDisableEventReplayImpl ( ( rEl : RElement , eventName : string , listenerFn : VoidFunction ) => {
61
66
if ( rEl . hasAttribute ( JSACTION_ATTRIBUTE ) ) {
62
- const el = unwrapRNode ( rEl ) as Element ;
67
+ const el = rEl as unknown as Element ;
63
68
// We don't immediately remove the attribute here because
64
69
// we need it for replay that happens after hydration.
65
70
if ( ! jsactionMap . has ( el ) ) {
66
71
jsactionMap . set ( el , new Map ( ) ) ;
67
72
}
68
- if ( ! jsactionMap . get ( el ) ! . has ( eventName ) ) {
69
- jsactionMap . get ( el ) ! . set ( eventName , [ ] ) ;
73
+ const eventMap = jsactionMap . get ( el ) ! ;
74
+ if ( ! eventMap . has ( eventName ) ) {
75
+ eventMap . set ( eventName , [ ] ) ;
70
76
}
71
- jsactionMap . get ( el ) ! . get ( eventName ) ! . push ( listenerFn ) ;
77
+ eventMap . get ( eventName ) ! . push ( listenerFn ) ;
72
78
}
73
79
} ) ;
74
80
} ,
@@ -192,7 +198,7 @@ export function setJSActionAttribute(
192
198
}
193
199
194
200
function handleEvent ( event : EventInfoWrapper ) {
195
- const nativeElement = unwrapRNode ( event . getAction ( ) ! . element ) as Element ;
201
+ const nativeElement = event . getAction ( ) ! . element as Element ;
196
202
const handlerFns = jsactionMap . get ( nativeElement ) ?. get ( event . getEventType ( ) ) ;
197
203
if ( ! handlerFns ) {
198
204
return ;
0 commit comments