events-ex 2.0.0-alpha.7 → 2.0.0-alpha.9

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [2.0.0-alpha.9](https://github.com/snowyu/events-ex.js/compare/v2.0.0-alpha.8...v2.0.0-alpha.9) (2024-03-26)
6
+
7
+
8
+ ### Features
9
+
10
+ * add type(event) to Event(this) for listener ([42b35e7](https://github.com/snowyu/events-ex.js/commit/42b35e75bf224b79d3b967469a7beb4f5aa120d1))
11
+
12
+ ## [2.0.0-alpha.8](https://github.com/snowyu/events-ex.js/compare/v2.0.0-alpha.7...v2.0.0-alpha.8) (2024-03-20)
13
+
14
+
15
+ ### Features
16
+
17
+ * add eventName to the notify error event ([da3be72](https://github.com/snowyu/events-ex.js/commit/da3be7238689da19589e4d3a104d57b749d8a771))
18
+
5
19
  ## [2.0.0-alpha.7](https://github.com/snowyu/events-ex.js/compare/v2.0.0-alpha.6...v2.0.0-alpha.7) (2024-03-20)
6
20
 
7
21
 
package/README.cn.md CHANGED
@@ -40,7 +40,7 @@ TODO: 异步事件,添加`emitAsync`方法. 没这么简单,因为要支持bubbl
40
40
  * 添加了 `listenerCount()` 类方法,以保持与 Node 事件模块的兼容性。
41
41
  * 添加了`emitAsync`方法,支持异步事件
42
42
 
43
- 注意: 时间内部引发错误不会中断通知,但是会在通知结束时 emit 错误事件(`emit('error', error, 'notify', listener, args)`)
43
+ 注意: 时间内部引发错误不会中断通知,但是会在通知结束时 emit 错误事件(`emit('error', error, 'notify', eventName, listener, args)`)
44
44
 
45
45
  ### 安装
46
46
 
package/README.md CHANGED
@@ -31,7 +31,7 @@ Browser-friendly enhanced event emitter [ability][Ability] and class. It's modif
31
31
  + Adds listenerCount() class method to keep compatibility with node events.
32
32
  * Adds async event emitting via `emitAsync` method.
33
33
 
34
- Note: The listener throw error should not broke the notification, but it will emit error(`emit('error', error, 'notify', listener, args)`) after notification.
34
+ Note: The listener throw error should not broke the notification, but it will emit error(`emit('error', error, 'notify', eventName, listener, args)`) after notification.
35
35
 
36
36
  ### Installation
37
37
 
package/docs/README.md CHANGED
@@ -32,7 +32,7 @@ Browser-friendly enhanced event emitter [ability][Ability] and class. It's modif
32
32
  + Adds listenerCount() class method to keep compatibility with node events.
33
33
  * Adds async event emitting via `emitAsync` method.
34
34
 
35
- Note: The listener throw error should not broke the notification, but it will emit error(`emit('error', error, 'notify', listener, args)`) after notification.
35
+ Note: The listener throw error should not broke the notification, but it will emit error(`emit('error', error, 'notify', eventName, listener, args)`) after notification.
36
36
 
37
37
  ### Installation
38
38
 
@@ -15,6 +15,7 @@
15
15
  - [result](event.Event.md#result)
16
16
  - [stopped](event.Event.md#stopped)
17
17
  - [target](event.Event.md#target)
18
+ - [type](event.Event.md#type)
18
19
 
19
20
  ### Methods
20
21
 
@@ -25,7 +26,7 @@
25
26
 
26
27
  ### constructor
27
28
 
28
- • **new Event**(`target`): [`Event`](event.Event.md)
29
+ • **new Event**(`target`, `type`): [`Event`](event.Event.md)
29
30
 
30
31
  Creates a new Event object instance that contains information about the event, such as the target element and the return value of the event.
31
32
 
@@ -34,6 +35,7 @@ Creates a new Event object instance that contains information about the event, s
34
35
  | Name | Type | Description |
35
36
  | :------ | :------ | :------ |
36
37
  | `target` | [`EventEmitter`](event_emitter.EventEmitter.md) | Who trigger the event |
38
+ | `type` | `any` | - |
37
39
 
38
40
  #### Returns
39
41
 
@@ -47,7 +49,7 @@ Event Object that contains information about the event, such as the target eleme
47
49
 
48
50
  #### Defined in
49
51
 
50
- [src/event.js:8](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/event.js#L8)
52
+ [src/event.js:8](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event.js#L8)
51
53
 
52
54
  ## Properties
53
55
 
@@ -59,7 +61,7 @@ Keep your event result here if any.
59
61
 
60
62
  #### Defined in
61
63
 
62
- [src/event.js:38](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/event.js#L38)
64
+ [src/event.js:38](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event.js#L38)
63
65
 
64
66
  ___
65
67
 
@@ -71,7 +73,7 @@ Whether stop the bubbling event
71
73
 
72
74
  #### Defined in
73
75
 
74
- [src/event.js:32](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/event.js#L32)
76
+ [src/event.js:32](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event.js#L32)
75
77
 
76
78
  ___
77
79
 
@@ -83,7 +85,17 @@ Who trigger the event
83
85
 
84
86
  #### Defined in
85
87
 
86
- [src/event.js:26](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/event.js#L26)
88
+ [src/event.js:26](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event.js#L26)
89
+
90
+ ___
91
+
92
+ ### type
93
+
94
+ • **type**: `any`
95
+
96
+ #### Defined in
97
+
98
+ [src/event.js:44](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event.js#L44)
87
99
 
88
100
  ## Methods
89
101
 
@@ -101,13 +113,13 @@ The result of the event.
101
113
 
102
114
  #### Defined in
103
115
 
104
- [src/event.js:45](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/event.js#L45)
116
+ [src/event.js:51](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event.js#L51)
105
117
 
106
118
  ___
107
119
 
108
120
  ### init
109
121
 
110
- ▸ **init**(`target`): `void`
122
+ ▸ **init**(`target`, `type`): `void`
111
123
 
112
124
  Initializes the event with the target object.
113
125
 
@@ -116,6 +128,7 @@ Initializes the event with the target object.
116
128
  | Name | Type | Description |
117
129
  | :------ | :------ | :------ |
118
130
  | `target` | [`EventEmitter`](event_emitter.EventEmitter.md) | The target object for the event. |
131
+ | `type` | `any` | - |
119
132
 
120
133
  #### Returns
121
134
 
@@ -123,4 +136,4 @@ Initializes the event with the target object.
123
136
 
124
137
  #### Defined in
125
138
 
126
- [src/event.js:20](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/event.js#L20)
139
+ [src/event.js:20](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event.js#L20)
@@ -26,4 +26,4 @@ Class that represents an event emitter.
26
26
 
27
27
  #### Defined in
28
28
 
29
- [src/event-emitter.js:7](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/event-emitter.js#L7)
29
+ [src/event-emitter.js:7](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event-emitter.js#L7)
@@ -47,7 +47,7 @@ Class that represents an event emitter.
47
47
 
48
48
  #### Defined in
49
49
 
50
- [src/event-emitter.d.ts:7](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/event-emitter.d.ts#L7)
50
+ [src/event-emitter.d.ts:7](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event-emitter.d.ts#L7)
51
51
 
52
52
  ## Methods
53
53
 
@@ -72,7 +72,7 @@ The result of the event.
72
72
 
73
73
  #### Defined in
74
74
 
75
- [src/event-emitter.d.ts:38](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/event-emitter.d.ts#L38)
75
+ [src/event-emitter.d.ts:38](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event-emitter.d.ts#L38)
76
76
 
77
77
  ___
78
78
 
@@ -97,7 +97,7 @@ A promise that resolves with the result of the event.
97
97
 
98
98
  #### Defined in
99
99
 
100
- [src/event-emitter.d.ts:44](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/event-emitter.d.ts#L44)
100
+ [src/event-emitter.d.ts:44](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event-emitter.d.ts#L44)
101
101
 
102
102
  ___
103
103
 
@@ -121,7 +121,7 @@ Returns the count of listeners that are registered to listen for the specified e
121
121
 
122
122
  #### Defined in
123
123
 
124
- [src/event-emitter.d.ts:66](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/event-emitter.d.ts#L66)
124
+ [src/event-emitter.d.ts:66](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event-emitter.d.ts#L66)
125
125
 
126
126
  ___
127
127
 
@@ -145,7 +145,7 @@ Returns an array of functions that are registered to listen for the specified ev
145
145
 
146
146
  #### Defined in
147
147
 
148
- [src/event-emitter.d.ts:59](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/event-emitter.d.ts#L59)
148
+ [src/event-emitter.d.ts:59](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event-emitter.d.ts#L59)
149
149
 
150
150
  ___
151
151
 
@@ -174,7 +174,7 @@ If the listener is not a function.
174
174
 
175
175
  #### Defined in
176
176
 
177
- [src/event-emitter.d.ts:32](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/event-emitter.d.ts#L32)
177
+ [src/event-emitter.d.ts:32](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event-emitter.d.ts#L32)
178
178
 
179
179
  ___
180
180
 
@@ -203,7 +203,7 @@ If the listener is not a function.
203
203
 
204
204
  #### Defined in
205
205
 
206
- [src/event-emitter.d.ts:16](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/event-emitter.d.ts#L16)
206
+ [src/event-emitter.d.ts:16](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event-emitter.d.ts#L16)
207
207
 
208
208
  ___
209
209
 
@@ -232,7 +232,7 @@ If the listener is not a function.
232
232
 
233
233
  #### Defined in
234
234
 
235
- [src/event-emitter.d.ts:24](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/event-emitter.d.ts#L24)
235
+ [src/event-emitter.d.ts:24](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event-emitter.d.ts#L24)
236
236
 
237
237
  ___
238
238
 
@@ -256,7 +256,7 @@ Removes all listeners for a specific event or all events from an event emitter.
256
256
 
257
257
  #### Defined in
258
258
 
259
- [src/event-emitter.d.ts:51](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/event-emitter.d.ts#L51)
259
+ [src/event-emitter.d.ts:51](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event-emitter.d.ts#L51)
260
260
 
261
261
  ___
262
262
 
@@ -276,7 +276,7 @@ ___
276
276
 
277
277
  #### Defined in
278
278
 
279
- [src/event-emitter.d.ts:52](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/event-emitter.d.ts#L52)
279
+ [src/event-emitter.d.ts:52](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event-emitter.d.ts#L52)
280
280
 
281
281
  ___
282
282
 
@@ -297,4 +297,4 @@ ___
297
297
 
298
298
  #### Defined in
299
299
 
300
- [src/event-emitter.d.ts:67](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/event-emitter.d.ts#L67)
300
+ [src/event-emitter.d.ts:67](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/event-emitter.d.ts#L67)
@@ -41,4 +41,4 @@ Removes all listeners for a specific event or all events from an event emitter.
41
41
 
42
42
  #### Defined in
43
43
 
44
- [src/all-off.js:12](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/all-off.js#L12)
44
+ [src/all-off.js:12](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/all-off.js#L12)
@@ -25,4 +25,4 @@
25
25
 
26
26
  #### Defined in
27
27
 
28
- [src/consts.js:6](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/consts.js#L6)
28
+ [src/consts.js:6](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/consts.js#L6)
@@ -48,4 +48,4 @@ Renames and re-exports [getEventableMethods](default_methods.md#geteventablemeth
48
48
 
49
49
  #### Defined in
50
50
 
51
- [src/default-methods.js:8](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/default-methods.js#L8)
51
+ [src/default-methods.js:8](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/default-methods.js#L8)
@@ -37,4 +37,4 @@ Renames and re-exports [hasListeners](has_listeners.md#haslisteners)
37
37
 
38
38
  #### Defined in
39
39
 
40
- [src/has-listeners.js:10](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/has-listeners.js#L10)
40
+ [src/has-listeners.js:10](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/has-listeners.js#L10)
@@ -46,4 +46,4 @@ Creates a pipeline between two event emitters, so that any events emitted by the
46
46
 
47
47
  #### Defined in
48
48
 
49
- [src/pipe.js:21](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/pipe.js#L21)
49
+ [src/pipe.js:21](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/pipe.js#L21)
@@ -46,4 +46,4 @@ Creates a pipeline between two event emitters, so that any events emitted by the
46
46
 
47
47
  #### Defined in
48
48
 
49
- [src/pipe-async.js:21](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/pipe-async.js#L21)
49
+ [src/pipe-async.js:21](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/pipe-async.js#L21)
@@ -43,4 +43,4 @@ Unifies the event listeners of two event emitter objects so that they share the
43
43
 
44
44
  #### Defined in
45
45
 
46
- [src/unify.js:17](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/unify.js#L17)
46
+ [src/unify.js:17](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/unify.js#L17)
@@ -36,4 +36,4 @@ Renames and re-exports [remove](util_array_remove.md#remove)
36
36
 
37
37
  #### Defined in
38
38
 
39
- [src/util/array-remove.js:5](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/util/array-remove.js#L5)
39
+ [src/util/array-remove.js:5](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/util/array-remove.js#L5)
@@ -38,4 +38,4 @@ Renames and re-exports [forEach](util_object_for_each.md#foreach)
38
38
 
39
39
  #### Defined in
40
40
 
41
- [src/util/object-for-each.js:6](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/util/object-for-each.js#L6)
41
+ [src/util/object-for-each.js:6](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/util/object-for-each.js#L6)
@@ -37,4 +37,4 @@ Renames and re-exports [pad](util_string_pad.md#pad)
37
37
 
38
38
  #### Defined in
39
39
 
40
- [src/util/string-pad.js:8](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/util/string-pad.js#L8)
40
+ [src/util/string-pad.js:8](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/util/string-pad.js#L8)
@@ -36,4 +36,4 @@ Renames and re-exports [toInt](util_to_int.md#toint)
36
36
 
37
37
  #### Defined in
38
38
 
39
- [src/util/to-int.js:2](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/util/to-int.js#L2)
39
+ [src/util/to-int.js:2](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/util/to-int.js#L2)
@@ -36,4 +36,4 @@ Renames and re-exports [validCallable](util_valid_callable.md#validcallable)
36
36
 
37
37
  #### Defined in
38
38
 
39
- [src/util/valid-callable.js:1](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/util/valid-callable.js#L1)
39
+ [src/util/valid-callable.js:1](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/util/valid-callable.js#L1)
@@ -36,4 +36,4 @@ Renames and re-exports [validObject](util_valid_object.md#validobject)
36
36
 
37
37
  #### Defined in
38
38
 
39
- [src/util/valid-object.js:3](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/util/valid-object.js#L3)
39
+ [src/util/valid-object.js:3](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/util/valid-object.js#L3)
@@ -30,7 +30,7 @@ Renames and re-exports [wrapEventEmitter](wrap_event_emitter.md#wrapeventemitter
30
30
 
31
31
  #### Defined in
32
32
 
33
- [src/wrap-event-emitter.js:6](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/wrap-event-emitter.js#L6)
33
+ [src/wrap-event-emitter.js:6](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/wrap-event-emitter.js#L6)
34
34
 
35
35
  ## Functions
36
36
 
@@ -54,4 +54,4 @@ o or new Event instance
54
54
 
55
55
  #### Defined in
56
56
 
57
- [src/wrap-event-emitter.js:33](https://github.com/snowyu/events-ex.js/blob/7dce4f6/src/wrap-event-emitter.js#L33)
57
+ [src/wrap-event-emitter.js:33](https://github.com/snowyu/events-ex.js/blob/42b35e7/src/wrap-event-emitter.js#L33)
@@ -94,7 +94,7 @@ function getEventableMethods(aClass) {
94
94
  }
95
95
  const args = r.args;
96
96
  const listeners = r.listeners;
97
- const evt = (0, _event.Event)(this);
97
+ const evt = (0, _event.Event)(this, r.type);
98
98
  const errs = [];
99
99
  try {
100
100
  let i = 0;
@@ -116,7 +116,7 @@ function getEventableMethods(aClass) {
116
116
  if (errs.length) {
117
117
  for (let i = 0; i < errs.length; i++) {
118
118
  const it = errs[i];
119
- this.emit('error', it.err, 'notify', it.listener, args);
119
+ this.emit('error', it.err, 'notify', r.type, it.listener, args);
120
120
  }
121
121
  }
122
122
  } finally {
@@ -137,7 +137,7 @@ function getEventableMethods(aClass) {
137
137
  }
138
138
  const args = r.args;
139
139
  const listeners = r.listeners;
140
- const evt = (0, _event.Event)(this);
140
+ const evt = (0, _event.Event)(this, r.type);
141
141
  const errs = [];
142
142
  try {
143
143
  for (const listener of listeners) {
@@ -156,7 +156,7 @@ function getEventableMethods(aClass) {
156
156
  if (errs.length) {
157
157
  for (let i = 0; i < errs.length; i++) {
158
158
  const it = errs[i];
159
- this.emit('error', it.err, 'notify', it.listener, args);
159
+ this.emit('error', it.err, 'notify', r.type, it.listener, args);
160
160
  }
161
161
  }
162
162
  } finally {
@@ -329,6 +329,7 @@ function _emit(type, msg) {
329
329
  listeners = listeners.slice();
330
330
  }
331
331
  return {
332
+ type,
332
333
  args,
333
334
  listeners
334
335
  };
package/lib/event.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * @param {import('./event-emitter').EventEmitter} target - Who trigger the event
6
6
  * @returns {Event} - The new Event instance.
7
7
  */
8
- export function Event(target: import('./event-emitter').EventEmitter): Event;
8
+ export function Event(target: import('./event-emitter').EventEmitter, type: any): Event;
9
9
  export class Event {
10
10
  /**
11
11
  * Creates a new Event object instance that contains information about the event, such as the target element and the return value of the event.
@@ -14,12 +14,12 @@ export class Event {
14
14
  * @param {import('./event-emitter').EventEmitter} target - Who trigger the event
15
15
  * @returns {Event} - The new Event instance.
16
16
  */
17
- constructor(target: import('./event-emitter').EventEmitter);
17
+ constructor(target: import('./event-emitter').EventEmitter, type: any);
18
18
  /**
19
19
  * Initializes the event with the target object.
20
20
  * @param {import('./event-emitter').EventEmitter} target - The target object for the event.
21
21
  */
22
- init(target: import('./event-emitter').EventEmitter): void;
22
+ init(target: import('./event-emitter').EventEmitter, type: any): void;
23
23
  /**
24
24
  * Who trigger the event
25
25
  * @type {Object}
@@ -38,6 +38,7 @@ export class Event {
38
38
  * @public
39
39
  */
40
40
  public result: any;
41
+ type: any;
41
42
  /**
42
43
  * Ends the event and returns the result.
43
44
  * @returns {*} The result of the event.
package/lib/event.js CHANGED
@@ -12,19 +12,19 @@ exports.default = void 0;
12
12
  * @param {import('./event-emitter').EventEmitter} target - Who trigger the event
13
13
  * @returns {Event} - The new Event instance.
14
14
  */
15
- function Event(target) {
15
+ function Event(target, type) {
16
16
  if (!(this instanceof Event)) {
17
- const evt = new Event(target);
17
+ const evt = new Event(target, type);
18
18
  return evt;
19
19
  }
20
- this.init(target);
20
+ this.init(target, type);
21
21
  }
22
22
 
23
23
  /**
24
24
  * Initializes the event with the target object.
25
25
  * @param {import('./event-emitter').EventEmitter} target - The target object for the event.
26
26
  */
27
- Event.prototype.init = function (target) {
27
+ Event.prototype.init = function (target, type) {
28
28
  /**
29
29
  * Who trigger the event
30
30
  * @type {Object}
@@ -43,6 +43,12 @@ Event.prototype.init = function (target) {
43
43
  * @public
44
44
  */
45
45
  this.result = undefined;
46
+ /**
47
+ * The type of the event.
48
+ * @type {string}
49
+ * @public
50
+ */
51
+ if (type) this.type = type;
46
52
  };
47
53
 
48
54
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "events-ex",
3
- "version": "2.0.0-alpha.7",
3
+ "version": "2.0.0-alpha.9",
4
4
  "description": "Browser-friendly enhanced events most compatible with standard node.js, it's powerful eventable ability.",
5
5
  "contributors": [
6
6
  {
@@ -91,7 +91,7 @@ export function getEventableMethods(aClass) {
91
91
  if (!r) {return}
92
92
  const args = r.args
93
93
  const listeners = r.listeners
94
- const evt = Event(this)
94
+ const evt = Event(this, r.type)
95
95
  const errs = []
96
96
  try {
97
97
  let i = 0
@@ -108,7 +108,7 @@ export function getEventableMethods(aClass) {
108
108
  if (errs.length) {
109
109
  for (let i=0;i<errs.length;i++) {
110
110
  const it = errs[i]
111
- this.emit('error', it.err, 'notify', it.listener, args)
111
+ this.emit('error', it.err, 'notify', r.type, it.listener, args)
112
112
  }
113
113
  }
114
114
  } finally {
@@ -127,7 +127,7 @@ export function getEventableMethods(aClass) {
127
127
  if (!r) {return}
128
128
  const args = r.args
129
129
  const listeners = r.listeners
130
- const evt = Event(this)
130
+ const evt = Event(this, r.type)
131
131
  const errs = []
132
132
  try {
133
133
  for (const listener of listeners) {
@@ -141,7 +141,7 @@ export function getEventableMethods(aClass) {
141
141
  if (errs.length) {
142
142
  for (let i=0;i<errs.length;i++) {
143
143
  const it = errs[i]
144
- this.emit('error', it.err, 'notify', it.listener, args)
144
+ this.emit('error', it.err, 'notify', r.type, it.listener, args)
145
145
  }
146
146
  }
147
147
  } finally {
@@ -295,7 +295,7 @@ function _emit(type, msg) {
295
295
  } else {
296
296
  listeners = listeners.slice()
297
297
  }
298
- return {args, listeners}
298
+ return {type, args, listeners}
299
299
  }
300
300
 
301
301
  function _notify(listener, evt, args) {
package/src/event.js CHANGED
@@ -5,19 +5,19 @@
5
5
  * @param {import('./event-emitter').EventEmitter} target - Who trigger the event
6
6
  * @returns {Event} - The new Event instance.
7
7
  */
8
- export function Event(target) {
8
+ export function Event(target, type) {
9
9
  if (!(this instanceof Event)) {
10
- const evt = new Event(target)
10
+ const evt = new Event(target, type)
11
11
  return evt
12
12
  }
13
- this.init(target)
13
+ this.init(target, type)
14
14
  }
15
15
 
16
16
  /**
17
17
  * Initializes the event with the target object.
18
18
  * @param {import('./event-emitter').EventEmitter} target - The target object for the event.
19
19
  */
20
- Event.prototype.init = function(target) {
20
+ Event.prototype.init = function(target, type) {
21
21
  /**
22
22
  * Who trigger the event
23
23
  * @type {Object}
@@ -36,6 +36,12 @@ Event.prototype.init = function(target) {
36
36
  * @public
37
37
  */
38
38
  this.result = undefined
39
+ /**
40
+ * The type of the event.
41
+ * @type {string}
42
+ * @public
43
+ */
44
+ if (type) this.type = type;
39
45
  }
40
46
 
41
47
  /**