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

typed-event-emitter

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typed-event-emitter - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

package.json
{
"name": "typed-event-emitter",
"version": "1.0.0",
"version": "1.0.1",
"description": "Alternative event emitter for JavaScript and TypeScript.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -10,4 +10,11 @@ # typed-event-emitter

## Install
Via npm:
$ npm install typed-event-emitter
## Usage
Take a look at the following snippet (TypeScript):

@@ -48,7 +55,7 @@

First the *EventEmitter* is loaded from the module. Next, any class, that shall
emit events, must extend that *EventEmitter*. If your class has its own
constructor, make sure to call `super()`.
First, the *EventEmitter* is loaded from the module. Any class, that shall emit
events, must extend that *EventEmitter*. If your class has its own constructor,
make sure to call `super()`.
Any events, your class could emit, must be registered in the form:
Any events, your class shall be able to emit, must be registered in the form:

@@ -69,4 +76,46 @@ ~~~TypeScript

### JavaScript
Your JavaScript host (i.e., your browser, node.js, etc.) should support classes
and inheritance in order to work correctly. The code shown above can also be
written in JavaScript (node.js):
~~~JavaScript
const EventEmitter = require('typed-event-emitter').EventEmitter;
class MyClass extends EventEmitter {
constructor(value) {
// initialize EventEmitter
super();
/* newValue: number */
this.onValueChanged = this.registerEvent();
this._value = value;
}
get value() {
return this._value;
}
set value(value) {
this._value = value;
this.emit(this.onValueChanged, this._value);
}
}
let instance = new MyClass();
instance.onValueChanged(newValue => {
console.log(`Value changed: ${newValue}`);
});
instance.value = 27;
~~~
Node that the events are registered explicitly within the constructor. Make sure
to initialize them *after* calling `super()`.
## License
typed-event-emitter is licensed under the ISC License.
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