@@ -101,12 +101,12 @@ function createTexture(
101
101
let idCounter = 0 ;
102
102
103
103
export class LightningViewElement <
104
- TStyleProps extends LightningViewElementStyle = LightningViewElementStyle ,
105
- TProps extends
106
- LightningViewElementProps < TStyleProps > = LightningViewElementProps < TStyleProps > ,
107
- > implements
108
- Focusable ,
109
- Pick < EventEmitter < LightningElementEvents > , 'on' | 'off' | 'emit' >
104
+ TStyleProps extends LightningViewElementStyle = LightningViewElementStyle ,
105
+ TProps extends
106
+ LightningViewElementProps < TStyleProps > = LightningViewElementProps < TStyleProps > ,
107
+ >
108
+ extends EventEmitter < LightningElementEvents >
109
+ implements Focusable
110
110
{
111
111
public static allElements : Record < number , LightningElement > = { } ;
112
112
@@ -118,7 +118,6 @@ export class LightningViewElement<
118
118
public readonly rawProps : TProps ;
119
119
public readonly props : TProps ;
120
120
121
- protected readonly _emitter = new EventEmitter < LightningElementEvents > ( ) ;
122
121
protected readonly _renderer : RendererMain ;
123
122
124
123
protected _parent : LightningElement | null = null ;
@@ -131,7 +130,7 @@ export class LightningViewElement<
131
130
private _shaderDef ?: ShaderDef ;
132
131
private _textureDef ?: TextureDef ;
133
132
private _focused = false ;
134
- private _focusable = true ;
133
+ private _focusable = false ;
135
134
private _visible = true ;
136
135
137
136
public get visible ( ) : boolean {
@@ -154,7 +153,7 @@ export class LightningViewElement<
154
153
this . blur ( ) ;
155
154
}
156
155
157
- this . emit ( 'focusableChanged' , this . _focusable ) ;
156
+ this . emit ( 'focusableChanged' , this , this . _focusable ) ;
158
157
}
159
158
160
159
public get focused ( ) {
@@ -240,18 +239,14 @@ export class LightningViewElement<
240
239
return this . node . id === 1 ;
241
240
}
242
241
243
- public on = this . _emitter . on . bind ( this . _emitter ) ;
244
- public off = this . _emitter . off . bind ( this . _emitter ) ;
245
- public addEventListener = this . _emitter . on . bind ( this . _emitter ) ;
246
- public removeEventListener = this . _emitter . off . bind ( this . _emitter ) ;
247
- public emit = this . _emitter . emit . bind ( this . _emitter ) ;
248
-
249
242
public constructor (
250
243
initialProps : TProps ,
251
244
renderer : RendererMain ,
252
245
plugins : Plugin < LightningElement > [ ] ,
253
246
fiber : Fiber ,
254
247
) {
248
+ super ( ) ;
249
+
255
250
this . _renderer = renderer ;
256
251
this . _plugins = plugins ?? [ ] ;
257
252
@@ -294,7 +289,7 @@ export class LightningViewElement<
294
289
295
290
LightningViewElement . allElements [ this . id ] = this ;
296
291
297
- this . _emitter . emit ( 'initialized' ) ;
292
+ this . emit ( 'initialized' ) ;
298
293
}
299
294
300
295
public destroy ( ) {
@@ -312,7 +307,7 @@ export class LightningViewElement<
312
307
313
308
delete LightningViewElement . allElements [ this . id ] ;
314
309
315
- this . _emitter . emit ( 'destroy' ) ;
310
+ this . emit ( 'destroy' ) ;
316
311
}
317
312
318
313
public insertChild (
@@ -331,7 +326,7 @@ export class LightningViewElement<
331
326
332
327
child . parent = this ;
333
328
334
- this . _emitter . emit ( 'childAdded' , child , index ) ;
329
+ this . emit ( 'childAdded' , child , index ) ;
335
330
}
336
331
337
332
public removeChild ( child : LightningElement ) {
@@ -343,22 +338,22 @@ export class LightningViewElement<
343
338
344
339
child . node . parent = null ;
345
340
346
- this . _emitter . emit ( 'childRemoved' , child , index ) ;
341
+ this . emit ( 'childRemoved' , child , index ) ;
347
342
}
348
343
349
344
public focus ( ) : void {
350
345
if ( ! this . _focused ) {
351
346
this . props . onFocusCapture ?.( this ) ;
352
347
this . _focused = true ;
353
- this . _emitter . emit ( 'focusChanged' , true ) ;
348
+ this . emit ( 'focusChanged' , this , true ) ;
354
349
this . props . onFocus ?.( this ) ;
355
350
}
356
351
}
357
352
358
353
public blur ( ) : void {
359
354
if ( this . _focused ) {
360
355
this . _focused = false ;
361
- this . _emitter . emit ( 'focusChanged' , false ) ;
356
+ this . emit ( 'focusChanged' , this , false ) ;
362
357
this . props . onBlur ?.( this ) ;
363
358
}
364
359
}
@@ -507,7 +502,7 @@ export class LightningViewElement<
507
502
}
508
503
509
504
if ( this . focusable !== prevFocusable ) {
510
- this . emit ( 'focusableChanged' , this . focusable ) ;
505
+ this . emit ( 'focusableChanged' , this , this . focusable ) ;
511
506
}
512
507
} ;
513
508
@@ -559,7 +554,7 @@ export class LightningViewElement<
559
554
}
560
555
561
556
if ( payload . style && Object . keys ( payload . style ) . length ) {
562
- this . _emitter . emit (
557
+ this . emit (
563
558
'stylesChanged' ,
564
559
this . props . style as Partial < LightningElementStyle > ,
565
560
) ;
@@ -580,12 +575,12 @@ export class LightningViewElement<
580
575
581
576
private _onTextureLoaded : NodeLoadedEventHandler = ( node , event ) => {
582
577
this . _handleTextureLoaded ( event ) ;
583
- this . _emitter . emit ( 'textureLoaded' , node , event ) ;
578
+ this . emit ( 'textureLoaded' , node , event ) ;
584
579
this . props . onTextureReady ?.( event . dimensions ) ;
585
580
} ;
586
581
587
582
private _onTextureFailed : NodeFailedEventHandler = ( ...args ) => {
588
- this . _emitter . emit ( 'textureFailed' , ...args ) ;
583
+ this . emit ( 'textureFailed' , ...args ) ;
589
584
} ;
590
585
591
586
private _onLayout = ( dimensions : Rect ) => {
@@ -599,7 +594,7 @@ export class LightningViewElement<
599
594
const animation = this . node . animate ( props , animationSettings || { } ) ;
600
595
601
596
animation . once ( 'stopped' , ( controller ) => {
602
- this . _emitter . emit ( 'animationFinished' , controller ) ;
597
+ this . emit ( 'animationFinished' , controller ) ;
603
598
} ) ;
604
599
605
600
return animation ;
0 commit comments