Skip to content

Commit

Permalink
improve readme and clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
behnammodi committed Sep 24, 2018
1 parent b3718d0 commit 1e576ae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -28,4 +28,13 @@ import { on } from 'jetemit';
on('TIME', time => {
console.log(time);
});
```

unsubscribe lisener
```javascript
const unsubscribe = on('TIME', time => {
console.log(time);
});

unsubscribe();
```
5 changes: 2 additions & 3 deletions index.js
Expand Up @@ -3,20 +3,19 @@
exports.__esModule = true;
var subscribes = {};

var on = exports.on = function on(name, func) {
exports.on = function on(name, func) {
subscribes[name] = subscribes[name] || [];
var index = subscribes[name].push(func) - 1;
return function () {
subscribes[name][index] = undefined;
};
};

var emit = exports.emit = function emit(name, arg) {
exports.emit = function emit(name, arg) {
if (subscribes[name]) {
subscribes[name].forEach(function (func) {
func && func(arg);
});
}
};


2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "jetemit",
"version": "1.0.1",
"version": "1.0.2",
"description": "",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 1e576ae

Please sign in to comment.