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

@lightningchart/eventer

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lightningchart/eventer

Simple and fast event emitter.

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4K
increased by83.18%
Maintainers
3
Weekly downloads
 
Created
Source

Eventer

Simple and fast event emitter library. Subscription is based on a unique Token, which can be used to unsubscribe from the topic.

The Eventer is used in LightningChart® JS charting library. https://www.lightningchart.com/

Installation

npm install --save @lightningchart/eventer

Documentation

Online documentation is available at arction.github.io/eventer

Getting started

import { Eventer } from '@lightningchart/eventer'

const eventer = new Eventer()

// new topic is created, handler is added as the first subscriber to the topic
const token1 = eventer.on('topic1', () => console.log('I am called from topic1'))
// 'topic1' already exists, so new listener is simply added to existing collection of handlers
const token2 = eventer.on('topic1', () => console.log('I am also called from topic1'))
// new collection of handlers is created for the second topic
// the function is added to it
eventer.on('topic2', () => console.log('I am called from topic2'))

eventer.emit('topic1')
// calls two functions which listen to the event
//
// outputs:
//    I am called from topic1
//    I am also called from topic1

eventer.emit('topic2')
// calls single functions which listen to the event
//
// outputs:
//    I am called from topic2

// remove the second listener from the first topic by token 
eventer.off(token2)

eventer.emit('topic1')
// calls single functions which listen to the event
//
// outputs:
//    I am called from topic1

// remove all listeners from all topics
eventer.allOff()

eventer.emit('topic2')
// nothing happened, since all subscriptions were terminated

Subscribe to topic

Subscribing to a topic is easy.

eventer.on('topic', ()=>{ console.log('Topic handler') })

Multiple subscriptions to a single topic can exist.

eventer.on('topic', ()=>{ console.log('Topic handler') })
eventer.on('topic2', ()=>{ console.log('Topic 2 handler') })
eventer.on('topic3', ()=>{ console.log('Topic 3 handler') })

Unsubscribe from topic

You can unsubscribe from a single topic by using the Token returned by eventer when you subscribed to the topic.

const token = eventer.on('topic', ()=>{ console.log('Topic handler') })

eventer.off(token)

You can also unsubscibe all listeners from a topic.

eventer.topicOff('topic')

It is also possible to unsubscribe all topics and all listeners.

eventer.allOff()

Emiting events

Events can be emitted for a topic. The emit can contain 0 or more arguments that will be provided to the topic listeners.

eventer.emit('topic')

eventer.on('topic2', ( arg1, arg2 ) => console.log( arg1, arg2 ))

eventer.emit('topic2', 'Hello ', 'World')

Development instructions

The project is developed using TypeScript. Build system of the project heavily relies on Node.js. Dependencies are managed with npm, therefore, remember to run npm install before starting of anything else.

There are several npm scripts, which are used for development process:

NameCommandDescription
buildnpm run buildrun build system
testnpm testrun tests and watch
lintnpm run lintrun static analyzer and watch
docsnpm run docsgenerate typedoc documentation
ci:testnpm run ci:testrun tests once
ci:lintnpm run ci:lintrun static analyzer once
ci:watchnpm run ci:watchrun CI circle and watch

Keywords

FAQs

Package last updated on 17 May 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc