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

vento

v2.1.1

Published

An event superclass for automatic method generation

Downloads

8

Readme

Vento

Vento is a event library that automatically creates event methods. Vento is used to be the super class of a class. You can also simply extend your class with Vento. After this you'll be able to either fire the event from the class itself or from external. You are also able to register to the event internally AND externally. All callbacks will be executed.

I implemented this library because I could not find another library doing this simple stuff. I wrote this code nearly in every project in my company or in private projects, so I outsourced the code from the projects.

The whole source is written in ES2015, so the examples are also written in ES2015 syntax.

Install

npm install vento

Usage

First you have to import Vento to the file you want to use it.

import Vento from 'vento';

Then extend your class with Vento.

class MyClass extends Vento {}

After this you can register new events either in the constructor or somewhere else.

this.addEvent('eventName');

You can also bind an internal method directly to your event.

this.addEvent('eventName', this.eventName);

Then you can register to the event. You can create an internal on function or register from external to your event.

eventName() {
  // do something
}

or

myClass.on('eventName', () => {
  // do something
});

or

myClass.onEventName(() => {
  // do something
});

Thats it... now you can fire your custom created event.

myClass.fireEventName();

or

myClass.fireEventName('some', { data: true });

Full example

import Vento from 'vento';

class MyClass extends Vento {
  constructor() {
    this.addEvent('test', this.test);
  }

  test(data1, data2) {
    console.log('inner notification', data1, data2);
  }
}

const myClass = new MyClass();
myClass.on('test', (data1, data2) => {
  console.log('outter notification bound with on', data1, data2);
});

myClass.onTest((data1, data2) => {
  console.log('outter notification bound with onTest', data1, data2);
});

myClass.fireOnTest('first object', 'second object');

Extend extended class

what? ...

If you have a class that already extends a class... or is extended by a class you should also have the ability to use Vento. So you can just hook Vento in the constructor of your sub class.

class SubClass extends SuperClass {
  constructor() {
    super();
    Vento.extend(this);

    this.addEvent('test');
  }
}

Copyright and license

Code and documentation released under the MIT license.