Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-ev

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-ev - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

19

CHANGELOG.md
# Changelog
<a name="0.4.0"></a>
## [0.4.0](https://github.com/jpcx/ts-ev/tree/0.4.0) (2022-03-13)
| __[Changes since 0.3.0](https://github.com/jpcx/ts-ev/compare/0.3.0...0.4.0)__ | [Release Notes](https://github.com/jpcx/ts-ev/releases/tag/0.4.0) | [README](https://github.com/jpcx/ts-ev/tree/0.4.0/README.md) |
| --- | --- | --- |
| [Source Code (zip)](https://github.com/jpcx/ts-ev/archive/0.4.0.zip) | [Source Code (tar.gz)](https://github.com/jpcx/ts-ev/archive/0.4.0.tar.gz) |
| --- | --- |
### Changed
- Clarified inheritance summary in the README.
- Updated all dependencies to latest versions.
### Fixed
- `DataFilter` type assertion fix.
<a name="0.3.0"></a>

@@ -4,0 +23,0 @@

2

index.d.ts

@@ -64,3 +64,3 @@ export declare class Emitter<BaseEvents extends {

[event: string]: (...args: any[]) => any;
}, Ev extends keyof BaseEvents | keyof DerivedEvents, Data extends EvData<BaseEvents, DerivedEvents, Ev> = EvData<BaseEvents, DerivedEvents, Ev>> = <From extends EvData<BaseEvents, DerivedEvents, Ev>>(args: From) => args is Data;
}, Ev extends keyof BaseEvents | keyof DerivedEvents, Data extends EvData<BaseEvents, DerivedEvents, Ev>> = (args: EvData<BaseEvents, DerivedEvents, Ev>) => args is Data;
export {};
{
"name": "ts-ev",
"version": "0.3.0",
"version": "0.4.0",
"description": "a typed event emitter that provides removal protection, filtering, and inheritance",

@@ -40,5 +40,5 @@ "license": "MIT",

"@jpcx/testts": "^0.4.0",
"@types/node": "^16.9.1",
"typescript": "^4.4.3"
"@types/node": "^17.0.21",
"typescript": "^4.6.2"
}
}

@@ -1,2 +0,2 @@

[![](https://github.com/jpcx/ts-ev/blob/0.3.0/assets/logo.png)](#)
[![](https://github.com/jpcx/ts-ev/blob/0.4.0/assets/logo.png)](#)

@@ -9,3 +9,2 @@ ![](https://img.shields.io/github/issues/jpcx/ts-ev)

![](https://img.shields.io/github/license/jpcx/ts-ev)
![](https://img.shields.io/librariesio/github/jpcx/ts-ev?label=dev-dependencies)

@@ -16,7 +15,11 @@ [![](https://nodei.co/npm/ts-ev.png?mini=true)](https://www.npmjs.com/package/ts-ev)

Unlike other typed event emitters, ts-ev includes a mechanism for arbitrarily deep extensions of its Emitter class such that each derived class has full access to its own events.
Unlike other typed event emitters, ts-ev includes a mechanism for arbitrarily deep extensions of its Emitter class:
- Each derived class may
- extend their parent functionality,
- extend their parent events,
- and define additional events.
ts-ev has zero imports, so it should be usable in any environment.
ts-ev has zero imports, so it should be usable in any TS environment.
**[CHANGELOG](https://github.com/jpcx/ts-ev/blob/0.3.0/CHANGELOG.md)**
**[CHANGELOG](https://github.com/jpcx/ts-ev/blob/0.4.0/CHANGELOG.md)**

@@ -30,3 +33,3 @@ ## Features

- Listeners may be prepended.
- Matches the behavior of EventEmitter from "events".
- Matches the behavior of `EventEmitter` from "events".

@@ -52,12 +55,27 @@ Protection:

BaseEvents:
- Maps any listeners that are used directly by the top-level emitter to an event string.
Two template parameters are provided, one for base events and another for derived events. This is to allow for extensions of an emitter-derived class that define additional events.
DerivedEvents:
- Maps any listeners that are not statically known by the base class to an event string.
- These events are only available to derived classes.
- To enable event inheritance, base classes must forward a template argument that defines the derived event listeners.
- This tparam should prohibit derivation of the base events; see the example.
For example:
```ts
// allows derived classes to define additional events (but prohibits additional "foo" events)
class Foo<DerivedEvents extends Emitter.Events.Except<"foo">>
extends Emitter<{ foo: (data: "bar") => any }, DerivedEvents> {
constructor() {
this.emit("foo", "bar"); // OK
}
}
// extend the functionality of Foo and define additional events
class Bar extends Foo<{ bar: (data: "baz") => any }> {
constructor() {
this.emit("foo", "bar"); // OK
this.emit("bar", "baz"); // OK
}
}
```
In this example, the `Emitter` `BaseEvents` defined by `Foo` are statically known to it and therefore can be used within the class and its descendants. It's `DerivedEvents` are not statically known by it, so they may only be used by the derived class that defines them (`Bar`).
```ts
public [on|prependOn|once|prependOnce]<

@@ -82,3 +100,13 @@ Ev extends keyof BaseEvents | keyof DerivedEvents,

// standard usage, no extensions
const emitter = new Emitter<{
foo: (bar: "baz") => any
}>();
// emitter.emit("foo", "bar"); // TS error
emitter.emit("foo", "baz"); // OK
// extend Emitter
class Foo<
// use a tparam to forward derived events to Emitter (allow event extensions)
DerivedEvents extends Emitter.Events.Except<"baseEv1" | "baseEv2">

@@ -186,2 +214,2 @@ > extends Emitter<

This project is licensed under the MIT License - see the [LICENSE](https://github.com/jpcx/ts-ev/blob/0.3.0/LICENSE) file for details
This project is licensed under the MIT License - see the [LICENSE](https://github.com/jpcx/ts-ev/blob/0.4.0/LICENSE) file for details

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc