Skip to content

Commit

Permalink
Add module.exports
Browse files Browse the repository at this point in the history
  • Loading branch information
Zlobin committed Apr 25, 2016
1 parent 8d54127 commit 6151172
Show file tree
Hide file tree
Showing 8 changed files with 355 additions and 349 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"rules": {
"comma-dangle": [2, "never"],
"no-param-reassign": 0,
"prefer-rest-params": 0
"prefer-rest-params": 0,
"no-underscore-dangle": 0
}
}
56 changes: 30 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,38 @@ Fastest is es-event-emitter

## Dependencies

There are no dependencies. You need only npm installed and just run `npm install` to grab the development dependencies.
There are no dependencies. You need only npm installed and just run `npm i` to grab the development dependencies.

## Examples
run `npm i es-event-emitter`

Run `npm i` under EventEmitter library's path and now you can include EventEmitter in html.

```javascript
var EM = require('es-event-emitter');
```

Or an usual html inculde:

```html
<script src="<path to es-event-emitter library>dist/bundle.js"></script>
<script>
var EM = EventEmitter.default();
// ...
</script>
<script src="<PATH/TO/LIBRARY>/dist/bundle.js">
```
or just:
or ES2015 import:
```javascript
import EM from 'es-event-emitter';
// ...
```
Creating an instance.
```javascript
const EM = new EventEmitter();
var EM = new EventEmitter();
```
An usual example.
```javascript
EM.on('foo', () => {
EM.on('foo', function() {
// some code...
});
Expand All @@ -76,7 +80,7 @@ EM.emit('foo');
It will be triggered only once and then callbacks will be removed.
```javascript
EM.once('foo', () => {
EM.once('foo', function() {
// some code...
});
Expand All @@ -87,7 +91,7 @@ EM.emit('foo');
Callback with parameters.
```javascript
EM.once('foo', (bar, baz) => {
EM.once('foo', function(bar, baz) {
// some code...
});
Expand All @@ -96,17 +100,17 @@ EM.emit('foo', 'var 1 for bar', 'var 2 for baz');
Callback's call can be ordered by "weight" parameter.
```javascript
EM.on('foo', () =>
console.log('3')
, null, 1);
EM.on('foo', function() {
console.log('3');
}, null, 1);
EM.on('foo', () =>
console.log('1')
, null, 3);
EM.on('foo', function() {
console.log('1');
}, null, 3);
EM.on('foo', () =>
console.log('2')
, null, 2);
EM.on('foo', function() {
console.log('2');
}, null, 2);
EM.emit('foo');
// 3
Expand All @@ -116,7 +120,7 @@ EM.emit('foo');
You can use chaining.
```javascript
EM.on('foo', () => {
EM.on('foo', function() {
// some code...
});
Expand All @@ -130,11 +134,11 @@ You can set maxNumberOfListeners as a parameter when creating new instance.
```javascript
const EM = new EventEmitter(1);
EM.on('foo', () => {
EM.on('foo', function() {
// some code...
});
// Note: it will show notification in console.
EM.on('foo', () => {
EM.on('foo', function() {
// some other code...
});
```
Expand All @@ -152,23 +156,23 @@ You can use JSDoc comments found within the source code.
1. Add event's namespace:
```javascript
EM.on('foo.*', () => {
EM.on('foo.*', function() {
// some code...
});
```
2. Add events through comma:
```javascript
EM.on('foo,bar,baz', () => {
EM.on('foo,bar,baz', function() {
// some code...
});
```
3. Add method "onAny" for listening each event:
```javascript
EM.onAny(() => {
EM.onAny(function() {
// some code...
});
```
2 changes: 1 addition & 1 deletion benchmark/single.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import EM from 'event-emitter';
import EM2 from 'eventemitter2';
import EM_native from 'events';
import EM_current from '../src/index.js';
import EM_current from '../src/event-emitter.js';

import Benchmark from 'benchmark';

Expand Down
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "es-event-emitter",
"description": "A small, incredible fast Event-Emitter library based on ES2015",
"version": "1.2.3",
"description": "Small and incredible fast Event-Emitter library based on JavaScript (ES2015)",
"version": "1.3.0",
"main": "src/index.js",
"author": {
"name": "Eugene Zlobin",
Expand Down Expand Up @@ -29,31 +29,32 @@
"listener"
],
"license": "MIT",
"dependencies": {},
"dependencies": {
"eslint-plugin-import": "^1.5.0"
},
"devDependencies": {
"babel": "^6.5.2",
"babel-cli": "^6.6.5",
"babel-core": "^6.7.4",
"babel-cli": "^6.7.7",
"babel-core": "^6.7.7",
"babel-loader": "^6.2.4",
"babel-plugin-transform-export-extensions": "^6.5.0",
"babel-plugin-transform-object-rest-spread": "^6.6.5",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-2": "^6.5.0",
"benchmark": "^2.1.0",
"eslint": "^2.7.0",
"eslint-config-airbnb": "^6.2.0",
"eslint": "^2.8.0",
"eslint-config-airbnb": "^8.0.0",
"eslint-loader": "^1.3.0",
"eslint-plugin-react": "^4.2.3",
"expect": "^1.16.0",
"eslint-plugin-react": "^5.0.1",
"expect": "^1.18.0",
"mocha": "^2.4.5",
"webpack": "^1.12.14"
"webpack": "^1.13.0"
},
"engines": {
"node": ">=4"
},
"scripts": {
"postinstall": "webpack",
"test": "mocha --compilers js:babel-core/register",
"start": "webpack && babel-node --presets es2015 ./benchmark/single.js"
"start": "babel-node --presets es2015 ./benchmark/single.js"
}
}
Loading

0 comments on commit 6151172

Please sign in to comment.