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

@veams/vent

v2.0.1

Published

Vent is a simple publish and subscribe system you can use to communicate between modules independently

Downloads

1,766

Readme

Vent (@veams/vent)

Vent is a simple publish and subscribe system you can use to communicate between modules independently.


Installation

NPM

npm install @veams/vent --save

Yarn

yarn add @veams/vent

Standalone Usage

Use Vent to trigger events globally and subscribe to it!

Example

Default events like click, resize and more

import createVent from '@veams/vent';

const Vent = createVent(); // If using the plugin you do not need this and have the functionality available in the namespace (like `Veams.Vent`)

// Let's add a throttle to the scroll event and trigger that
window.onscroll = Veams.helpers.throttle((e) => {
    Vent.publish('scroll', e);
}, 200);

// Now we can easily catch that ...
Vent.subscribe('scroll', () => {
    console.log('Throttled scroll captured ... ');
});

Custom events

import createVent from '@veams/vent';

const Vent = createVent(); // If using the plugin you do not need this and have the functionality available in the namespace (like `Veams.Vent`)

const dataHandler = (data) => {
    // Make something with the data ...
    console.log('my custom data received by publish(): ', data);
})

Vent.subscribe('custom:event', dataHandler);

Vent.subscribe('resize', () => {
    // First we want to publish it, so that `dataHandler()` will be executed
    Vent.publish('custom:event', {
        testData: 'My test data'
    });
	
    // After that we unsubscribe to make sure that `dataHandler()` is only executed once
    Vent.unsubscribe('custom:event', dataHandler);
});

Veams Plugin

Additionally we have a plugin in place giving you the flexibility to use @veams/vent in the Veams eco system. Veams exposes a global event object (Veams.EVENTS) which can be used and extended by this plugin.

The module extends the default EVENTS object of Veams when you pass the option called furtherEvents.

Usage

import Veams from '@veams/core';
import VentPlugin from '@veams/vent/lib/plugin/vent';
import EVENTS from './custom-events';

// Intialize core of Veams
Veams.onInitialize(() => {
    // Add plugins to the Veams system
    Veams.use(VentPlugin, {
        furtherEvents: EVENTS
    });
});

Options

| Option | Type | Default | Description | |:--- |:---:|:---:|:--- | | furtherEvents | {Object} | [false] | Add your custom events to the global events object of Veams. |

Api

When enabled the Api provides a way to subscribe and unsubscribe from global events and publish to the subscribers.

Vent.subscribe(name:string, callback:function)

alias: .on()

  • @param {String} name - Event name which you subscribed to.
  • @param {Function} callback - The callback function which get executed when event is triggered.

Vent.unsubscribe(name:string, callback:function)

alias: .off()

  • @param {String} name - Event name which you have subscribed to.
  • @param {Function} callback - The callback function which is registered.

Vent.publish(name:string, obj?:object, scope?:any)

alias: .trigger()

  • @param {String} name - Event name which you have subscribed to.
  • @param {Object} obj - Optional custom data object which you can pass.
  • @param {scope} any - Optional scope/context on which you want to execute .call().