A typed event: listeners subscribe with connect and are called with the arguments passed to emit.
Example
const onChange = new Signal<(value: number) => void>();
const connection = onChange.connect((value) => console.log(value));
onChange.emit(1); // logs 1
connection.disconnect();
Methods
connect (callback, order) SignalConnection
Subscribes a listener.
| Name | Type | Default | Description |
|---|---|---|---|
callback |
THandler |
Called with the arguments of every |
|
order |
number | 0 |
Listeners with a higher order run later. Defaults to 0. |
Returns:
| Type | Description |
|---|---|
| SignalConnection |
Unsubscribes the first listener connected with this callback.
| Name | Type | Description |
|---|---|---|
callback |
THandler |
The callback passed to |
Returns:
| Type | Description |
|---|---|
| boolean | false if it was not connected. |
Unsubscribes every listener.
Calls every enabled listener.
| Name | Type | Description |
|---|---|---|
args |
Parameters<THandler> |
Passed to each listener. |
Returns:
| Type | Description |
|---|---|
| number | The number of connected listeners. |
Returns:
| Type | Description |
|---|---|
| boolean | true if at least one listener is connected. |