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

orsa-listeners

v0.0.1

Published

Orsa listener types

Downloads

3

Readme

Orsa Listeners

The Orsa listeners classes are the easiest way to write a new plugin. They let you focus on doing the processing part of the work, without having to worry about the event stream from Orsa.

There are four classes:

| Class | Description | |-----|-----| | BaseListener | This is the base class for all the listeners. It provides listenFor which is an easy way to register for events. As well as addTask which is a handy way of adding tasks. And logging through logInfo, logError, and logWarn. As nice as BaseListener is, you'll probably want to use ProjectListener or FileListener instead, both of which are subclasses of TypeListener | | TypeListener | TypeListener manages listening to particular types of DOM elements, notably File and Project. It knows which messages to listen for. It also supports locking. | | ProjectListener | Listens for changes to Project elements. | | FileListener | Listens for changes to File elements. |

The two critical methods on ProjectListener and FileListener that you need to override are shouldProcess(domElement) and process(domElement, done). The shouldProcess method is called to determine if now is the right time to run. And the process method is called when shouldProcess returns true.

In shouldProcess you should inspect the attributes and metadata of the DOM element to make sure that you have the data you need to run. In process you do the work and then call done when you are done.

You also have access to this.orsa any time you want to log something.

An example file listener watches for a Javascript AST to become available and then does something with it, like so:

const get = require('lodash.get');

class MyCoolPlugin extends FileListener {
  shouldProcess(domElement) {
    return get(domElement.metadata, 'js.ast', null) !== null;
  }

  process(domElement, callback) {
    domElement.metadata.set('js.woohoo', 'yay!');
    callback();
  }
}

Naming

Naming your plugin class appropriately is really important. Orsa uses the class name of your Plugin to disambiguate it from other plugins. So it's really important that it's unique. We recommend naming your plugin class as a camel-cased version of the package name. For example orsa-my-scanner-plugin would become OrsaMyScannerPlugin as shown below:

class OrsaMyScannerPlugin extends ProjectListener {
  ...
}

Locking

The TypeListener class provides a helpful locking behavior. Because a process method might make multiple changes to a DOM element, which would cause multiple events, it's likely that you would get into an event stream endless death spiral. Locking ensures that if process is already running against a particular element, it will not be run again until process has been completed.