1
1
[ ![ GitHub license] ( https://img.shields.io/badge/license-MIT-blue.svg?maxAge=10&style=flat-square )] ( https://raw.githubusercontent.com/SplittyDev/evee.js/master/LICENSE.md )
2
2
[ ![ npm] ( https://img.shields.io/npm/v/evee.svg?maxAge=10&style=flat-square )] ( https://www.npmjs.com/package/evee )
3
- [ ![ Travis] ( https://img.shields.io/travis/SplittyDev/evee.js.svg?maxAge=10&style=flat-square )] ( https://travis-ci.org/SplittyDev/evee.js )
4
- [ ![ Gratipay] ( https://img.shields.io/gratipay/SplittyDev.svg?style=flat-square )] ( https://gratipay.com/evee.js/ )
5
3
6
4
# evee.js
7
- The blazing fast ES6 event library.
5
+ The blazing fast event library.
8
6
9
- Evee is a lightweight event library, written in clean ECMAScript6 .
10
- Evee exports both an ES5 and an ES6 version to support a wide range of clients .
7
+ Evee is a lightweight event library, written in clean JavaScript .
8
+ Evee exports ESM, CommonJS and Browser globals, so you can use it in any environment .
11
9
12
- ## Status
13
- The project is still actively maintained, but the functionality is complete.
14
- Bugs will still be fixed and feature requests are more than welcome.
15
-
16
- ## How to upgrade from evee 1.x to evee 2.1.0+
17
- As of version 2.1.0, evee exports two entry points: ` evee ` and ` evee/es6 ` .
18
- The ` evee ` export is what you're used to, and will work with all ES5 compatible targets.
19
- The ` evee/es6 ` export is the ES6 version of evee, which is generally faster.
20
-
21
- If you wanna keep using the ES5 version, you don't need to change anything!
22
- If you wanna upgrade to the beautiful ES6 version, here's how to do it:
10
+ ## Upgrading to Evee 3
11
+ Evee now natively supports ESM and CommonJS, so you can import it in any environment.
23
12
13
+ If you're planning to use Evee in NodeJS, you can now import it like this:
24
14
``` js
25
- // Importing evee/es6 (require )
26
- const Evee = require (' evee/es6 ' ),
27
- evee = new Evee ;
15
+ import Evee from ' evee' ; // If you're using ESM (import/export )
16
+ const Evee = require (' evee' ). default ; // If you're using CommonJS (require)
17
+ ```
28
18
29
- // Importing evee/es6 (ES6 modules)
30
- import Evee from ' evee/es6' ;
31
- const evee = new Evee ;
19
+ If you're planning to use Evee in the browser, you can now import it like this:
20
+ ``` html
21
+ <!-- ESM if you're targeting modern browsers -->
22
+ <script type =" module" >
23
+ import Evee from ' https://cdn.jsdelivr.net/npm/evee' ;
24
+ const evee = new Evee ();
25
+ </script >
26
+
27
+ <!-- Global export if you're targeting older browsers -->
28
+ <script src =" https://cdn.jsdelivr.net/npm/evee/dist/browser/index.js" ></script >
29
+ <script >
30
+ const evee = new Evee (); // `Evee` is defined globally
31
+ </script >
32
32
```
33
33
34
34
## How to use
35
35
``` js
36
- // Grab a new evee instance
37
- const Evee = require ( ' evee/es6 ' ),
38
- evee = new Evee ;
36
+ import Evee from ' evee'
37
+
38
+ const evee = new Evee ()
39
39
40
40
// Subscribe to the 'update' event
41
- evee .on (' update' , e => console .log (` Ticks: ${ e .data } ` ));
41
+ evee .on (' update' , e => console .log (` Received event # ${ e .data } ` ))
42
42
43
- var ticks = 0 ;
44
- while (true ) {
43
+ for (let i = 0 ; i < 100 ; i++ ) {
45
44
46
45
// Dispatch the 'update' event
47
- evee .emit (' update' , ++ ticks );
46
+ evee .emit (' update' , i );
48
47
}
49
48
```
50
49
51
50
You can also keep track of your event listeners unsubscribe from events you don't need anymore.
52
51
53
52
``` js
54
- // Grab a new evee instance
55
- const Evee = require ( ' evee/es6 ' ),
56
- evee = new Evee ;
53
+ import Evee from ' evee'
54
+
55
+ const evee = new Evee ()
57
56
58
57
// Subscribe to the 'say' event
59
58
var receiver = evee .on (' say' , e => console .log (e .data ));
@@ -69,9 +68,9 @@ If you want to fire an event only once, you can do that too!
69
68
The event will be automatically removed after the first usage:
70
69
71
70
``` js
72
- // Grab a new evee instance
73
- const Evee = require ( ' evee/es6 ' ),
74
- evee = new Evee ;
71
+ import Evee from ' evee'
72
+
73
+ const evee = new Evee ()
75
74
76
75
// Subscribe to the 'say' event
77
76
evee .once (' say' , e => console .log (' hello, world' ));
@@ -84,12 +83,4 @@ evee.signal('say');
84
83
```
85
84
86
85
As you can see, evee is really easy to use!
87
- Start using evee today and stop worrying about slow events :)
88
-
89
- ## Running the benchmarks
90
- ```
91
- $ git clone [email protected] :SplittyDev/evee.js.git
92
- $ cd evee.js
93
- $ npm install --only=dev
94
- $ npm run-script bench-dev
95
- ```
86
+ Start using evee today and stop worrying about slow events :)
0 commit comments