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

@pandino/event-admin

v0.8.31

Published

Reference implementation of the Pandino Event Admin API

Downloads

6

Readme

Event Admin

build-test license TypeScript

This is the reference implementation of the Pandino Event API.

Context

This package is part of the pandino-root monorepo. For detailed information about what is Pandino / how this package fits into the ecosystem, please consult with the related documentation(s).

Creating Events

Events consist of quite a lot of properties, therefore the easiest way to construct one is by utilizing the EventFactory. Sending the Event can be achieved by calling the postEvent() method on the obtained EventAdmin instance.

Every Event consists of a topic (string), and a properties object.

Please note, that Event delivery is fully async, and the order of delivery is not pre-defined!

It should be considered as a best practice to ensure that the properies objects is serializable. E.g.: JSON.stringify() and JSON.parse() compliant.

Example

import { EVENT_ADMIN_INTERFACE_KEY, EVENT_FACTORY_INTERFACE_KEY } from '@pandino/event-api';

export default class Activator {
  async start(context) {
    this.eventAdminReference = context.getServiceReference(EVENT_ADMIN_INTERFACE_KEY);
    this.eventAdmin = context.getService(this.eventAdminReference);
    this.eventFactoryReference = context.getServiceReference(EVENT_FACTORY_INTERFACE_KEY);
    this.eventFactory = context.getService(this.eventFactoryReference);

    // create the Event
    const event = eventFactory.build('@scope/app/TestTopic', {
      prop1: 'yayy',
    });
    
    // send the Event
    this.eventAdmin.postEvent(event);
  }

  async stop(context) {
    context.ungetService(this.eventFactoryReference);
    context.ungetService(this.eventAdminReference);
  }
}

Listening to Events

Any Service which implements the @pandino/pandino-event-admin/EventHandler interface and has the service property event.topics (either a single string, or an Array<string> can be provided as value) defined can listen to Pandino Events.

In order to narrow down unnecessary triggering of EventHandlers, an additional service property event.filter can be defined!

Example

import { EVENT_HANDLER_INTERFACE_KEY, EVENT_TOPIC } from '@pandino/event-api';

export default class BundleActivator {
  async start(context) {
    this.registration = context.registerService(EVENT_HANDLER_INTERFACE_KEY, new TestTopicEventHandler(), {
      [EVENT_TOPIC]: '@scope/app/TestTopic'
    });
  }

  async stop(context) {
    context.unregisterService(this.registration);
  }
}

class TestTopicEventHandler {
  handleEvent(event) {
    console.log(event.getTopic());
    console.log(event.getPropertyNames());
    // ...
  }
}

Topics

Topics should be unique. The recommended way of setting them up to prefix every topic with an actual package scope, and make them as explicit as possible. Topic segment separator MUST be the / character. Topics CAN start with the @ character to mirror NPM-style scopes, but it is not mandatory.

Topic matching

Matching by default is done in an case-sensitive, as-is manner for plain topics, e.g.: @scope/package/topic1. In this case, only exact matches will trigger listeners.

However there are two reserved keys which you can use as suffixes to loosen up the matching:

  • .: matches for exactly one additional segment, no more, no less
  • *: matches for at least one additional segment, no less

Examples

In the Table below headers represent topics, and the first column the test cases:

| | @pandino/pandino/Foo | @pandino/pandino. | @pandino/pandino* | |---------------------------|----------------------|-------------------|-------------------| | @pandino/pandino/Foo | true | true | true | | @pandino/pandino/Bar | false | true | true | | @pandino/pandino/Foo$1 | false | true | true | | @pandino/pandino/Foo/Test | false | false | true | | @pandino/pandino | false | false | false |

License

Eclipse Public License - v 2.0