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

venter

v0.1.1

Published

a simple pub/sub class for nodeJS with support for scopes and namespaces

Downloads

3

Readme

node-venter

A simple pub/sub class with support for scopes and namespaces.

Venter extends Node's EventEmitter class.

Scopes

Scopes mean you can create different instances of Venter so they have seperate pub/sub channels and life-cycle

Namespaces

Namespaces mean you can subscribe to the same event multiple times from the same method with the same handler(callback). Additionally, namespaces allow you to unregister from one event while leaving other handlers in place.

These come in handy when you have an event you'd like to listen to with one callback and the code registering the handler is part of more than one flow. the different flows may happen or not within the lifetime of your application. Without namespaces it will be difficult implementing this and have the listeners registered and unregistered appropriately.

API

Venter

  • getScope()

    Return the scope the venter was initialized with.

  • addListener(type, listener, [namespace])

Alias: on

Adds a listener to the end of the listeners array for the specified event.
  • emit(type, [p1,p2,...]

Alias: trigger

Execute each of the listeners in order with the supplied arguments.
if a namespace is registered for the provided type, listeners that were registered with or without a namespace will be executed.
 
  • removeListener(type, listener, [namespace])

Alias: off

Remove a listener from the listener array for the specified event. Caution: changes array indices in the listener array behind the listener.
if a namespace is provided, only the listener that was registered with the same namespace will be removed.
  • removeAllListeners(type, [namespace])

    Removes all listeners, or those of the specified event. It's not a good idea to remove listeners that were added elsewhere in the code, especially when it's on an emitter that you didn't create (e.g. sockets or file streams). if a namespace is provided, only the listeners that were registered with the same namespace will be removed.

  • hasListener(type, [namespace])

    Returns true if a listener was registered for the provided type. if a namespace is provided, will only return true if a listener was registered with that namespace.

  • for the rest of the API, see the node documentation (EventEmitter)

Registrar

  • get(scope)

    creates a new venter instance in the provided scope or returns an existing one if one already created.

  • remove(scope)

    removes a venter (and its listeners) for the provided scope.

Examples

Example #1 - Simple

var Venter = require("venter");

var testVenter = Venter.get("my-test-scope");

testVenter.on("some_event", function(){console.log("hello");}); //on=addListener

testVenter.emit("some_event"); 

//prints 'hello' to console

Example #2 - With Namespace

var fileVenter = require("venter").get("files");

function updateFile(file){

  //update the file
  
  fileVenter.trigger("file_event", file); //trigger=emit
}

function onFileUpdate(viewName, fileData){
    console.log("something happened with the file: ", fileData);
    
    //update the relevant view
}

function getFilesFromDir(viewName, dir_name, filter){
    
    if (!fileVenter.hasListener("file_event", fileName)){
        //registers to 'file_event' with the filter as the namespace 
        fileVenter.addListener("file_event", onFileUpdate.bind(null, viewName), filter); 
    }
    
    //return files from dir based on filter
}

getFilesFromDir("main-view", "dir1", "*.jpg"); //called from view a
getFilesFromDir("list-view", "dir1", "*.gif"); //called from view b

updateFile("dir1/vaction.jpg");
updateFile("dir1/dancing_kitty.gif");