
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
medooze-event-emitter
Advanced tools
This is a modified version of Node.js EventEmitter
class for use within Medooze's codebase.
It's exported directly by this module, and meant to be extended rather than used as a standalone object.
The changes are:
emit()
is marked protected to prevent it from accidentally being called from outside of the classmaxListener
limit is removedstop()
method, which removes all listeners and causes future calls (except emit()
) to be no-opsemit()
(thrown at the next tick instead)Using the same mechanism as tiny-typed-emitter, this class allows users to declare the events that a class may emit, as well as the arguments each one accepts. Calls to on()
/ once()
/ emit()
are then typechecked accordingly.
Usage is as follows: projects that use type checking must supply an interface as generic parameter to the class when extending it. Each property of this interface is an event, and its type must be that of the listener (a function accepting some arguments and returning void
).
Here's an example of how that would look in a project that uses JSDoc annotations (see tiny-typed-emitter for an example using TypeScript syntax):
const Emitter = require("medooze-event-emitter");
/**
* @typedef {Object} SubscriptionEvents
* @property {(transport: Transport, kind: boolean) => void} inited - subscription has initialized
* @property {() => void} stopped - subscription has stopped
*/
/** @extends {Emitter<SubscriptionEvents>} */
class Subscription extends Emitter {
// ...
}
Here we define a Subscription
class that may emit two events: stopped
, with no arguments, and inited
with an argument of type Transport
and another of type boolean
.
FAQs
type-safe, modified version of EventEmitter
We found that medooze-event-emitter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.