Socket
Socket
Sign inDemoInstall

emy

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    emy

An adorably small event emitter/pubsub library.


Version published
Weekly downloads
6
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

v1.1.0 - 2021-04-17

Added

  • Added source maps to build output.

Changed

  • Updated devDependencies.

Fixed

  • Fixed a bug where publish would crash due to handlers being stored in WeakSet.

Readme

Source

emy

An adorably small event emitter/pubsub library.

Usage

import emy from 'emy';

const [publish, subscribe] = emy();

const unsubscribe = subscribe((event) => {
  console.log(`Hello ${event.value}!`);
});

publish({ value: 'world' });

unsubscribe();

API

emy()

Creates a new event emitter.

const [publish, subscribe] = emy();
Return value

An array containing 2 functions, publish and subscribe.

These can be renamed to whatever you prefer, for example [emit, on] or [publishFoo, subscribeFoo].

publish(event)

Invokes all subscribed listeners.

publish({ value: 'world' });
Parameters
  • event any value to be passed to each listener.

subscribe(listener)

Register a listener.

const unsubscribe = subscribe((event) => {
  console.log(`Hello ${event.value}!`);
});

unsubscribe();
Parameters
  • listener function to call when event is published.
Return value

Returns a function which unregisters the listener when called.

Keywords

FAQs

Last updated on 16 Apr 2021

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc