@adonisjs/events 8.4.1-0 → 8.4.2-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Emitter } from './emitter.js';
|
|
2
2
|
export declare class BaseEvent {
|
|
3
3
|
constructor(..._: any[]);
|
|
4
|
-
static emitter
|
|
4
|
+
static emitter?: Emitter<any>;
|
|
5
5
|
static useEmitter(emitter: Emitter<any>): void;
|
|
6
6
|
static dispatch<T extends typeof BaseEvent>(this: T, ...args: ConstructorParameters<T>): Promise<void>;
|
|
7
7
|
}
|
package/build/src/base_event.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { RuntimeException } from '@poppinss/utils';
|
|
1
2
|
export class BaseEvent {
|
|
2
3
|
constructor(..._) { }
|
|
3
4
|
static emitter;
|
|
4
5
|
static useEmitter(emitter) {
|
|
5
6
|
this.emitter = emitter;
|
|
6
7
|
}
|
|
7
|
-
static dispatch(...args) {
|
|
8
|
+
static async dispatch(...args) {
|
|
9
|
+
if (!this.emitter) {
|
|
10
|
+
throw new RuntimeException(`Cannot dispatch "${this.name}" event. Make sure to pass emitter to the base event for dispatch method to work`);
|
|
11
|
+
}
|
|
8
12
|
return this.emitter.emit(this, new this(...args));
|
|
9
13
|
}
|
|
10
14
|
}
|