Class: EventLite

EventLite()

new EventLite()

event-lite.js - Light-weight EventEmitter (less than 1KB when gzipped)
License:
  • MIT
Source:
See:
Example
var EventLite = require("event-lite");

function MyClass() {...}             // your class

EventLite.mixin(MyClass.prototype);  // import event methods

var obj = new MyClass();
obj.on("foo", function() {...});     // add event listener
obj.once("bar", function() {...});   // add one-time event listener
obj.emit("foo");                     // dispatch event
obj.emit("bar");                     // dispatch another event
obj.off("foo");                      // remove event listener

Methods

(static) mixin(target)

Import on(), once(), off() and emit() methods into target object.
Parameters:
Name Type Description
target Prototype
Source:

emit(type, valueopt) → {boolean}

Dispatch (trigger) an event.
Parameters:
Name Type Attributes Description
type string
value * <optional>
Source:
Returns:
True when a listener received the event
Type
boolean

off(typeopt, funcopt) → {EventLite}

Remove an event listener.
Parameters:
Name Type Attributes Description
type string <optional>
func function <optional>
Source:
Returns:
Self for method chaining
Type
EventLite

on(type, func) → {EventLite}

Add an event listener.
Parameters:
Name Type Description
type string
func function
Source:
Returns:
Self for method chaining
Type
EventLite

once(type, func) → {EventLite}

Add one-time event listener.
Parameters:
Name Type Description
type string
func function
Source:
Returns:
Self for method chaining
Type
EventLite