# EventHandle

Class

Source: https://github.com/playcanvas/playcanvas-observer/blob/7b88674dee207b87954eabfb61685546418ad536/src/event-handle.ts#L11

EventHandle manages the binding and unbinding of event listeners. It provides a convenient way
to add, remove, and invoke event handlers associated with specific event names. Each EventHandle
is linked to an 'owner' object, typically an instance of the Events class, allowing for elegant
event management and chaining.

## Constructors

### constructor

```ts
new EventHandle(owner: Events, name: string, fn: HandleEvent)
```

Creates an instance of EventHandle.

**Parameters**

- `owner` ([`Events`](https://api.playcanvas.com/observer/classes/Events.md)): Owner
- `name` (`string`): Name
- `fn` ([`HandleEvent`](https://api.playcanvas.com/observer/types/HandleEvent.md)): Callback function

## Methods

### call

```ts
call(events: Events, ...args: any[]): void
```

Invokes the callback function associated with the event handle. This method directly
triggers the event's callback without the event being emitted by the event system.

**Parameters**

- `events` ([`Events`](https://api.playcanvas.com/observer/classes/Events.md))
- `args` (`any[]`)

### on

```ts
on(name: string, fn: HandleEvent): EventHandle
```

Registers a new event listener on the same owner as the EventHandle. This method allows
chaining additional event listeners to the owner of this event handle.

**Parameters**

- `name` (`string`): Name
- `fn` ([`HandleEvent`](https://api.playcanvas.com/observer/types/HandleEvent.md)): Callback function

**Returns** [`EventHandle`](https://api.playcanvas.com/observer/classes/EventHandle.md): EventHandle

### unbind

```ts
unbind(): void
```

Unbinds the event handle from the owner, effectively removing the event listener. After
calling this method, the event handle will no longer trigger the callback function when the
event is emitted.
