Skip to content

Commit fec2f46

Browse files
committed
Prepare upgrade to Evee 3
1 parent 09a04b6 commit fec2f46

File tree

9 files changed

+4161
-180
lines changed

9 files changed

+4161
-180
lines changed

.babelrc

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
{
2-
"presets": [
3-
["es2015", { "modules": false }]
4-
]
2+
"env": {
3+
"browser": {
4+
"presets": [
5+
[
6+
"@babel/preset-env",
7+
{
8+
"targets": {
9+
"browsers": "last 2 versions"
10+
}
11+
}
12+
]
13+
]
14+
},
15+
"cjs": {
16+
"presets": [
17+
[
18+
"@babel/preset-env",
19+
{
20+
"targets": {
21+
"node": "current"
22+
},
23+
"modules": "commonjs"
24+
}
25+
]
26+
]
27+
},
28+
"esm": {
29+
"presets": [
30+
[
31+
"@babel/preset-env",
32+
{
33+
"targets": {
34+
"node": "current"
35+
},
36+
"modules": false
37+
}
38+
]
39+
]
40+
}
41+
}
542
}

README.md

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,58 @@
11
[![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)
22
[![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/)
53

64
# evee.js
7-
The blazing fast ES6 event library.
5+
The blazing fast event library.
86

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.
119

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.
2312

13+
If you're planning to use Evee in NodeJS, you can now import it like this:
2414
```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+
```
2818

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>
3232
```
3333

3434
## How to use
3535
```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()
3939

4040
// 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}`))
4242

43-
var ticks = 0;
44-
while(true) {
43+
for (let i = 0; i < 100; i++) {
4544

4645
// Dispatch the 'update' event
47-
evee.emit('update', ++ticks);
46+
evee.emit('update', i);
4847
}
4948
```
5049

5150
You can also keep track of your event listeners unsubscribe from events you don't need anymore.
5251

5352
```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()
5756

5857
// Subscribe to the 'say' event
5958
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!
6968
The event will be automatically removed after the first usage:
7069

7170
```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()
7574

7675
// Subscribe to the 'say' event
7776
evee.once('say', e => console.log('hello, world'));
@@ -84,12 +83,4 @@ evee.signal('say');
8483
```
8584

8685
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 :)

benchmark.js

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,33 @@
1-
// Grab Benchmark
2-
var Benchmark = require ('benchmark');
1+
import Benchmark from 'benchmark'
2+
import { default as Node } from 'events'
3+
import Evee from './dist/esm/index.js'
34

4-
// Grab Node, Evee5 and Evee6
5-
const Node = require ('events'),
6-
Evee = require ('./'),
7-
Evex = require ('./es6'),
8-
suite = new Benchmark.Suite;
5+
const suite = new Benchmark.Suite()
96

107
// Initialise globals
11-
var node = new Node;
12-
var evee = new Evee;
13-
var evex = new Evex;
8+
var node = new Node();
9+
var evee = new Evee();
1410

15-
suite.add('node new', () => {
16-
var _ = new Node;
17-
}).add('evee5 new', () => {
18-
var _ = new Evee;
19-
}).add('evee6 new', () => {
20-
var _ = new Evex;
21-
}).add('node clear', () => {
11+
node.setMaxListeners(99999999);
12+
13+
suite.add('node new', () => {
14+
var _ = new Node();
15+
}).add('evee new', () => {
16+
var _ = new Evee();
17+
}).add('node clear', () => {
2218
node.removeAllListeners();
23-
}).add('evee5 clear', () => {
19+
}).add('evee clear', () => {
2420
evee.clear();
25-
}).add('evee6 clear', () => {
26-
evex.clear();
27-
}).add('node on', () => {
21+
}).add('node on', () => {
2822
node.on('event', () => undefined);
29-
}).add('evee5 on', () => {
23+
}).add('evee on', () => {
3024
evee.on('event', () => undefined);
31-
}).add('evee6 on', () => {
32-
evex.on('event', () => undefined);
33-
}).add('node emit', () => {
25+
}).add('node emit', () => {
3426
node.emit('event');
35-
}).add('evee5 emit', () => {
27+
}).add('evee emit', () => {
3628
evee.emit('event');
37-
}).add('evee6 emit', () => {
38-
evex.emit('event');
3929
}).on('cycle', event => {
40-
node = new Node;
41-
node.setMaxListeners(99999999);
42-
evee = new Evee;
43-
evex = new Evex;
30+
node.removeAllListeners();
31+
evee.clear();
4432
console.log(String(event.target));
45-
}).run({ 'async': false });
33+
}).run({ 'async': true });

examples/basic.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Evee from 'evee'
2+
const evee = new Evee()
3+
4+
// handle the 'say' event
5+
evee.on('say', e => console.log(e.data));
6+
7+
// delay for 1200ms and then fire the event
8+
setTimeout(() => evee.emit('say', 'hello from evee.js!'), 1200);

examples/tonic.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)