File tree Expand file tree Collapse file tree 4 files changed +15
-11
lines changed Expand file tree Collapse file tree 4 files changed +15
-11
lines changed Original file line number Diff line number Diff line change
1
+ import AbstractEvent from 'shared/AbstractEvent' ;
2
+
3
+ type CallbackFunction = ( event : AbstractEvent < unknown > ) => void ;
4
+
5
+ interface Callback {
6
+ [ key : string ] : CallbackFunction [ ] ;
7
+ }
8
+
1
9
/**
2
10
* The Emitter is a simple emitter class that provides you with `on()`, `off()` and `trigger()` methods
3
11
* @class Emitter
4
12
* @module Emitter
5
13
*/
6
14
export default class Emitter {
7
- constructor ( ) {
8
- this . callbacks = { } ;
9
- }
15
+ public callbacks : Callback = { } ;
10
16
11
17
/**
12
18
* Registers callbacks by event name
13
19
* @param {String } type
14
20
* @param {...Function } callbacks
15
21
*/
16
- on ( type , ...callbacks ) {
22
+ on ( type : string , ...callbacks : CallbackFunction [ ] ) {
17
23
if ( ! this . callbacks [ type ] ) {
18
24
this . callbacks [ type ] = [ ] ;
19
25
}
@@ -28,7 +34,7 @@ export default class Emitter {
28
34
* @param {String } type
29
35
* @param {Function } callback
30
36
*/
31
- off ( type , callback ) {
37
+ off ( type : string , callback : CallbackFunction ) {
32
38
if ( ! this . callbacks [ type ] ) {
33
39
return null ;
34
40
}
@@ -48,7 +54,7 @@ export default class Emitter {
48
54
* Triggers event callbacks by event object
49
55
* @param {AbstractEvent } event
50
56
*/
51
- trigger ( event ) {
57
+ trigger ( event : AbstractEvent < unknown > ) {
52
58
if ( ! this . callbacks [ event . type ] ) {
53
59
return null ;
54
60
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ export { default } from './Emitter' ;
Original file line number Diff line number Diff line change @@ -2,10 +2,10 @@ import AbstractEvent from 'shared/AbstractEvent';
2
2
3
3
import Emitter from '../Emitter' ;
4
4
5
- class TestEvent extends AbstractEvent { }
5
+ class TestEvent extends AbstractEvent < unknown > { }
6
6
7
7
describe ( 'Emitter' , ( ) => {
8
- let emitter ;
8
+ let emitter : Emitter ;
9
9
10
10
beforeEach ( ( ) => {
11
11
emitter = new Emitter ( ) ;
You can’t perform that action at this time.
0 commit comments