npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@arction/eventer

v1.0.2

Published

Simple and fast event emitter.

Downloads

8,453

Readme

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.arction.com/

Installation

npm install --save @arction/eventer

Documentation

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

Getting started

import { Eventer } from '@arction/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:

| Name | Command | Description | | ---------|------------------|--------------------------| | build | npm run build | run build system | test | npm test | run tests and watch | | lint | npm run lint | run static analyzer and watch | docs | npm run docs | generate typedoc documentation | ci:test | npm run ci:test | run tests once | ci:lint | npm run ci:lint | run static analyzer once | ci:watch | npm run ci:watch | run CI circle and watch