Caplin Trader 4.7.1

Class: module:br/util/ListenerFactory

module:br/util/ListenerFactory

Utility class for creating listener objects that re-route incoming events to a method of your choice.

This class is useful in the following scenarios:

  • Objects that are only interested in a single event, and don't want to implement the entire interface.
  • Objects that need to implement the same interface multiple times so they can observe multiple objects — this is only possible using proxy listeners like this.

Constructor

new module:br/util/ListenerFactory(interfaceFunc, eventName)

Construct a new ListenerFactory that can create listeners for the given event, on the given interface.
Parameters:
Name Type Description
interfaceFunc function The listener interface that objects created with this factory will implement.
eventName String The particular event on the listener interface that will be proxied through.

Methods

createListener(call)

Returns a listener that will forward received events through to the given method on the given object.
Parameters:
Name Type Description
call function The call-back to use for the created listener.