• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

excaliburjs / Excalibur / 18822699988

26 Oct 2025 07:30PM UTC coverage: 88.641% (-0.01%) from 88.653%
18822699988

Pull #3549

github

web-flow
Merge 16223b894 into 66f91aa13
Pull Request #3549: hasChild

5183 of 7067 branches covered (73.34%)

0 of 1 new or added line in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

14289 of 16120 relevant lines covered (88.64%)

24592.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.1
/src/engine/EntityComponentSystem/Entity.ts
1
import type { ComponentCtor } from './Component';
2
import { Component, isComponentCtor } from './Component';
3

4
import type { Message } from '../Util/Observable';
5
import { Observable } from '../Util/Observable';
6
import type { OnInitialize, OnPreUpdate, OnPostUpdate, OnAdd, OnRemove } from '../Interfaces/LifecycleEvents';
7
import type { Engine } from '../Engine';
8
import { InitializeEvent, PreUpdateEvent, PostUpdateEvent, AddEvent, RemoveEvent } from '../Events';
9
import { KillEvent } from '../Events';
10
import type { EventKey, Handler, Subscription } from '../EventEmitter';
11
import { EventEmitter } from '../EventEmitter';
12
import type { Scene } from '../Scene';
13
import { removeItemFromArray } from '../Util/Util';
14
import type { MaybeKnownComponent } from './Types';
15

16
/**
17
 * Interface holding an entity component pair
18
 */
19
export interface EntityComponent {
20
  component: Component;
21
  entity: Entity;
22
}
23

24
/**
25
 * AddedComponent message
26
 */
27
export class AddedComponent implements Message<EntityComponent> {
28
  readonly type: 'Component Added' = 'Component Added';
×
29
  constructor(public data: EntityComponent) {}
×
30
}
31

32
/**
33
 * Type guard to know if message is f an Added Component
34
 */
35
export function isAddedComponent(x: Message<EntityComponent>): x is AddedComponent {
36
  return !!x && x.type === 'Component Added';
×
37
}
38

39
/**
40
 * RemovedComponent message
41
 */
42
export class RemovedComponent implements Message<EntityComponent> {
43
  readonly type: 'Component Removed' = 'Component Removed';
×
44
  constructor(public data: EntityComponent) {}
×
45
}
46

47
/**
48
 * Type guard to know if message is for a Removed Component
49
 */
50
export function isRemovedComponent(x: Message<EntityComponent>): x is RemovedComponent {
51
  return !!x && x.type === 'Component Removed';
×
52
}
53

54
/**
55
 * Built in events supported by all entities
56
 */
57
export type EntityEvents = {
58
  initialize: InitializeEvent;
59
  //@ts-ignore
60
  add: AddEvent;
61
  //@ts-ignore
62
  remove: RemoveEvent;
63
  preupdate: PreUpdateEvent;
64
  postupdate: PostUpdateEvent;
65
  kill: KillEvent;
66
};
67

68
export const EntityEvents = {
246✔
69
  Add: 'add',
70
  Remove: 'remove',
71
  Initialize: 'initialize',
72
  PreUpdate: 'preupdate',
73
  PostUpdate: 'postupdate',
74
  Kill: 'kill'
75
} as const;
76

77
export interface EntityOptions<TComponents extends Component> {
78
  name?: string;
79
  components?: TComponents[];
80
}
81

82
/**
83
 * An Entity is the base type of anything that can have behavior in Excalibur, they are part of the built in entity component system
84
 *
85
 * Entities can be strongly typed with the components they contain
86
 *
87
 * ```typescript
88
 * const entity = new Entity<ComponentA | ComponentB>();
89
 * entity.components.a; // Type ComponentA
90
 * entity.components.b; // Type ComponentB
91
 * ```
92
 */
