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

excaliburjs / Excalibur / 16730880992

04 Aug 2025 06:15PM UTC coverage: 87.948% (-0.03%) from 87.973%
16730880992

push

github

web-flow
Merge pull request #3492 from excaliburjs/fix/remove-unadded-entity-warning

removes unadded entity warning

5149 of 7137 branches covered (72.15%)

1 of 2 new or added lines in 2 files covered. (50.0%)

2 existing lines in 1 file now uncovered.

13945 of 15856 relevant lines covered (87.95%)

24789.11 hits per line

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

90.58
/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 = {
119✔
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 {
119✔
94
  private static _ID = 0;
95
  /**
96
   * The unique identifier for the entity
97
   */
98
  public id: number = Entity._ID++;
7,536✔
99

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

102
  /**
103
   * Listen to or emit events for an entity
104
   */
105
  public events = new EventEmitter<EntityEvents>();
7,536✔
106
  private _tags = new Set<string>();
7,536✔
107
  public componentAdded$ = new Observable<Component>();
7,536✔
108
  public componentRemoved$ = new Observable<Component>();
7,536✔
109
  public tagAdded$ = new Observable<string>();
7,536✔
110
  public tagRemoved$ = new Observable<string>();
7,536✔
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,536✔
119
  public componentValues: Component[] = [];
7,536✔
120
  private _componentsToRemove: ComponentCtor[] = [];
7,536✔
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,536✔
129
      componentsToAdd = componentsOrOptions;
2,934✔
130
      nameToAdd = name;
2,934✔
131
    } else if (componentsOrOptions && typeof componentsOrOptions === 'object') {
4,602!
NEW
132
      const { components, name } = componentsOrOptions;
×
UNCOV
133
      componentsToAdd = components ?? [];
×
UNCOV
134
      nameToAdd = name;
×
135
    }
136
    if (nameToAdd) {
7,536✔
137
      this.name = nameToAdd;
10✔
138
    }
139
    if (componentsToAdd) {
7,536✔
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,536✔
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,536✔
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;
30✔
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,022✔
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);
58✔
209
    this.tagAdded$.notifyAll(tag);
58✔
210
    return this;
58✔
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);
4✔
221
    this.tagRemoved$.notifyAll(tag);
4✔
222
    return this;
4✔
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++) {
13✔
258
      if (!this.tags.has(requiredTags[i])) {
26✔
259
        return false;
2✔
260
      }
261
    }
262
    return true;
11✔
263
  }
264

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

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

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

277
  private _children: Entity[] = [];
7,536✔
278
  /**
279
   * Get the direct children of this entity
280
   */
