udf-event
v2.1.1
Published
A lite event system
Downloads
4
Maintainers
Readme
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');