93
export class Entity<TKnownComponents extends Component = any> implements OnInitialize, OnPreUpdate, OnPostUpdate, OnAdd, OnRemove {
246✔
94
  private static _ID = 0;
95
  /**
96
   * The unique identifier for the entity
97
   */
98
  public id: number = Entity._ID++;
7,549✔
99

100
  public name = `Entity#${this.id}`;
7,549✔
101

102
  /**
103
   * Listen to or emit events for an entity
104
   */
105
  public events = new EventEmitter<EntityEvents>();
7,549✔
106
  private _tags = new Set<string>();
7,549✔
107
  public componentAdded$ = new Observable<Component>();
7,549✔
108
  public componentRemoved$ = new Observable<Component>();
7,549✔
109
  public tagAdded$ = new Observable<string>();
7,549✔
110
  public tagRemoved$ = new Observable<string>();
7,549✔
111
  /**
112
   * Current components on the entity
113
   *
114
   * **Do not modify**
115
   *
116
   * Use addComponent/removeComponent otherwise the ECS will not be notified of changes.
117
   */
118
  public readonly components = new Map<Function, Component>();
7,549✔
119
  public componentValues: Component[] = [];
7,549✔
120
  public _componentsToRemove: ComponentCtor[] = [];
7,549✔
121

122
  constructor(options: EntityOptions<TKnownComponents>);
123
  constructor(components?: TKnownComponents[], name?: string);
124
  constructor(componentsOrOptions?: TKnownComponents[] | EntityOptions<TKnownComponents>, name?: string) {
125
    let componentsToAdd!: TKnownComponents[];
126
    let nameToAdd: string | undefined;
127

128
    if (Array.isArray(componentsOrOptions)) {
7,549✔
129
      componentsToAdd = componentsOrOptions;
2,934✔
130
      nameToAdd = name;
2,934✔
131
    } else if (componentsOrOptions && typeof componentsOrOptions === 'object') {
4,615!
132
      const { components, name } = componentsOrOptions;
×
133
      componentsToAdd = components ?? [];
×
134
      nameToAdd = name;
×
135
    }
136
    if (nameToAdd) {
7,549✔
137
      this.name = nameToAdd;
10✔
138
    }
139
    if (componentsToAdd) {
7,549✔
140
      for (const component of componentsToAdd) {
2,934✔
141
        this.addComponent(component);
8,656✔
142
      }
143
    }
144
  }
145

146
  /**
147
   * The current scene that the entity is in, if any
148
   */
149
  public scene: Scene | null = null;
7,549✔
150

151
  /**
152
   * Whether this entity is active, if set to false it will be reclaimed
153
   * @deprecated use isActive
154
   */
155
  public get active(): boolean {
156
    return this.isActive;
1✔
157
  }
158

159
  /**
160
   * Whether this entity is active, if set to false it will be reclaimed
161
   * @deprecated use isActive
162
   */
163
  public set active(val: boolean) {
164
    this.isActive = val;
1✔
165
  }
166

167
  /**
168
   * Whether this entity is active, if set to false it will be reclaimed
169
   */
170
  public isActive: boolean = true;
7,549✔
171

172
  /**
173
   * Kill the entity, means it will no longer be updated. Kills are deferred to the end of the update.
174
   * If parented it will be removed from the parent when killed.
175
   */
176
  public kill() {
177
    if (this.isActive) {
30!
178
      this.isActive = false;
30✔
179
      this.unparent();
30✔
180
    }
181
    this.emit('kill', new KillEvent(this));
30✔
182
  }
183

184
  public isKilled() {
185
    return !this.isActive;
2✔
186
  }
187

188
  /**
189
   * Specifically get the tags on the entity from {@apilink TagsComponent}
190
   */
191
  public get tags(): Set<string> {
192
    return this._tags;
18✔
193
  }
194

195
  /**
196
   * Check if a tag exists on the entity
197
   * @param tag name to check for
198
   */
199
  public hasTag(tag: string): boolean {
200
    return this._tags.has(tag);
5,067✔
201
  }
202

203
  /**
204
   * Adds a tag to an entity
205
   * @param tag
206
   */
207
  public addTag(tag: string): Entity<TKnownComponents> {
208
    this._tags.add(tag);
64✔
209
    this.tagAdded$.notifyAll(tag);
64✔
210
    return this;
64✔
211
  }
212

213
  /**
214
   * Removes a tag on the entity
215
   *
216
   * Removals are deferred until the end of update
217
   * @param tag
218
   */
219
  public removeTag(tag: string): Entity<TKnownComponents> {
220
    this._tags.delete(tag);
8✔
221
    this.tagRemoved$.notifyAll(tag);
8✔
222
    return this;
8✔
223
  }
224

225
  /**
226
   * The types of the components on the Entity
227
   */
228
  public get types(): ComponentCtor[] {
229
    return Array.from(this.components.keys()) as ComponentCtor[];
24✔
230
  }
231

232
  /**
233
   * Returns all component instances on entity
234
   */
235
  public getComponents(): Component[] {
236
    return Array.from(this.components.values());
8✔
237
  }
238

239
  /**
240
   * Verifies that an entity has all the required types
241
   * @param requiredTypes
242
   */
243
  hasAll<TComponent extends Component>(requiredTypes: ComponentCtor<TComponent>[]): boolean {
244
    for (let i = 0; i < requiredTypes.length; i++) {
×
245
      if (!this.components.has(requiredTypes[i])) {
×
246
        return false;
×
247
      }
248
    }
249
    return true;
×
250
  }
251

252
  /**
253
   * Verifies that an entity has all the required tags
254
   * @param requiredTags
255
   */
256
  hasAllTags(requiredTags: string[]): boolean {
257
    for (let i = 0; i < requiredTags.length; i++) {
7✔
258
      if (!this.tags.has(requiredTags[i])) {
14✔
259
        return false;
2✔
260
      }
261
    }
262
    return true;
5✔
263
  }
264

265
  get<TComponent extends Component>(type: ComponentCtor<TComponent>): MaybeKnownComponent<TComponent, TKnownComponents> {
266
    return this.components.get(type) as MaybeKnownComponent<TComponent, TKnownComponents>;
68,615✔
267
  }
268

269
  private _parent: Entity | null = null;
7,549✔
270
  public get parent(): Entity | null {
271
    return this._parent;
15,211✔
272
  }
273

274
  public childrenAdded$ = new Observable<Entity>();
7,549✔
275
  public childrenRemoved$ = new Observable<Entity>();
7,549✔
276

277
  private _children: Entity[] = [];
7,549✔
278
  /**
279
   * Get the direct children of this entity
280
   */
281
  public get children(): readonly Entity[] {
282
    return this._children;
20,010✔
283
  }
284

285
  /**
286
   * Unparents this entity, if there is a parent. Otherwise it does nothing.
287
   */
288
  public unparent() {
289
    if (this._parent) {
135✔
290
      this._parent.removeChild(this);
7✔
291
      this._parent = null;
7✔
292
    }
293
  }
294

295
  /**
296
   * Check if a child entity exists on the parent entity
297
   * @param child entity to check for
298
   */
299
  public hasChild(child: Entity): boolean {
NEW
300
    return child.parent === this;
×
301
  }
302

303

304
  /**
305
   * Adds an entity to be a child of this entity
306
   * @param entity
307
   */
308
  public addChild(entity: Entity): Entity {
309
    if (entity.parent === null) {
2,969✔
310
      if (this.getAncestors().includes(entity)) {
2,968✔
311
        throw new Error('Cycle detected, cannot add entity');
1✔
312
      }
313
      this._children.push(entity);
2,967✔
314
      entity._parent = this;
2,967✔
315
      this.childrenAdded$.notifyAll(entity);
2,967✔
316
    } else {
317
      throw new Error('Entity already has a parent, cannot add without unparenting');
1✔
318
    }
319
    return this;
2,967✔
320
  }
321

322
  /**
323
   * Remove an entity from children if it exists
324
   * @param entity
325
   */
326
  public removeChild(entity: Entity): Entity {
327
    if (entity.parent === this) {
22!
328
      removeItemFromArray(entity, this._children);
22✔
329
      entity._parent = null;
22✔
330
      this.childrenRemoved$.notifyAll(entity);
22✔
331
    }
332
    return this;
22✔
333
  }
334

335
  /**
336
   * Removes all children from this entity
337
   */
338
  public removeAllChildren(): Entity {
339
    // Avoid modifying the array issue by walking backwards
340
    for (let i = this.children.length - 1; i >= 0; i--) {
1✔
341
      this.removeChild(this.children[i]);
6✔
342
    }
343
    return this;
1✔
344
  }
345

346
  /**
347
   * Returns a list of parent entities starting with the topmost parent. Includes the current entity.
348
   */
349
  public getAncestors(): Entity[] {
350
    const result: Entity[] = [this];
7,802✔
351
    let current = this.parent;
7,802✔
352
    while (current) {
7,802✔
353
      result.push(current);
2,052✔
354
      current = current.parent;
2,052✔
355
    }
356
    return result.reverse();
7,802✔
357
  }
358

359
  /**
360
   * Returns a list of all the entities that descend from this entity. Includes the current entity.
361
   */
362
  public getDescendants(): Entity[] {
363
    let result: Entity[] = [this];
1✔
364
    let queue: Entity[] = [this];
1✔
365
    while (queue.length > 0) {
1✔
366
      const curr = queue.pop();
3✔
367
      if (curr) {
3!
368
        queue = queue.concat(curr.children);
3✔
369
        result = result.concat(curr.children);
3✔
370
      }
371
    }
372
    return result;
1✔
373
  }
374

375
  /**
376
   * Creates a deep copy of the entity and a copy of all its components
377
   */
378
  public clone(): Entity {
379
    const newEntity = new Entity();
10✔
380
    for (const c of this.types) {
10✔
381
      const componentInstance = this.get(c);
14✔
382
      if (componentInstance) {
14!
383
        newEntity.addComponent(componentInstance.clone());
14✔
384
      }
385
    }
386
    for (const child of this.children) {
10✔
387
      newEntity.addChild(child.clone());
2✔
388
    }
389
    return newEntity;
10✔
390
  }
391

392
  /**
393
   * Adds a copy of all the components from another template entity as a "prefab"
394
   * @param templateEntity Entity to use as a template
395
   * @param force Force component replacement if it already exists on the target entity
396
   */
397
  public addTemplate(templateEntity: Entity, force: boolean = false): Entity {
3✔
398
    for (const c of templateEntity.getComponents()) {
3✔
399
      this.addComponent(c.clone(), force);
5✔
400
    }
401
    for (const child of templateEntity.children) {
3✔
402
      this.addChild(child.clone().addTemplate(child));
2✔
403
    }
404
    return this;
3✔
405
  }
406

407
  private _getClassHierarchyRoot(componentType: ComponentCtor): ComponentCtor {
408
    let current = componentType;
25,934✔
409
    let parent = Object.getPrototypeOf(current.prototype)?.constructor;
25,934!
410

411
    while (parent && parent !== Object && parent !== Component) {
25,934✔
412
      current = parent;
2✔
413
      parent = Object.getPrototypeOf(current.prototype)?.constructor;
2!
414
    }
415
    return current;
25,934✔
416
  }
417

418
  /**
419
   * Adds a component to the entity
420
   * @param component Component or Entity to add copy of components from
421
   * @param force Optionally overwrite any existing components of the same type
422
   */
423
  public addComponent<TComponent extends Component>(component: TComponent, force: boolean = false): Entity<TKnownComponents | TComponent> {
29,524✔
424
    // if component already exists, skip if not forced
425
    if (this.has(component.constructor as ComponentCtor)) {
29,549✔
426
      if (force) {
3,658✔
427
        // Remove existing component type if exists when forced
428
        this.removeComponent(component.constructor as ComponentCtor, true);
7✔
429
      } else {
430
        // early exit component exits
431
        return this as Entity<TKnownComponents | TComponent>;
3,651✔
432
      }
433
    }
434

435
    // TODO circular dependencies will be a problem
436
    if (component.dependencies && component.dependencies.length) {
25,898✔
437
      for (const ctor of component.dependencies) {
1,833✔
438
        this.addComponent(new ctor());
3,665✔
439
      }
440
    }
441

442
    component.owner = this;
25,898✔
443
    const rootComponent = this._getClassHierarchyRoot(component.constructor as ComponentCtor);
25,898✔
444
    this.components.set(rootComponent, component);
25,898✔
445
    this.components.set(component.constructor, component);
25,898✔
446
    this.componentValues.push(component);
25,898✔
447
    if (component.onAdd) {
25,898✔
448
      component.onAdd(this);
10,170✔
449
    }
450

451
    this.componentAdded$.notifyAll(component);
25,898✔
452
    return this as Entity<TKnownComponents | TComponent>;
25,898✔
453
  }
454

455
  /**
456
   * Removes a component from the entity, by default removals are deferred to the end of entity update to avoid consistency issues
457
   *
458
   * Components can be force removed with the `force` flag, the removal is not deferred and happens immediately
459
   * @param typeOrInstance
460
   * @param force
461
   */
462
  public removeComponent<TComponent extends Component>(
463
    typeOrInstance: ComponentCtor<TComponent> | TComponent,
464
    force = false
19✔
465
  ): Entity<Exclude<TKnownComponents, TComponent>> {
466
    let type: ComponentCtor<TComponent>;
467
    if (isComponentCtor(typeOrInstance)) {
55✔
468
      type = typeOrInstance;
54✔
469
    } else {
470
      type = typeOrInstance.constructor as ComponentCtor<TComponent>;
1✔
471
    }
472

473
    if (force) {
55✔
474
      const componentToRemove = this.components.get(type);
36✔
475
      if (componentToRemove) {
36!
476
        this.componentRemoved$.notifyAll(componentToRemove);
36✔
477
        componentToRemove.owner = undefined;
36✔
478
        if (componentToRemove.onRemove) {
36✔
479
          componentToRemove.onRemove(this);
8✔
480
        }
481
        const componentIndex = this.componentValues.indexOf(componentToRemove);
36✔
482
        if (componentIndex > -1) {
36!
483
          this.componentValues.splice(componentIndex, 1);
36✔
484
        }
485
      }
486

487
      const rootComponent = this._getClassHierarchyRoot(type);
36✔
488
      this.components.delete(rootComponent);
36✔
489
      this.components.delete(type); // remove after the notify to preserve typing
36✔
490
    } else {
491
      this._componentsToRemove.push(type);
19✔
492
    }
493

494
    return this as any;
55✔
495
  }
496

497
  public clearComponents() {
498
    const components = this.types;
2✔
499
    for (const c of components) {
2✔
500
      this.removeComponent(c);
14✔
501
    }
502
  }
503

504
  /**
505
   * @hidden
506
   * @internal
507
   */
508
  public processComponentRemoval() {
509
    for (const type of this._componentsToRemove) {
5,622✔
510
      this.removeComponent(type, true);
18✔
511
    }
512
    this._componentsToRemove.length = 0;
5,622✔
513
  }
514

515
  /**
516
   * Check if a component type exists
517
   * @param type
518
   */
519
  public has<TComponent extends Component>(type: ComponentCtor<TComponent>): boolean {
520
    return this.components.has(type);
52,861✔
521
  }
522

523
  private _isInitialized = false;
7,549✔
524
  private _isAdded = false;
7,549✔
525

526
  /**
527
   * Gets whether the actor is Initialized
528
   */
529
  public get isInitialized(): boolean {
530
    return this._isInitialized;
3,391✔
531
  }
532

533
  public get isAdded(): boolean {
534
    return this._isAdded;
6,186✔
535
  }
536

537
  /**
538
   * Initializes this entity, meant to be called by the Scene before first update not by users of Excalibur.
539
   *
540
   * It is not recommended that internal excalibur methods be overridden, do so at your own risk.
541
   * @internal
542
   */
543
  public _initialize(engine: Engine) {
544
    if (!this.isInitialized) {
3,350✔
545
      this.onInitialize(engine);
1,309✔
546
      this.events.emit('initialize', new InitializeEvent(engine, this));
1,309✔
547
      this._isInitialized = true;
1,309✔
548
    }
549
  }
550

551
  /**
552
   * Adds this Actor, meant to be called by the Scene when Actor is added.
553
   *
554
   * It is not recommended that internal excalibur methods be overridden, do so at your own risk.
555
   * @internal
556
   */
557
  public _add(engine: Engine) {
558
    if (!this.isAdded && this.isActive) {
3,093✔
559
      this.onAdd(engine);
1,271✔
560
      this.events.emit('add', new AddEvent(engine, this));
1,271✔
561
      this._isAdded = true;
1,271✔
562
    }
563
  }
564

565
  /**
566
   * Removes Actor, meant to be called by the Scene when Actor is added.
567
   *
568
   * It is not recommended that internal excalibur methods be overridden, do so at your own risk.
569
   * @internal
570
   */
571
  public _remove(engine: Engine) {
572
    if (this.isAdded && !this.isActive) {
3,093✔
573
      this.onRemove(engine);
5✔
574
      this.events.emit('remove', new RemoveEvent(engine, this));
5✔
575
      this._isAdded = false;
5✔
576
    }
577
  }
578

579
  /**
580
   * It is not recommended that internal excalibur methods be overridden, do so at your own risk.
581
   *
582
   * Internal _preupdate handler for {@apilink onPreUpdate} lifecycle event
583
   * @internal
584
   */
585
  public _preupdate(engine: Engine, elapsed: number): void {
586
    this.events.emit('preupdate', new PreUpdateEvent(engine, elapsed, this));
920✔
587
    this.onPreUpdate(engine, elapsed);
920✔
588
  }
589

590
  /**
591
   * It is not recommended that internal excalibur methods be overridden, do so at your own risk.
592
   *
593
   * Internal _preupdate handler for {@apilink onPostUpdate} lifecycle event
594
   * @internal
595
   */
596
  public _postupdate(engine: Engine, elapsed: number): void {
597
    this.events.emit('postupdate', new PostUpdateEvent(engine, elapsed, this));
920✔
598
    this.onPostUpdate(engine, elapsed);
920✔
599
  }
600

601
  /**
602
   * `onInitialize` is called before the first update of the entity. This method is meant to be
603
   * overridden.
604
   *
605
   * Synonymous with the event handler `.on('initialize', (evt) => {...})`
606
   */
607
  public onInitialize(engine: Engine): void {
608
    // Override me
609
  }
610

611
  /**
612
   * `onAdd` is called when Actor is added to scene. This method is meant to be
613
   * overridden.
614
   *
615
   * Synonymous with the event handler `.on('add', (evt) => {...})`
616
   */
617
  public onAdd(engine: Engine): void {
618
    // Override me
619
  }
620

621
  /**
622
   * `onRemove` is called when Actor is added to scene. This method is meant to be
623
   * overridden.
624
   *
625
   * Synonymous with the event handler `.on('remove', (evt) => {...})`
626
   */
627
  public onRemove(engine: Engine): void {
628
    // Override me
629
  }
630

631
  /**
632
   * Safe to override onPreUpdate lifecycle event handler. Synonymous with `.on('preupdate', (evt) =>{...})`
633
   *
634
   * `onPreUpdate` is called directly before an entity is updated.
635
   */
636
  public onPreUpdate(engine: Engine, elapsed: number): void {
637
    // Override me
638
  }
639

640
  /**
641
   * Safe to override onPostUpdate lifecycle event handler. Synonymous with `.on('postupdate', (evt) =>{...})`
642
   *
643
   * `onPostUpdate` is called directly after an entity is updated.
644
   */
645
  public onPostUpdate(engine: Engine, elapsed: number): void {
646
    // Override me
647
  }
648

649
  /**
650
   *
651
   * Entity update lifecycle, called internally
652
   * @internal
653
   * @param engine
654
   * @param elapsed
655
   */
656
  public update(engine: Engine, elapsed: number): void {
657
    this._initialize(engine);
918✔
658
    this._add(engine);
918✔
659
    this._preupdate(engine, elapsed);
918✔
660
    for (const child of this.children) {
918✔
661
      child.update(engine, elapsed);
×
662
    }
663
    this._postupdate(engine, elapsed);
918✔
664
    this._remove(engine);
918✔
665
  }
666

667
  public emit<TEventName extends EventKey<EntityEvents>>(eventName: TEventName, event: EntityEvents[TEventName]): void;
668
  public emit(eventName: string, event?: any): void;
669
  public emit<TEventName extends EventKey<EntityEvents> | string>(eventName: TEventName, event?: any): void {
670
    this.events.emit(eventName, event);
8✔
671
  }
672

673
  public on<TEventName extends EventKey<EntityEvents>>(eventName: TEventName, handler: Handler<EntityEvents[TEventName]>): Subscription;
674
  public on(eventName: string, handler: Handler<unknown>): Subscription;
675
  public on<TEventName extends EventKey<EntityEvents> | string>(eventName: TEventName, handler: Handler<any>): Subscription {
676
    return this.events.on(eventName, handler);
9✔
677
  }
678

679
  public once<TEventName extends EventKey<EntityEvents>>(eventName: TEventName, handler: Handler<EntityEvents[TEventName]>): Subscription;
680
  public once(eventName: string, handler: Handler<unknown>): Subscription;
681
  public once<TEventName extends EventKey<EntityEvents> | string>(eventName: TEventName, handler: Handler<any>): Subscription {
682
    return this.events.once(eventName, handler);
×
683
  }
684

685
  public off<TEventName extends EventKey<EntityEvents>>(eventName: TEventName, handler: Handler<EntityEvents[TEventName]>): void;
686
  public off(eventName: string, handler: Handler<unknown>): void;
687
  public off(eventName: string): void;
688
  public off<TEventName extends EventKey<EntityEvents> | string>(eventName: TEventName, handler?: Handler<any>): void {
689
    if (handler) {
×
690
      this.events.off(eventName, handler);
×
691
    } else {
692
      this.events.off(eventName);
×
693
    }
694
  }
695
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc