1.0.0 • Published 8 years ago
@kempo/edo v1.0.0
EDO
Event Driven Object
Constructor
new EDO()
Creates a new EDO object.
Members
ready
: bool
Indicates if the ready event has been triggered yet.
Methods
on(events, handler)
: this
Start listening for events.
events
: string - A space delimited list of events to start listening for.handler
: function - A function to be called when the events occur. This function accepts two parameters, the first is the event that occured and the second is the event_data passed to thetrigger
.
once(events, handler)
: this
Starts listening for events to occur one time. Once the event occurs the handler will be automatically removed.
events
: string - A space delimited list of events to start listening for.handler
: function - A function to be called when the events occur. This function accepts two parameters, the first is the event that occured and the second is the event_data passed to thetrigger
.
off(events, handler)
: this
Stop listening for events.
events
: string - A space delimited list of events to stop listening for.handler
: function - The handler to stop calling when the event occurs.
off(events)
: this
Stop listening for events.
events
: string - A space delimited list of events to stop listening for.
off(handler)
: this
Stop listening for events.
handler
: function - The handler to stop calling when the event occurs.
trigger(events, event_data)
: this
Trigger an event within the object.
events
: string - A space delimited list of events to trigger.event_data
: anything - Some data to pass to the event handlers about this event occurance.
Special ready Event
The ready event is treated different than all other in a few ways.
- The ready event can only be triggered once. All subsequent ready events will be ignored.
- If a ready event has already been triggered and an
on
oronce
method call targets the ready event, the handler will be called immediately with theevent_data
of the previous ready event. - The
ready
member isfalse
until a ready event is triggered, then it becomestrue
and can never become change again.
- Setting the
ready
member totrue
will automatically trigger a ready event with noevent_data
.
1.0.0
8 years ago