udf-event
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published

udf-event

A lite and convenient event system

Just a simple singleton event system used by myself :)

Usage

var udfEvent = require('udf-event');

// Bind the signal with the event function: udfEvent.bind(signal, func, context);
udfEvent.on('SPEAK', function1, this);

// Bind the signal with another event function, but this function will always get called first!
udfEvent.onPriority('SPEAK', function2, this);

// Bind the signal with a 3rd event function
// But once the function3 get called, the binding of this function with this signal will be destroyed
udfEvent.onOnce('SPEAK', function3, this);

// Call the event: udfEvent.call(signal, data);
// Calls order: function2, function1, function3
udfEvent.emit('SPEAK', 'Hello!');

// Unbind the binded function with the signal
udfEvent.off('SPEAK', function1);

// Unbind all the binded functions associated with the listener
udfEvent.offBy(this);

// Destory the signal, all bindings will be destroyed
udfEvent.destroy('SPEAK');

Package Sidebar

Install

npm i udf-event

Weekly Downloads

1

Version

2.1.1

License

MIT

Unpacked Size

7.71 kB

Total Files

4

Last publish

Collaborators

  • undefineded