@@ -46,11 +46,11 @@ export class DOMEvent implements Event {
46
46
Object . defineProperty ( DOMEvent . prototype , 'AT_TARGET' , { value : DOMEvent . AT_TARGET } ) ;
47
47
Object . defineProperty ( DOMEvent . prototype , 'BUBBLING_PHASE' , { value : DOMEvent . BUBBLING_PHASE } ) ;
48
48
Object . defineProperty ( DOMEvent . prototype , 'cancelBubble' , { value : false , writable : true } ) ;
49
- Object . defineProperty ( DOMEvent . prototype , '_canceled ' , { value : false , writable : true } ) ;
49
+ Object . defineProperty ( DOMEvent . prototype , 'defaultPrevented ' , { value : false , writable : true } ) ;
50
50
Object . defineProperty ( DOMEvent . prototype , 'isTrusted' , { value : false , writable : true , enumerable : true } ) ;
51
- Object . defineProperty ( DOMEvent . prototype , '_eventPhase ' , { value : DOMEvent . NONE , writable : true } ) ;
52
- Object . defineProperty ( DOMEvent . prototype , '_currentTarget ' , { value : null , writable : true } ) ;
53
- Object . defineProperty ( DOMEvent . prototype , '_target ' , { value : null , writable : true } ) ;
51
+ Object . defineProperty ( DOMEvent . prototype , 'eventPhase ' , { value : DOMEvent . NONE , writable : true } ) ;
52
+ Object . defineProperty ( DOMEvent . prototype , 'currentTarget ' , { value : null , writable : true } ) ;
53
+ Object . defineProperty ( DOMEvent . prototype , 'target ' , { value : null , writable : true } ) ;
54
54
Object . defineProperty ( DOMEvent . prototype , 'propagationState' , { value : EventPropagationState . resume , writable : true } ) ;
55
55
Object . defineProperty ( DOMEvent . prototype , 'listenersLive' , { value : emptyArray , writable : true } ) ;
56
56
Object . defineProperty ( DOMEvent . prototype , 'listenersLazyCopy' , { value : emptyArray , writable : true } ) ;
@@ -86,8 +86,6 @@ export class DOMEvent implements Event {
86
86
*/
87
87
static unstable_currentEvent : DOMEvent | null = null ;
88
88
89
- private _canceled : boolean ;
90
-
91
89
/** @deprecated Setting this value does nothing. */
92
90
cancelBubble : boolean ;
93
91
@@ -125,42 +123,27 @@ export class DOMEvent implements Event {
125
123
* Returns true if preventDefault() was invoked successfully to indicate
126
124
* cancelation, and false otherwise.
127
125
*/
128
- get defaultPrevented ( ) {
129
- return this . _canceled ;
130
- }
126
+ defaultPrevented : boolean ;
127
+
128
+ // Strictly speaking, we should use { public get, private set } for all of
129
+ // `eventPhase`, `currentTarget`, and `target`, but using simple properties
130
+ // saves 800 nanoseconds per run of handleEvent() (and so is one of our
131
+ // biggest optimisations).
131
132
132
- private _eventPhase : 0 | 1 | 2 | 3 ;
133
133
/**
134
134
* Returns the event's phase, which is one of NONE, CAPTURING_PHASE,
135
135
* AT_TARGET, and BUBBLING_PHASE.
136
136
*/
137
- get eventPhase ( ) {
138
- return this . _eventPhase ;
139
- }
140
- private set eventPhase ( value : 0 | 1 | 2 | 3 ) {
141
- this . _eventPhase = value ;
142
- }
137
+ eventPhase : 0 | 1 | 2 | 3 ;
143
138
144
- private _currentTarget : Observable | null ;
145
139
/**
146
140
* Returns the object whose event listener's callback is currently being
147
141
* invoked.
148
142
*/
149
- get currentTarget ( ) {
150
- return this . _currentTarget ;
151
- }
152
- private set currentTarget ( value : Observable | null ) {
153
- this . _currentTarget = value ;
154
- }
143
+ currentTarget : Observable | null ;
155
144
156
- private _target : Observable | null ;
157
145
/** Returns the object to which event is dispatched (its target). */
158
- get target ( ) {
159
- return this . _target ;
160
- }
161
- private set target ( value : Observable | null ) {
162
- this . _target = value ;
163
- }
146
+ target : Observable | null ;
164
147
165
148
// From CustomEvent rather than Event. Can consider factoring out this
166
149
// aspect into DOMCustomEvent.
@@ -245,7 +228,7 @@ export class DOMEvent implements Event {
245
228
if ( ! this . cancelable ) {
246
229
return ;
247
230
}
248
- this . _canceled = true ;
231
+ this . defaultPrevented = true ;
249
232
}
250
233
/**
251
234
* Invoking this method prevents event from reaching any registered event
@@ -294,7 +277,7 @@ export class DOMEvent implements Event {
294
277
}
295
278
this . eventPhase = this . CAPTURING_PHASE ;
296
279
this . target = target ;
297
- this . _canceled = false ;
280
+ this . defaultPrevented = false ;
298
281
299
282
// Internal API to facilitate testing - to be removed once we've
300
283
// completed the breaking changes to migrate fully to DOMEvents.
@@ -361,7 +344,7 @@ export class DOMEvent implements Event {
361
344
362
345
if ( this . propagationState !== EventPropagationState . resume ) {
363
346
reset ( ) ;
364
- return this . returnValue ;
347
+ return ! this . defaultPrevented ;
365
348
}
366
349
}
367
350
@@ -381,7 +364,7 @@ export class DOMEvent implements Event {
381
364
382
365
if ( this . propagationState !== EventPropagationState . resume ) {
383
366
reset ( ) ;
384
- return this . returnValue ;
367
+ return ! this . defaultPrevented ;
385
368
}
386
369
387
370
// If the event doesn't bubble, then, having dispatched it at the
@@ -406,7 +389,7 @@ export class DOMEvent implements Event {
406
389
} ) ;
407
390
408
391
reset ( ) ;
409
- return this . returnValue ;
392
+ return ! this . defaultPrevented ;
410
393
}
411
394
412
395
private handleEvent ( { data, isGlobal, phase, removeEventListener } : { data : EventData ; isGlobal : boolean ; phase : 0 | 1 | 2 | 3 ; removeEventListener : ( eventName : string , callback ?: any , thisArg ?: any , capture ?: boolean ) => void } ) {
0 commit comments