281
  public get children(): readonly Entity[] {
282
    return this._children;
20,001✔
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
   * Adds an entity to be a child of this entity
297
   * @param entity
298
   */
299
  public addChild(entity: Entity): Entity {
300
    if (entity.parent === null) {
2,969✔
301
      if (this.getAncestors().includes(entity)) {
2,968✔
302
        throw new Error('Cycle detected, cannot add entity');
1✔
303
      }
304
      this._children.push(entity);
2,967✔
305
      entity._parent = this;
2,967✔
306
      this.childrenAdded$.notifyAll(entity);
2,967✔
307
    } else {
308
      throw new Error('Entity already has a parent, cannot add without unparenting');
1✔
309
    }
310
    return this;
2,967✔
311
  }
312

313
  /**
314
   * Remove an entity from children if it exists
315
   * @param entity
316
   */
317
  public removeChild(entity: Entity): Entity {
318
    if (entity.parent === this) {
22!
319
      removeItemFromArray(entity, this._children);
22✔
320
      entity._parent = null;
22✔
321
      this.childrenRemoved$.notifyAll(entity);
22✔
322
    }
323
    return this;
22✔
324
  }
325

326
  /**
327
   * Removes all children from this entity
328
   */
329
  public removeAllChildren(): Entity {
330
    // Avoid modifying the array issue by walking backwards
331
    for (let i = this.children.length - 1; i >= 0; i--) {
1✔
332
      this.removeChild(this.children[i]);
6✔
333
    }
334
    return this;
1✔
335
  }
336

337
  /**
338
   * Returns a list of parent entities starting with the topmost parent. Includes the current entity.
339
   */
340
  public getAncestors(): Entity[] {
341
    const result: Entity[] = [this];
7,808✔
342
    let current = this.parent;
7,808✔
343
    while (current) {
7,808✔
344
      result.push(current);
2,052✔
345
      current = current.parent;
2,052✔
346
    }
347
    return result.reverse();
7,808✔
348
  }
349

350
  /**
351
   * Returns a list of all the entities that descend from this entity. Includes the current entity.
352
   */
353
  public getDescendants(): Entity[] {
354
    let result: Entity[] = [this];
1✔
355
    let queue: Entity[] = [this];
1✔
356
    while (queue.length > 0) {
1✔
357
      const curr = queue.pop();
3✔
358
      if (curr) {
3!
359
        queue = queue.concat(curr.children);
3✔
360
        result = result.concat(curr.children);
3✔
361
      }
362
    }
363
    return result;
1✔
364
  }
365

366
  /**
367
   * Creates a deep copy of the entity and a copy of all its components
368
   */
369
  public clone(): Entity {
370
    const newEntity = new Entity();
10✔
371
    for (const c of this.types) {
10✔
372
      const componentInstance = this.get(c);
14✔
373
      if (componentInstance) {
14!
374
        newEntity.addComponent(componentInstance.clone());
14✔
375
      }
376
    }
377
    for (const child of this.children) {
10✔
378
      newEntity.addChild(child.clone());
2✔
379
    }
380
    return newEntity;
10✔
381
  }
382

383
  /**
384
   * Adds a copy of all the components from another template entity as a "prefab"
385
   * @param templateEntity Entity to use as a template
386
   * @param force Force component replacement if it already exists on the target entity
387
   */
388
  public addTemplate(templateEntity: Entity, force: boolean = false): Entity {
3✔
389
    for (const c of templateEntity.getComponents()) {
3✔
390
      this.addComponent(c.clone(), force);
5✔
391
    }
392
    for (const child of templateEntity.children) {
3✔
393
      this.addChild(child.clone().addTemplate(child));
2✔
394
    }
395
    return this;
3✔
396
  }
397

398
  private _getClassHierarchyRoot(componentType: ComponentCtor): ComponentCtor {
399
    let current = componentType;
25,881✔
400
    let parent = Object.getPrototypeOf(current.prototype)?.constructor;
25,881!
401

402
    while (parent && parent !== Object && parent !== Component) {
25,881✔
403
      current = parent;
2✔
404
      parent = Object.getPrototypeOf(current.prototype)?.constructor;
2!
405
    }
406
    return current;
25,881✔
407
  }
408

409
  /**
410
   * Adds a component to the entity
411
   * @param component Component or Entity to add copy of components from
412
   * @param force Optionally overwrite any existing components of the same type
413
   */
414
  public addComponent<TComponent extends Component>(component: TComponent, force: boolean = false): Entity<TKnownComponents | TComponent> {
29,455✔
415
    // if component already exists, skip if not forced
416
    if (this.has(component.constructor as ComponentCtor)) {
29,480✔
417
      if (force) {
3,638✔
418
        // Remove existing component type if exists when forced
419
        this.removeComponent(component.constructor as ComponentCtor, true);
7✔
420
      } else {
421
        // early exit component exits
422
        return this as Entity<TKnownComponents | TComponent>;
3,631✔
423
      }
424
    }
425

426
    // TODO circular dependencies will be a problem
427
    if (component.dependencies && component.dependencies.length) {
25,849✔
428
      for (const ctor of component.dependencies) {
1,823✔
429
        this.addComponent(new ctor());
3,645✔
430
      }
431
    }
432

433
    component.owner = this;
25,849✔
434
    const rootComponent = this._getClassHierarchyRoot(component.constructor as ComponentCtor);
25,849✔
435
    this.components.set(rootComponent, component);
25,849✔
436
    this.components.set(component.constructor, component);
25,849✔
437
    this.componentValues.push(component);
25,849✔
438
    if (component.onAdd) {
25,849✔
439
      component.onAdd(this);
10,150✔
440
    }
441

442
    this.componentAdded$.notifyAll(component);
25,849✔
443
    return this as Entity<TKnownComponents | TComponent>;
25,849✔
444
  }
445

446
  /**
447
   * Removes a component from the entity, by default removals are deferred to the end of entity update to avoid consistency issues
448
   *
449
   * Components can be force removed with the `force` flag, the removal is not deferred and happens immediately
450
   * @param typeOrInstance
451
   * @param force
452
   */
453
  public removeComponent<TComponent extends Component>(
454
    typeOrInstance: ComponentCtor<TComponent> | TComponent,
455
    force = false
20✔
456
  ): Entity<Exclude<TKnownComponents, TComponent>> {
457
    let type: ComponentCtor<TComponent>;
458
    if (isComponentCtor(typeOrInstance)) {
52✔
459
      type = typeOrInstance;
51✔
460
    } else {
461
      type = typeOrInstance.constructor as ComponentCtor<TComponent>;
1✔
462
    }
463

464
    if (force) {
52✔
465
      const componentToRemove = this.components.get(type);
32✔
466
      if (componentToRemove) {
32!
467
        this.componentRemoved$.notifyAll(componentToRemove);
32✔
468
        componentToRemove.owner = undefined;
32✔
469
        if (componentToRemove.onRemove) {
32✔
470
          componentToRemove.onRemove(this);
8✔
471
        }
472
        const componentIndex = this.componentValues.indexOf(componentToRemove);
32✔
473
        if (componentIndex > -1) {
32!
474
          this.componentValues.splice(componentIndex, 1);
32✔
475
        }
476
      }
477

478
      const rootComponent = this._getClassHierarchyRoot(type);
32✔
479
      this.components.delete(rootComponent);
32✔
480
      this.components.delete(type); // remove after the notify to preserve typing
32✔
481
    } else {
482
      this._componentsToRemove.push(type);
20✔
483
    }
484

485
    return this as any;
52✔
486
  }
487

488
  public clearComponents() {
489
    const components = this.types;
2✔
490
    for (const c of components) {
2✔
491
      this.removeComponent(c);
14✔
492
    }
493
  }
494

495
  /**
496
   * @hidden
497
   * @internal
498
   */
499
  public processComponentRemoval() {
500
    for (const type of this._componentsToRemove) {
5,628✔
501
      this.removeComponent(type, true);
18✔
502
    }
503
    this._componentsToRemove.length = 0;
5,628✔
504
  }
505

506
  /**
507
   * Check if a component type exists
508
   * @param type
509
   */
510
  public has<TComponent extends Component>(type: ComponentCtor<TComponent>): boolean {
511
    return this.components.has(type);
52,694✔
512
  }
513

514
  private _isInitialized = false;
7,536✔
515
  private _isAdded = false;
7,536✔
516

517
  /**
518
   * Gets whether the actor is Initialized
519
   */
520
  public get isInitialized(): boolean {
521
    return this._isInitialized;
3,397✔
522
  }
523

524
  public get isAdded(): boolean {
525
    return this._isAdded;
6,192✔
526
  }
527

528
  /**
529
   * Initializes this entity, meant to be called by the Scene before first update not by users of Excalibur.
530
   *
531
   * It is not recommended that internal excalibur methods be overridden, do so at your own risk.
532
   * @internal
533
   */
534
  public _initialize(engine: Engine) {
535
    if (!this.isInitialized) {
3,353✔
536
      this.onInitialize(engine);
1,309✔
537
      this.events.emit('initialize', new InitializeEvent(engine, this));
1,309✔
538
      this._isInitialized = true;
1,309✔
539
    }
540
  }
541

542
  /**
543
   * Adds this Actor, meant to be called by the Scene when Actor is added.
544
   *
545
   * It is not recommended that internal excalibur methods be overridden, do so at your own risk.
546
   * @internal
547
   */
548
  public _add(engine: Engine) {
549
    if (!this.isAdded && this.isActive) {
3,096✔
550
      this.onAdd(engine);
1,271✔
551
      this.events.emit('add', new AddEvent(engine, this));
1,271✔
552
      this._isAdded = true;
1,271✔
553
    }
554
  }
555

556
  /**
557
   * Removes Actor, meant to be called by the Scene when Actor is added.
558
   *
559
   * It is not recommended that internal excalibur methods be overridden, do so at your own risk.
560
   * @internal
561
   */
562
  public _remove(engine: Engine) {
563
    if (this.isAdded && !this.isActive) {
3,096✔
564
      this.onRemove(engine);
5✔
565
      this.events.emit('remove', new RemoveEvent(engine, this));
5✔
566
      this._isAdded = false;
5✔
567
    }
568
  }
569

570
  /**
571
   * It is not recommended that internal excalibur methods be overridden, do so at your own risk.
572
   *
573
   * Internal _preupdate handler for {@apilink onPreUpdate} lifecycle event
574
   * @internal
575
   */
576
  public _preupdate(engine: Engine, elapsed: number): void {
577
    this.events.emit('preupdate', new PreUpdateEvent(engine, elapsed, this));
923✔
578
    this.onPreUpdate(engine, elapsed);
923✔
579
  }
580

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

592
  /**
593
   * `onInitialize` is called before the first update of the entity. This method is meant to be
594
   * overridden.
595
   *
596
   * Synonymous with the event handler `.on('initialize', (evt) => {...})`
597
   */
598
  public onInitialize(engine: Engine): void {
599
    // Override me
600
  }
601

602
  /**
603
   * `onAdd` is called when Actor is added to scene. This method is meant to be
604
   * overridden.
605
   *
606
   * Synonymous with the event handler `.on('add', (evt) => {...})`
607
   */
608
  public onAdd(engine: Engine): void {
609
    // Override me
610
  }
611

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

622
  /**
623
   * Safe to override onPreUpdate lifecycle event handler. Synonymous with `.on('preupdate', (evt) =>{...})`
624
   *
625
   * `onPreUpdate` is called directly before an entity is updated.
626
   */
627
  public onPreUpdate(engine: Engine, elapsed: number): void {
628
    // Override me
629
  }
630

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

640
  /**
641
   *
642
   * Entity update lifecycle, called internally
643
   * @internal
644
   * @param engine
645
   * @param elapsed
646
   */
647
  public update(engine: Engine, elapsed: number): void {
648
    this._initialize(engine);
921✔
649
    this._add(engine);
921✔
650
    this._preupdate(engine, elapsed);
921✔
651
    for (const child of this.children) {
921✔
652
      child.update(engine, elapsed);
×
653
    }
654
    this._postupdate(engine, elapsed);
921✔
655
    this._remove(engine);
921✔
656
  }
657

658
  public emit<TEventName extends EventKey<EntityEvents>>(eventName: TEventName, event: EntityEvents[TEventName]): void;
659
  public emit(eventName: string, event?: any): void;
660
  public emit<TEventName extends EventKey<EntityEvents> | string>(eventName: TEventName, event?: any): void {
661
    this.events.emit(eventName, event);
8✔
662
  }
663

664
  public on<TEventName extends EventKey<EntityEvents>>(eventName: TEventName, handler: Handler<EntityEvents[TEventName]>): Subscription;
665
  public on(eventName: string, handler: Handler<unknown>): Subscription;
666
  public on<TEventName extends EventKey<EntityEvents> | string>(eventName: TEventName, handler: Handler<any>): Subscription {
667
    return this.events.on(eventName, handler);
9✔
668
  }
669

670
  public once<TEventName extends EventKey<EntityEvents>>(eventName: TEventName, handler: Handler<EntityEvents[TEventName]>): Subscription;
671
  public once(eventName: string, handler: Handler<unknown>): Subscription;
672
  public once<TEventName extends EventKey<EntityEvents> | string>(eventName: TEventName, handler: Handler<any>): Subscription {
673
    return this.events.once(eventName, handler);
×
674
  }
675

676
  public off<TEventName extends EventKey<EntityEvents>>(eventName: TEventName, handler: Handler<EntityEvents[TEventName]>): void;
677
  public off(eventName: string, handler: Handler<unknown>): void;
678
  public off(eventName: string): void;
679
  public off<TEventName extends EventKey<EntityEvents> | string>(eventName: TEventName, handler?: Handler<any>): void {
680
    if (handler) {
×
681
      this.events.off(eventName, handler);
×
682
    } else {
683
      this.events.off(eventName);
×
684
    }
685
  }
686
}
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