Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Emitten
is a very basic event emitter for TypeScript.
This simple class
allows you to subscribe/unsubscribe to a defined library of events.
Add Emitten
to your project.
# Using NPM
npm install emitten
# Or some other package manager, such as Yarn
yarn add emitten
Import and start emit’in!
// Import the fully public Emitten variant.
// Alternatively, use the fully protected variant: EmittenProtected
// Or, the partially protected variant: EmittenCommon
import {Emitten} from 'emitten';
// Define your “event map” of `eventName: listener(args)` pairs.
// Both the `eventName` and the `args` from the `listener` are
// captured by TypeScript to assert type-safety!
type EventMap = {
change: (value: string) => void;
count: (value?: number) => void;
collect: (...values: boolean[]) => void;
other: (required: string, ...optional: string[]) => void;
};
// Instantiate, passing `EventMap` as a generic.
const myEmitter = new Emitten<EventMap>();
// By referencing the `EventMap` you created,
// you can assign the correct type to your listeners.
const handleChange: EventMap['change'] = (value) => {};
// Register a subscription!
myEmitter.on('change', handleChange);
// Emit an event! The arguments accepted
// by `.emit()` will be correctly typed.
myEmitter.emit('change', 'Hello world');
// Remove a subscription!
myEmitter.off('change', handleChange);
// Register a subscription only once! The listener
// will be automatically removed after a single `emit`.
myEmitter.once('count', (value = 0) => {});
myEmitter.emit('count', 123);
// Capture and manually call the removal function!
// The arguments accepted by any listener will correctly
// correspond with the registered `eventName`.
const dispose = myEmitter.on('collect', (...values) => {});
myEmitter.emit('collect', true, false, !true, !false);
dispose();
// Get a list of all the events that currently
// have subscriptions.
const currentEvents = myEmitter.activeEvents;
// Remove all registered listeners!
myEmitter.empty();
For more guidance, please take a look at the Examples document
.
FAQs
Barebones TypeScript event emitter
We found that emitten demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.