Extends
Methods
trigger<Name extends keyof Events>(eventName, paramopt) → {boolean}
- Source:
- Overrides:
Fires an event to call listeners.
Name |
Type |
Default |
Description |
eventName |
Name
|
...
|
|
Event name |
param ? |
TargetParam<any>
|
...
|
{}
|
Event parameter |
trigger<Name extends keyof Events, Param = Events[Name]>(eventName)
→ {boolean}
Name |
Type |
Description |
eventName |
extends TargetParam<Param> ? Name : never
|
|
trigger<Name extends keyof Events, Param = Events[Name]>(eventName, param)
→ {boolean}
Name |
Type |
Description |
eventName |
Name
|
|
param |
TargetParam<Param>
|
|
Example
import EventEmitter from "@scena/event-emitter";
const emitter = new EventEmitter();
emitter.on("a", e => {
});
emitter.emit("a", {
a: 1,
});
Returns:
If false, stop the event.
-
Type
-
boolean
once<Name extends keyof Events & string, Param = Events[Name]>(eventName, listeneropt) → {Promise<OnEvent<Param, this>>}
- Source:
- Inherited From:
Add a disposable listener and Use promise to the registered event.
Name |
Type |
Description |
eventName |
Name
|
Name of the event to be added |
listener ? |
EventListener<Param, this>
|
disposable listener function of the event to be added |
Example
import EventEmitter from "@scena/event-emitter";
cosnt emitter = new EventEmitter();
// Add a disposable listener in "a" event
emitter.once("a", () => {
});
// Use Promise
emitter.once("a").then(e => {
});
Returns:
-
Type
-
Promise<OnEvent<Param, this>>
on(eventName, listeneropt) → {this}
- Source:
- Inherited From:
Add a listener to the registered event.
Name |
Type |
Description |
eventName |
string | object
|
...
|
Name of the event to be added |
listener ? |
EventListener<Events[any], this>
|
...
|
listener function of the event to be added |
on<Name extends keyof Events, Param = Events[Name]>(eventName, listener)
→ {this}
Name |
Type |
Description |
eventName |
Name
|
|
listener |
EventListener<Param, this>
|
|
on(events)
→ {this}
Name |
Type |
Description |
events |
EventHash<Events, this>
|
|
Example
import EventEmitter from "@scena/event-emitter";
cosnt emitter = new EventEmitter();
// Add listener in "a" event
emitter.on("a", () => {
});
// Add listeners
emitter.on({
a: () => {},
b: () => {},
});
Returns:
-
Type
-
this
off(eventNameopt, listeneropt) → {this}
- Source:
- Inherited From:
Remove listeners registered in the event target.
Name |
Type |
Description |
eventName ? |
string | object
|
...
|
Name of the event to be removed |
listener ? |
EventListener<Events[any], this>
|
...
|
listener function of the event to be removed |
off<Name extends keyof Events, Param = Events[Name]>(eventName, listener)
→ {this}
Name |
Type |
Description |
eventName ? |
Name
|
|
listener ? |
EventListener<Param, this>
|
|
off(events)
→ {this}
Name |
Type |
Description |
events |
EventHash<Events, this>
|
|
Example
import EventEmitter from "@scena/event-emitter";
cosnt emitter = new EventEmitter();
// Remove all listeners.
emitter.off();
// Remove all listeners in "A" event.
emitter.off("a");
// Remove "listener" listener in "a" event.
emitter.off("a", listener);
Returns:
-
Type
-
this
emit(eventName, paramopt) → {boolean}
- Source:
- Inherited From:
Fires an event to call listeners.
Name |
Type |
Default |
Description |
eventName |
string
|
...
|
|
Event name |
param ? |
TargetParam<any>
|
...
|
{}
|
Event parameter |
emit<Name extends keyof Events, Param = Events[Name]>(eventName)
→ {boolean}
Name |
Type |
Description |
eventName |
extends Param ? Name : never
|
|
emit<Name extends keyof Events, Param = Events[Name]>(eventName, param)
→ {boolean}
Name |
Type |
Description |
eventName |
Name
|
|
param |
TargetParam<Param>
|
|
Example
import EventEmitter from "@scena/event-emitter";
const emitter = new EventEmitter();
emitter.on("a", e => {
});
emitter.emit("a", {
a: 1,
});
Returns:
If false, stop the event.
-
Type
-
boolean
dragStart(e, options)
- Source:
dragEnd()
- Source:
- Source:
Events
move
- Source:
- Source: