module Tilia::Event::EventEmitterInterface

Event Emitter Interface

Anything that accepts listeners and emits events should implement this interface.

Public Instance Methods

emit(event_name, arguments = [], continue_call_back = nil) click to toggle source

Emits an event.

This method will return true if 0 or more listeners were succesfully handled. false is returned if one of the events broke the event chain.

If the continueCallBack is specified, this callback will be called every time before the next event handler is called.

If the continueCallback returns false, event propagation stops. This allows you to use the eventEmitter as a means for listeners to implement functionality in your application, and break the event loop as soon as some condition is fulfilled.

Note that returning false from an event subscriber breaks propagation and returns false, but if the continue-callback stops propagation, this is still considered a 'successful' operation and returns true.

Lastly, if there are 5 event handlers for an event. The continueCallback will be called at most 4 times.

@param event_name @param [Array] arguments @param [#call, nil] continue_call_back @return [Boolean]

# File lib/tilia/event/event_emitter_interface.rb, line 50
def emit(event_name, arguments = [], continue_call_back = nil)
end
listeners(event_name) click to toggle source

Returns the list of listeners for an event.

The list is returned as an array, and the list of events are sorted by their priority.

@param event_name @return [Array<#call>]

# File lib/tilia/event/event_emitter_interface.rb, line 60
def listeners(event_name)
end
on(event_name, call_back, priority = 100) click to toggle source

Subscribe to an event.

@param event_name @param [#call] call_back @param [Fixnum] priority @return [void]

# File lib/tilia/event/event_emitter_interface.rb, line 14
def on(event_name, call_back, priority = 100)
end
once(event_name, call_back, priority = 100) click to toggle source

Subscribe to an event exactly once.

@param event_name @param [#call] call_back @param [Fixnum] priority @return [void]

# File lib/tilia/event/event_emitter_interface.rb, line 23
def once(event_name, call_back, priority = 100)
end
remove_all_listeners(event_name = nil) click to toggle source

Removes all listeners.

If the eventName argument is specified, all listeners for that event are removed. If it is not specified, every listener for every event is removed.

@param event_name @return [void]

# File lib/tilia/event/event_emitter_interface.rb, line 82
def remove_all_listeners(event_name = nil)
end
remove_listener(event_name, listener) click to toggle source

Removes a specific listener from an event.

If the listener could not be found, this method will return false. If it was removed it will return true.

@param event_name @param [#call] listener @return [Boolean]

# File lib/tilia/event/event_emitter_interface.rb, line 71
def remove_listener(event_name, listener)
end