# EventBus

## Content

# Interface: EventBus

The image viewer event bus.
Use the event bus to listen and receive certain specific "events".
Available events are: "before-open", "after-open",  "before-close",  "after-close",  "zoom-changed",  "frame-index-changed",  "animation-started",  "animation-stopped".

## Examples

```javascript
// Listen frame index changes:
viewer.eventBus.on("frame-index-changed", function(args) { console.log("Image frame changed", args); });
```

```javascript
// Listen "after-open" event once:
viewer.eventBus.on("after-open", function(args) { console.log("Image opened", args); }, { once: true });
```

## Methods

### dispatch()

```ts
dispatch(eventName, data): void;
```

Use the dispatch method to raise an event.

#### Parameters

##### eventName

[`EventBusEventName`](../type-aliases/EventBusEventName)

##### data

`any`

#### Returns

`void`

***

### off()

```ts
off(eventName, listener): void;
```

Remove event listener specified by the listener argument for the event specified by the eventName argument.

#### Parameters

##### eventName

[`EventBusEventName`](../type-aliases/EventBusEventName)

##### listener

[`EventBusEventListener`](../type-aliases/EventBusEventListener)

#### Returns

`void`

***

### offAll()

```ts
offAll(eventName): void;
```

Remove all event listeners for the event specified by the eventName argument.

#### Parameters

##### eventName

[`EventBusEventName`](../type-aliases/EventBusEventName)

#### Returns

`void`

***

### on()

```ts
on(
   eventName, 
   listener, 
   options?): void;
```

Listen an event bus event.

#### Parameters

##### eventName

[`EventBusEventName`](../type-aliases/EventBusEventName)

##### listener

[`EventBusEventListener`](../type-aliases/EventBusEventListener)

##### options?

[`EventBusAttachOptions`](../type-aliases/EventBusAttachOptions)

#### Returns

`void`
