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/plugin-vent

v1.1.0

Published

The Veams Vent Plugin is a global publish and subscribe object. You can use this plugin to communicate between modules independently.

Downloads

280

Readme

Veams Vent Plugin (@veams/plugin-vent)

The Veams Vent Plugin is a global publish and subscribe object. You can use this plugin to communicate between modules independently.

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.

TypeScript is supported.


Installation

NPM

npm install @veams/plugin-vent --save

Yarn

yarn add @veams/plugin-vent

Usage

import Veams from '@veams/core';
import VentPlugin from '@veams/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.

Veams.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.

Veams.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.

Veams.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().

Example

Default events like click, resize and more

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

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

Custom events

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

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

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