Comparing version 0.2.0 to 0.2.1
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="0.2.1"></a> | ||
## [0.2.1](https://github.com/383514580/any-event/compare/v0.2.0...v0.2.1) (2018-12-02) | ||
### Bug Fixes | ||
* 修复声明文件错误 ([354cd11](https://github.com/383514580/any-event/commit/354cd11)) | ||
<a name="0.2.0"></a> | ||
@@ -7,0 +17,0 @@ # 0.2.0 (2018-12-02) |
@@ -54,9 +54,9 @@ 'use strict'; | ||
function EventEmitter() { | ||
this.listenersMap = {}; | ||
this._listenersMap = {}; | ||
} | ||
EventEmitter.prototype.on = function (eventName, listener) { | ||
if (undefined === this.listenersMap[eventName]) { | ||
this.listenersMap[eventName] = []; | ||
if (undefined === this._listenersMap[eventName]) { | ||
this._listenersMap[eventName] = []; | ||
} | ||
this.listenersMap[eventName].push(listener); | ||
this._listenersMap[eventName].push(listener); | ||
return this; | ||
@@ -70,6 +70,6 @@ }; | ||
EventEmitter.prototype.off = function (eventName, listener) { | ||
var listeners = this.listenersMap[eventName]; | ||
var listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners) { | ||
if (undefined === listener) { | ||
delete this.listenersMap[eventName]; | ||
delete this._listenersMap[eventName]; | ||
} | ||
@@ -89,3 +89,3 @@ else { | ||
var e_1, _a; | ||
var listeners = this.listenersMap[eventName]; | ||
var listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners && 0 < listeners.length) { | ||
@@ -119,3 +119,3 @@ try { | ||
EventEmitter.prototype.destroy = function () { | ||
this.listenersMap = {}; | ||
this._listenersMap = {}; | ||
}; | ||
@@ -122,0 +122,0 @@ return EventEmitter; |
@@ -52,9 +52,9 @@ /*! ***************************************************************************** | ||
function EventEmitter() { | ||
this.listenersMap = {}; | ||
this._listenersMap = {}; | ||
} | ||
EventEmitter.prototype.on = function (eventName, listener) { | ||
if (undefined === this.listenersMap[eventName]) { | ||
this.listenersMap[eventName] = []; | ||
if (undefined === this._listenersMap[eventName]) { | ||
this._listenersMap[eventName] = []; | ||
} | ||
this.listenersMap[eventName].push(listener); | ||
this._listenersMap[eventName].push(listener); | ||
return this; | ||
@@ -68,6 +68,6 @@ }; | ||
EventEmitter.prototype.off = function (eventName, listener) { | ||
var listeners = this.listenersMap[eventName]; | ||
var listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners) { | ||
if (undefined === listener) { | ||
delete this.listenersMap[eventName]; | ||
delete this._listenersMap[eventName]; | ||
} | ||
@@ -87,3 +87,3 @@ else { | ||
var e_1, _a; | ||
var listeners = this.listenersMap[eventName]; | ||
var listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners && 0 < listeners.length) { | ||
@@ -117,3 +117,3 @@ try { | ||
EventEmitter.prototype.destroy = function () { | ||
this.listenersMap = {}; | ||
this._listenersMap = {}; | ||
}; | ||
@@ -120,0 +120,0 @@ return EventEmitter; |
@@ -58,9 +58,9 @@ (function (global, factory) { | ||
function EventEmitter() { | ||
this.listenersMap = {}; | ||
this._listenersMap = {}; | ||
} | ||
EventEmitter.prototype.on = function (eventName, listener) { | ||
if (undefined === this.listenersMap[eventName]) { | ||
this.listenersMap[eventName] = []; | ||
if (undefined === this._listenersMap[eventName]) { | ||
this._listenersMap[eventName] = []; | ||
} | ||
this.listenersMap[eventName].push(listener); | ||
this._listenersMap[eventName].push(listener); | ||
return this; | ||
@@ -74,6 +74,6 @@ }; | ||
EventEmitter.prototype.off = function (eventName, listener) { | ||
var listeners = this.listenersMap[eventName]; | ||
var listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners) { | ||
if (undefined === listener) { | ||
delete this.listenersMap[eventName]; | ||
delete this._listenersMap[eventName]; | ||
} | ||
@@ -93,3 +93,3 @@ else { | ||
var e_1, _a; | ||
var listeners = this.listenersMap[eventName]; | ||
var listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners && 0 < listeners.length) { | ||
@@ -123,3 +123,3 @@ try { | ||
EventEmitter.prototype.destroy = function () { | ||
this.listenersMap = {}; | ||
this._listenersMap = {}; | ||
}; | ||
@@ -126,0 +126,0 @@ return EventEmitter; |
{ | ||
"name": "any-event", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "🍰 一个mini的事件管理器", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -1,7 +0,7 @@ | ||
import {Listener, ListenersMap} from '../types'; | ||
import { Listener, ListenersMap } from '../types'; | ||
export default class EventEmitter { | ||
public listenersMap: ListenersMap; | ||
private _listenersMap: ListenersMap; | ||
constructor() { | ||
this.listenersMap = {}; | ||
this._listenersMap = {}; | ||
}; | ||
@@ -14,7 +14,7 @@ | ||
*/ | ||
on(eventName: string, listener: Listener): EventEmitter{ | ||
if (undefined === this.listenersMap[eventName]) { | ||
this.listenersMap[eventName] = []; | ||
on(eventName: string, listener: Listener): EventEmitter { | ||
if (undefined === this._listenersMap[eventName]) { | ||
this._listenersMap[eventName] = []; | ||
} | ||
this.listenersMap[eventName].push(listener); | ||
this._listenersMap[eventName].push(listener); | ||
return this; | ||
@@ -29,3 +29,3 @@ }; | ||
*/ | ||
once(eventName: string, listener: Listener) : EventEmitter{ | ||
once(eventName: string, listener: Listener): EventEmitter { | ||
listener.isOnce = true; | ||
@@ -43,3 +43,3 @@ this.on(eventName, listener); | ||
off(eventName: string, listener?: Listener): EventEmitter { | ||
const listeners = this.listenersMap[eventName]; | ||
const listeners = this._listenersMap[eventName]; | ||
// 事件存在 | ||
@@ -49,3 +49,3 @@ if (undefined !== listeners) { | ||
if (undefined === listener) { | ||
delete this.listenersMap[eventName]; | ||
delete this._listenersMap[eventName]; | ||
} | ||
@@ -69,4 +69,4 @@ // 清空指定回调 | ||
*/ | ||
emit(eventName: string, ...payload: any):boolean { | ||
const listeners = this.listenersMap[eventName]; | ||
emit(eventName: string, ...payload: any): boolean { | ||
const listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners && 0 < listeners.length) { | ||
@@ -92,4 +92,4 @@ for (let [index, listener] of listeners.entries()) { | ||
destroy() { | ||
this.listenersMap = {}; | ||
this._listenersMap = {}; | ||
}; | ||
}; |
@@ -19,2 +19,4 @@ export type Listener = ((...payload: any) => void) & { isOnce?: boolean } | ||
public destroy: () => void; | ||
} | ||
} | ||
export default EventEmitter; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27846
533