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

nano-event-bus-ts

v1.0.2

Published

An Event bus library by typescript

Downloads

4

Readme

Nano Event Bus

This is a simple and tiny event emitter library for JavaScript/Typescript, motivate from this library nano-events. This library have a mechanism to listen event lately, it means an event is emitted before to mainly support for Micro Frontend projects.

  const user = {
    id: '1',
    name: 'John'
  }

  emit('user.update', user);

  on('user.update-user', 'client.user.update-user', (event) => {
    console.log(event)
  }, true);
  // => { lifecycle: 'initialized', value: { id: '1', name: 'John' } }

Micro Frontend example

Overcoming difficulties in event listening between remote and host apps due to the delayed loading of the remoteEntry file.

Consider the scenario where the host loads first, and subsequent Products remote apps load later. The host immediately triggers an event host.router.update meant for a Product app that is still in the loading process, the Product app may fail to capture the event. Flow Solution: To mitigate this, a mechanism has been developed to store emitted events and re-emit them once the remote app successfully loads. At this time, Product app still get information of event host.router.update from host app at initialize lifecycle state, and continue to handle next step.

Micro Frontend Repository

Table of Content

Install

npm install nano-event-bus-ts

Usages

Create Event Bus

const eventBus = createNanoEventBus()

Add Listener

Use on method to add listener for specific event:

eventBus.on('test', 'listener', (event) => {
  // Do something
});

eventBus.emit('do-something', { test: 10 });

Different with other libraries, when using on method to listen event, have to define listenerName, it will use listenerName to cache handler and some other information instead of using reference value of handler method like other libs.

Listen emitted event late

Pass true value for isLateListening param of on method

eventBus.emit('do-something', { test: 10 });

eventBus.on('test', 'listener', (event) => {
  console.log(event) //  => { lifecycle: 'initialized', value: { id: '1', name: 'John' } }
}, true);

When applying late listening to the emitted event, the first listening will have the lifecycle is initialized, the next one will be emitted.

When not applying late listening, this lifecycle is always initialized.

Remove listeners and events

const removeListener = eventBus.on('test', 'listener', (event) => {
  // Do something
});
removeListener();

const removeEvent = eventBus.emit('do-something', { test: 10 });
removeEvent();