yaeti
Yet Another EventTarget Implementation
Last updated 3 years ago by ibc .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install yaeti 
SYNC missed versions from official npm registry.

yaeti

Yet Another EventTarget Implementation.

The library exposes both the EventTarget interface and the Event interface.

Installation

$ npm install yaeti --save

Usage

var yaeti = require('yaeti');

// Custom class we want to make an EventTarget.
function Foo() {
    // Call EventTarget constructor
    yaeti.EventTarget.call(this);
}
// Inherit EventTarget prototype
Foo.prototype = Object.create(yaeti.EventTarget.prototype);
Foo.prototype.constructor = Foo;

// Create an instance.
var foo = new Foo();

function listener1() {
    console.log('listener1');
}

function listener2() {
    console.log('listener2');
}
 
foo.addEventListener('bar', listener1);
foo.addEventListener('bar', listener2);
foo.removeEventListener('bar', listener1);

var event = new yaeti.Event('bar');

foo.dispatchEvent(event);

// Output:
// => "listener2"

API

yaeti.EventTarget interface

Implementation of the EventTarget interface.

ES5

function Foo() {
    yaeti.EventTarget.call(this);
}
Foo.prototype = Object.create(yaeti.EventTarget.prototype);
Foo.prototype.constructor = Foo;

ES6

class Foo extends EventTarget () {
    constructor () {
        super();
    }
}

The interface implements the addEventListener, removeEventListener and dispatchEvent methods as defined by the W3C.

listeners read-only property

Returns an object whose keys are configured event types (String) and whose values are an array of listeners (functions) for those event types.

yaeti.Event interface

Implementation of the Event interface.

NOTE: Just useful in Node (the browser already exposes the native Event interface).

var event = new yaeti.Event('bar');

Author

IƱaki Baz Castillo

License

MIT

Current Tags

  • 1.0.3                                ...           latest (3 years ago)

10 Versions

  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           7 years ago
  • 1.0.1                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
  • 0.0.6                                ...           9 years ago
  • 0.0.5                                ...           9 years ago
  • 0.0.4                                ...           9 years ago
  • 0.0.3                                ...           9 years ago
  • 0.0.2                                ...           9 years ago
  • 0.0.1                                ...           9 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (6)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |