@irrelon/emitter 5.0.2 → 5.0.3
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/package.json +1 -1
- package/readme.md +19 -19
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -2,14 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Usage
|
|
4
4
|
|
|
5
|
-
###
|
|
6
|
-
Include the ./dist/index.min.js file in your HTML
|
|
7
|
-
|
|
8
|
-
```html
|
|
9
|
-
<script src="./dist/index.min.js"></script>
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
### Node.js
|
|
5
|
+
### Node.js and Packaging Systems Like Webpack
|
|
13
6
|
Install via NPM / Yarn:
|
|
14
7
|
|
|
15
8
|
```bash
|
|
@@ -26,21 +19,21 @@ Include in your application:
|
|
|
26
19
|
var Emitter = require('@irrelon/emitter');
|
|
27
20
|
```
|
|
28
21
|
|
|
29
|
-
##
|
|
30
|
-
Given an example class:
|
|
22
|
+
## Extend The Emitter Class
|
|
31
23
|
|
|
32
24
|
```js
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
import {Emitter} from "@irrelon/emitter";
|
|
26
|
+
class MyClass extends Emitter {
|
|
27
|
+
async someAsyncFunc () {
|
|
28
|
+
await this.emit('myEvent', myData, myOtherData);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
someFunc () {
|
|
32
|
+
this.emit('myEvent', myData, myOtherData);
|
|
33
|
+
}
|
|
35
34
|
};
|
|
36
35
|
```
|
|
37
36
|
|
|
38
|
-
Add emitter functionality:
|
|
39
|
-
|
|
40
|
-
```js
|
|
41
|
-
Emitter(MyClass);
|
|
42
|
-
```
|
|
43
|
-
|
|
44
37
|
Your class now inherits the emitter methods:
|
|
45
38
|
|
|
46
39
|
* on
|
|
@@ -52,4 +45,11 @@ Your class now inherits the emitter methods:
|
|
|
52
45
|
* emitStaticId
|
|
53
46
|
* cancelStatic
|
|
54
47
|
* deferEmit
|
|
55
|
-
* willEmit
|
|
48
|
+
* willEmit
|
|
49
|
+
|
|
50
|
+
### Browser
|
|
51
|
+
Include the Emitter.js file in your HTML (the path depends on where you've put the file)
|
|
52
|
+
|
|
53
|
+
```html
|
|
54
|
+
<script src="./src/Emitter.js" type="module"></script>
|
|
55
|
+
```
|