# utils/emittermixin

module

<a id="interfaces">

## Interfaces

<a id="interface-CallbackOptions">

### `CallbackOptions`

<a id="interface-Emitter">

### `Emitter`

<a id="interface-EmitterMixinDelegateChain">

### `EmitterMixinDelegateChain`

<a id="type-definitions">

## Type Definitions

<a id="typedef-BaseEvent">

### `BaseEvent`

<a id="typedef-EmitterMixinConstructor">

### `EmitterMixinConstructor`

<a id="typedef-GetCallback">

### `GetCallback`

<a id="typedef-GetCallbackOptions">

### `GetCallbackOptions`

<a id="typedef-GetEventInfo">

### `GetEventInfo`

<a id="typedef-GetNameOrEventInfo">

### `GetNameOrEventInfo`

<a id="functions">

## Functions

<a id="function-EmitterMixin:EXTENDS">

### `EmitterMixin( base ) → EmitterMixinConstructor<Base>`

Mixin that injects the [events API](module_utils_emittermixin-Emitter.md) into its host.

This function creates a class that inherits from the provided `base` and implements `Emitter` interface.

```typescript
class BaseClass { ... }

class MyClass extends EmitterMixin( BaseClass ) {
	// This class derives from `BaseClass` and implements the `Emitter` interface.
}
```

Read more about the concept of emitters in the:

* [Event system and observables](../framework/architecture/core-editor-architecture.md#event-system-and-observables) section of the [Core editor architecture](../framework/architecture/core-editor-architecture.md) guide.
* [Event system](../framework/deep-dive/event-system.md) deep-dive guide.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L62)

#### Type parameters

* `Base: extends Constructor`

#### Parameters

* `base: Base`

#### Returns

* `EmitterMixinConstructor<Base>`

<a id="function-EmitterMixin:NO_ARGUMENTS">

### `EmitterMixin() → EmitterMixinConstructor`

Mixin that injects the [events API](module_utils_emittermixin-Emitter.md) into its host.

This function creates a class that implements `Emitter` interface.

```typescript
class MyClass extends EmitterMixin() {
	// This class implements the `Emitter` interface.
}
```

Read more about the concept of emitters in the:

* [Event system and observables](../framework/architecture/core-editor-architecture.md#event-system-and-observables) section of the [Core editor architecture](../framework/architecture/core-editor-architecture.md) guide.
* [Event system](../framework/deep-dive/event-system.md) deep dive guide.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L82)

#### Returns

* `EmitterMixinConstructor`

<a id="function-_getEmitterId">

### `_getEmitterId( emitter ) → string | undefined` _(internal)_

Returns emitter's unique id.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L710)

#### Parameters

* `emitter: Emitter`

  An emitter which id will be returned.

#### Returns

* `string | undefined`

<a id="function-_getEmitterListenedTo">

### `_getEmitterListenedTo( listeningEmitter, listenedToEmitterId ) → Emitter | null` _(internal)_

Checks if `listeningEmitter` listens to an emitter with given `listenedToEmitterId` and if so, returns that emitter. If not, returns `null`.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L680)

#### Parameters

* `listeningEmitter: Emitter`

  An emitter that listens.

* `listenedToEmitterId: string`

  Unique emitter id of emitter listened to.

#### Returns

* `Emitter | null`

<a id="function-_setEmitterId">

### `_setEmitterId( emitter, id? ) → void` _(internal)_

Sets emitter's unique id.

**Note:** `_emitterId` can be set only once.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L698)

#### Parameters

* `emitter: Emitter`

  An emitter for which id will be set.

* `id?: string`

  Unique id to set. If not passed, random unique id will be set.

#### Returns

* `void`

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
