Socket
Socket
Sign inDemoInstall

sparkles

Package Overview
Dependencies
0
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    sparkles

Namespaced global event emitter


Version published
Weekly downloads
1.7M
decreased by-0.91%
Maintainers
3
Install size
5.70 kB
Created
Weekly downloads
 

Package description

What is sparkles?

The sparkles npm package is used for creating and managing a global event namespace for your application, allowing different parts of your application to communicate with each other using events. It is a lightweight event emitter.

What are sparkles's main functionalities?

Event Emission

This feature allows you to emit events globally within your application. Any part of your application that has required sparkles and called it as a function will be able to listen for 'my-event' and react accordingly.

const sparkles = require('sparkles')();
sparkles.emit('my-event', { some: 'data' });

Event Listening

This feature allows you to listen for events that have been emitted globally. In this example, when 'my-event' is emitted, the callback function will be executed, and the passed data will be logged to the console.

const sparkles = require('sparkles')();
sparkles.on('my-event', (data) => {
  console.log('Received data:', data);
});

Event Namespacing

Sparkles allows you to create separate event namespaces. This can be useful if you want to avoid event name collisions between different parts of your application.

const sparkles = require('sparkles')('my-namespace');
sparkles.emit('my-event', { some: 'data' });

Other packages similar to sparkles

Changelog

Source

2.1.0 (2024-03-23)

Features

  • Add module for accessing legacy store (#10) (7f8b667)

Readme

Source

sparkles

NPM version Downloads Build Status Coveralls Status

Namespaced global event emitter

Usage

Sparkles exports a function that returns a singleton EventEmitter. This EE can be shared across your application, whether or not node loads multiple copies.

Note: If you put an event handler in a file in your application, that file must be loaded in via an import somewhere in your application, even if it's not directly being used. Otherwise, it will not be loaded into memory.

var sparkles = require('sparkles')(); // make sure to call the function

sparkles.on('my-event', function (evt) {
  console.log('my-event handled', evt);
});

sparkles.emit('my-event', { my: 'event' });

API

sparkles(namespace)

Returns an EventEmitter that is shared amongst the provided namespace. If no namespace is provided, returns a default EventEmitter.

sparkles.exists(namespace);

Checks whether a namespace exists and returns true or false.

Why the name?

This is a "global emitter"; shortened: "glitter" but it was already taken; so we got sparkles instead :smile:

License

MIT

Keywords

FAQs

Last updated on 23 Mar 2024

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