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

partyline

v0.0.15

Published

Extension of EventEmitter that allows for multiple objects to act as shared observers

Downloads

3

Readme

Partyline

Turn your modules into a busybody.

What is it?

Partyline is a NodeJS module that extends the EventEmitter object. It can be used as a mediator, or can return a new contructor function for your modules/objects that can listen/observe all events across any/all other inherited objects that are set using the .register() method.

How to use it?

Include it as you would any other module, and derive a new instance

var pl = require('./partyline');

Now you can use the Partyline instance's .derive() method to be the basis for your custom module/constructor(s). Note that the returned constructor function also makes an internal call to an method .init(), which can be used to set any internal variables or set up code within the constructor.

var MyModule = pl.derive();

var MyOtherModule = pl.derive();
MyOtherModule.prototype.init = function(){
    // your own inititalization code here
};

var objectA = new MyModule();

// will run your code set in the .init() method above
var objectB = new MyOtherModule();

With your modules inheriting from Partyline, they all can register events which will be observed by any instance that inherits from Partyline. Expanding from the code above, we can do this:

objectA.register('someEvent', function(){
    console.log("This is objectA");
});

objectB.register('someEvent', function(){
    console.log("objectB here");
});

This has registered 2 objects to the 'someEvent' event. Now objectA, objectB, and pl are all able to trigger 'someEvent' by using the .broadcast() method.

// you cant trigger "someEvent" in this way
objectA.broadcast('someEvent');

// as will this
objectB.broadcast('someEvent');

// and also this
pl.broadcast('someEvent');

// any one of the above object's broadcast calls will produce the same log output of:
// "This is objectA"
// "objectB here"

Also remember, that since Partyline extend NodeJS' events.EventEmitter object, all instances above are able to use .on() and .emit() methods as you would do so with EventEmitter. Note that using events in this manner are not broadcasted to children of Partlyline.

Lastly, if using Browserify, you can include Partyline into your clientside scripts as well.

API

.derive([function])

Returns a function who's prototype matches Partyline's prototype. This function can then be further extended as needed with your own functionality. You may also extend a current constructor function by passing it as an argument. In this case, the return value will be your updated constcuctor.

.register(event, callback)

Adds and event with callback to the .registries object. Can be triggered by any descendant of Partyline.

.broadcast(ev, data)

Fires an event (ev) to all descendants of Partyline that registered the emitted event name

.registries

An object that stores all the events/callbacks set with .register()