@legworkstudio/eventful

1.0.0 • Public • Published

Eventful

A helper class for events.

Build Status

Use

let Eventful = require('eventful');

class MyClass extends Eventful{
	constructor(){
		super();
	}
}

Listen:

_myObject.on('some-event', (event) => console.log(event) );

Trigger:

_myObject.trigger('some-event', {foo: bar, fizz: buzz, data: {} }); _myObject.trigger('some-other-event');

Detach:

_myObject.off('some-event');

With Eventful you can attach listeners to any object that you have access to and transfer data between the caller and the object.

Returns

Will return an object with the event and any data associate with that event.

{
	ev_type: 'some-event'
	foo: bar,
	fizz: buzz,
	data: {}
}

Methods

on('event-type'): Attach an event (string) off('event-type'): Detaches an event that has been attached (string) trigger('event-type', {}): Triggers an event (string, data)

Tests

To run tests npm test

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.01latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.01

Package Sidebar

Install

npm i @legworkstudio/eventful

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • legworkstudio