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

qevents

v0.1.1

Published

Simple global event handler for event driven applications

Downloads

1

Readme

qEvents

v. 0.1.0

Installing

npm install qevents

Description

This very small module might become usefull when you want to: - Have an event-driven environment - Simple message broadcasting

What is it?

An wrapper over NodeJS native events in order to control your application via events.

It has no special requirements or dependencies.

Why use it?

You can avoid callback hell and code redundancy.

A word on coding standards

In order to keep track of events throughout your application, certain standards must be use 1. Creating listener methods 1.1 Should be function expressions in order to remove them when you want 2. Create at the beginning of the module declaration listeners methods and then create listeners. All application listeners should be loaded on applicaiton launch

Usage

1. Simple usage

controller_1.js


var qEvents = require('qevents'),
    Control_1 = {};

//--- Create a private channel for this controller
Control_1.events = new qEvents.instance('C_1Events');

/**
 * Create event listeners
 */

//--- You can create responses first

Control_1.response = {
    action: function _action () {
        console.log('Received', arguments);
    },
    tempAction: function _tempAction () {
        console.log('One time received', arguments)
    }
}

//--- Then add the listener
Control_1.events.listen('ListenAction', Control_1.response.action);

//--- And a listener that will be called once
Control_1.events.listenOnce('ListenTempAction', Control_1.response.tempAction);


//--- Dispatch locally
Control_1.events.dispatch('ListenAction', 'string param', {p2: 'Object param'});
Control_1.events.dispatch('ListenTempAction', 'string param', {p2: 'Object param'});

controller_2.js

var qEvents = require('qevents'),
    Control_2 = {};
    
//--- Dispatch to controller 1 from here
qEvents.remote.dispatch('C_1Events', 'ListenTempAction', 'param1', 'param2'); //---Will not work
qEvents.remote.dispatch('C_1Events', 'ListenAction', 'param1', 'param2'); //---Will work
2. Same listener key

If you don't care which is the order processing you can add more listeners to the same listener key

var qEvents = require('qevents'),
    Control = {};

//--- Create a private channel for this controller
Control.events = new qEvents.instance('CEvents');
    
Control.action_1: function _action () {
    console.log('Received', arguments);
}

Control.action_2: function _action () {
    console.log('Received', arguments);
}

Control.events.listen('ListenAction', Control.action_1);
Control.events.listen('ListenAction', Control.action_2);

//--- Will dispatch to both actions
Control.events.dispatch('ListenAction', 'string param', {p2: 'Object param'});
3. Chaining listeners

Once a listener receives data you can trigger new event with the build in method chainTo

var qEvents = require('qevents'),
    Control = {};

//--- Create a private channel for this controller
Control.events = new qEvents.instance('CEvents');

Control.action_1: function _action1 () {
    console.log('Received', arguments);
    
    //--- Chain locally
    this._chainTo('CEvents', 'chain_1', {param: 'Send this to chain_1 listener'});
}

Control.chain_1: function _chain1 () {
    console.log('Received', arguments);
}

//--- Create listeners
Control.events.listen('ListenAction', Control.action_1);
Control.events.listen('ListenChain', Control.chain_1);

//--- Will dispatch to both actions
Control.events.dispatch('ListenAction', 'string param', {p2: 'Object param'});

Or chain from a remote

var qEvents = require('qevents'),
    Remote = {};
    
Remote.events = new qEvents.instance('RemoteEvents');

Remote.rAction_1 = function _rAction1 () {
    this.__chainTo('CEvents', 'action_1', {rParam: "This is a remote received object"});
};

//--- Define listener
Remote.events.listen('RemoteListen', Remote.rAction_1);

//--- This will fire all the way to Control.chain_1 method
Remote.events.dispatch('rAction_1');
4. Removing listeners

Remove one listener

Control.events.remove('ListenAction', Control.action_1);

Remove all listeners

Control.events.purge('ListenAction');

[NOTE!] Remote events section has no event listener adding or event listener removing for security resons

TODO

Combine channel and header into an object
Improve internal listeners storage