Comparing version 0.2.0 to 0.2.1
# Changelog | ||
<a name="0.2.1"></a> | ||
## [0.2.1](https://github.com/jpcx/ts-ev/tree/0.2.1) (2021-09-15) | ||
| __[Changes since 0.1.0](https://github.com/jpcx/ts-ev/compare/0.2.0...0.2.1)__ | [Release Notes](https://github.com/jpcx/ts-ev/releases/tag/0.2.1) | [README](https://github.com/jpcx/ts-ev/tree/0.2.1/README.md) | | ||
| --- | --- | --- | | ||
| [Source Code (zip)](https://github.com/jpcx/ts-ev/archive/0.2.1.zip) | [Source Code (tar.gz)](https://github.com/jpcx/ts-ev/archive/0.2.1.tar.gz) | | ||
| --- | --- | | ||
Fixed variable name consistency. | ||
<a name="0.2.0"></a> | ||
@@ -4,0 +16,0 @@ |
@@ -8,11 +8,11 @@ export declare class Emitter<BaseEvents extends { | ||
constructor(); | ||
on<Ev extends keyof BaseEvents | keyof DerivedEvents, Data extends EvData<BaseEvents, DerivedEvents, Ev> = EvData<BaseEvents, DerivedEvents, Ev>>(event: Ev, listener: (...args: Data) => any, options?: { | ||
on<Ev extends keyof BaseEvents | keyof DerivedEvents, Data extends EvData<BaseEvents, DerivedEvents, Ev> = EvData<BaseEvents, DerivedEvents, Ev>>(ev: Ev, listener: (...args: Data) => any, options?: { | ||
filter?: DataFilter<BaseEvents, DerivedEvents, Ev, Data>; | ||
protect?: boolean; | ||
}): this; | ||
prependOn<Ev extends keyof BaseEvents | keyof DerivedEvents, Data extends EvData<BaseEvents, DerivedEvents, Ev> = EvData<BaseEvents, DerivedEvents, Ev>>(event: Ev, listener: (...args: Data) => any, options?: { | ||
prependOn<Ev extends keyof BaseEvents | keyof DerivedEvents, Data extends EvData<BaseEvents, DerivedEvents, Ev> = EvData<BaseEvents, DerivedEvents, Ev>>(ev: Ev, listener: (...args: Data) => any, options?: { | ||
filter?: DataFilter<BaseEvents, DerivedEvents, Ev, Data>; | ||
protect?: boolean; | ||
}): this; | ||
once<Ev extends keyof BaseEvents | keyof DerivedEvents, Data extends EvData<BaseEvents, DerivedEvents, Ev> = EvData<BaseEvents, DerivedEvents, Ev>>(ev: Ev, cb: (...args: Data) => any, options?: { | ||
once<Ev extends keyof BaseEvents | keyof DerivedEvents, Data extends EvData<BaseEvents, DerivedEvents, Ev> = EvData<BaseEvents, DerivedEvents, Ev>>(ev: Ev, listener: (...args: Data) => any, options?: { | ||
filter?: DataFilter<BaseEvents, DerivedEvents, Ev, Data>; | ||
@@ -24,3 +24,3 @@ protect?: boolean; | ||
}): Promise<Data>; | ||
prependOnce<Ev extends keyof BaseEvents | keyof DerivedEvents, Data extends EvData<BaseEvents, DerivedEvents, Ev> = EvData<BaseEvents, DerivedEvents, Ev>>(ev: Ev, cb: (...args: Data) => any, options?: { | ||
prependOnce<Ev extends keyof BaseEvents | keyof DerivedEvents, Data extends EvData<BaseEvents, DerivedEvents, Ev> = EvData<BaseEvents, DerivedEvents, Ev>>(ev: Ev, listener: (...args: Data) => any, options?: { | ||
filter?: DataFilter<BaseEvents, DerivedEvents, Ev, Data>; | ||
@@ -32,6 +32,6 @@ protect?: boolean; | ||
}): Promise<Data>; | ||
off<Ev extends keyof BaseEvents | keyof DerivedEvents>(ev: Ev, cb: EvListener<BaseEvents, DerivedEvents, Ev>): this; | ||
off<Ev extends keyof BaseEvents | keyof DerivedEvents>(ev: Ev, listener: EvListener<BaseEvents, DerivedEvents, Ev>): this; | ||
off<Ev extends keyof BaseEvents | keyof DerivedEvents>(ev: Ev): this; | ||
off(): this; | ||
emit<Ev extends keyof BaseEvents | keyof DerivedEvents>(event: Ev, ...data: EvData<BaseEvents, DerivedEvents, Ev>): this; | ||
emit<Ev extends keyof BaseEvents | keyof DerivedEvents>(ev: Ev, ...data: EvData<BaseEvents, DerivedEvents, Ev>): this; | ||
} | ||
@@ -38,0 +38,0 @@ export declare module Emitter { |
46
index.js
@@ -11,4 +11,4 @@ "use strict"; | ||
} | ||
on(event, listener, options) { | ||
const info = this._evinfo[event]; | ||
on(ev, listener, options) { | ||
const info = this._evinfo[ev]; | ||
const opts = Object.assign({ once: false }, options); | ||
@@ -18,7 +18,7 @@ if (info) | ||
else | ||
this._evinfo[event] = [[listener, opts]]; | ||
this._evinfo[ev] = [[listener, opts]]; | ||
return this; | ||
} | ||
prependOn(event, listener, options) { | ||
const info = this._evinfo[event]; | ||
prependOn(ev, listener, options) { | ||
const info = this._evinfo[ev]; | ||
const opts = Object.assign({ once: false }, options); | ||
@@ -28,13 +28,13 @@ if (info) | ||
else | ||
this._evinfo[event] = [[listener, opts]]; | ||
this._evinfo[ev] = [[listener, opts]]; | ||
return this; | ||
} | ||
once(ev, cbOrOptions, options) { | ||
if (typeof cbOrOptions === "function") { | ||
once(ev, listenerOrOptions, options) { | ||
if (typeof listenerOrOptions === "function") { | ||
const info = this._evinfo[ev]; | ||
const opts = Object.assign({ once: true }, options); | ||
if (info) | ||
info.push([cbOrOptions, opts]); | ||
info.push([listenerOrOptions, opts]); | ||
else | ||
this._evinfo[ev] = [[cbOrOptions, opts]]; | ||
this._evinfo[ev] = [[listenerOrOptions, opts]]; | ||
return this; | ||
@@ -45,3 +45,3 @@ } | ||
const info = this._evinfo[ev]; | ||
const opts = Object.assign(Object.assign({ once: true }, cbOrOptions), { protect: true }); | ||
const opts = Object.assign(Object.assign({ once: true }, listenerOrOptions), { protect: true }); | ||
const shim = (...data) => resolve(data); | ||
@@ -55,10 +55,10 @@ if (info) | ||
} | ||
prependOnce(ev, cbOrOptions, options) { | ||
if (typeof cbOrOptions === "function") { | ||
prependOnce(ev, listenerOrOptions, options) { | ||
if (typeof listenerOrOptions === "function") { | ||
const info = this._evinfo[ev]; | ||
const opts = Object.assign({ once: true }, options); | ||
if (info) | ||
info.unshift([cbOrOptions, opts]); | ||
info.unshift([listenerOrOptions, opts]); | ||
else | ||
this._evinfo[ev] = [[cbOrOptions, opts]]; | ||
this._evinfo[ev] = [[listenerOrOptions, opts]]; | ||
return this; | ||
@@ -69,3 +69,3 @@ } | ||
const info = this._evinfo[ev]; | ||
const opts = Object.assign(Object.assign({ once: true }, cbOrOptions), { protect: true }); | ||
const opts = Object.assign(Object.assign({ once: true }, listenerOrOptions), { protect: true }); | ||
const shim = (...data) => resolve(data); | ||
@@ -79,7 +79,7 @@ if (info) | ||
} | ||
off(ev, cb) { | ||
if (ev !== undefined && cb !== undefined) { | ||
off(ev, listener) { | ||
if (ev !== undefined && listener !== undefined) { | ||
const cbs = this._evinfo[ev]; | ||
if (cbs) { | ||
cbs.splice(cbs.findIndex(([l]) => l === cb), 1); | ||
cbs.splice(cbs.findIndex(([l]) => l === listener), 1); | ||
if (cbs.length === 0) | ||
@@ -107,9 +107,9 @@ delete this._evinfo[ev]; | ||
} | ||
emit(event, ...data) { | ||
if (this._evinfo[event]) | ||
for (const [cb, { once, filter }] of [...this._evinfo[event]]) | ||
emit(ev, ...data) { | ||
if (this._evinfo[ev]) | ||
for (const [cb, { once, filter }] of [...this._evinfo[ev]]) | ||
if (filter ? filter(data) : true) { | ||
cb(...data); | ||
if (once) | ||
this.off(event, cb); | ||
this.off(ev, cb); | ||
} | ||
@@ -116,0 +116,0 @@ return this; |
{ | ||
"name": "ts-ev", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "a typed event emitter that provides removal protection, filtering, and inheritance", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -1,2 +0,2 @@ | ||
[![](https://github.com/jpcx/ts-ev/blob/0.2.0/assets/logo.png)](#) | ||
[![](https://github.com/jpcx/ts-ev/blob/0.2.1/assets/logo.png)](#) | ||
@@ -19,3 +19,3 @@ ![](https://img.shields.io/github/issues/jpcx/ts-ev) | ||
**[changelog](https://github.com/jpcx/ts-ev/blob/0.2.0/CHANGELOG.md)** | ||
**[changelog](https://github.com/jpcx/ts-ev/blob/0.2.1/CHANGELOG.md)** | ||
@@ -22,0 +22,0 @@ ## Features |
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
16435
1576