ComBroker Class
_controllers\ComBroker.js:1
The ComBroker is lite weight event bus that can be used inside MV* frameworks and offer services for the application. Services provided include registration and query of data members, registration and query of instances (often registered instances are service providers themselves) and a central location for binding and triggering of events.
Constructor
ComBroker
()
Object
Returns:
instantiated ComBroker
Example:
Backbone.comBroker = new ComBroker.bus(); Backbone.comBroker.setService('me',function(i_var){ alert('I am a service ' + i_var)}); var g = com.getService('me'); g("hello again"); $(com).bind('change',function(e){ alert('pop ' +e); }); $(Backbone.comBroker).triggerHandler('change'); example: Backbone.comBroker.fire(loginManager.LOGINBUTTON, this, '#loginButton', "hellow world" ); example: Backbone.comBroker.listen(loginManager.AUTHENITCATING,loginManager.LOGINBUTTON,function(e){});
Item Index
Methods
clearServices
()
Clear all current registered services
event
-
i_event
-
i_context
-
i_caller
-
i_data
The jQuery.Event constructor is exposed and can be used when calling trigger. The new operator is optional.
Parameters:
-
i_event
Event -
i_context
Object -
i_caller
Object -
i_data
Object
Returns:
none.
fire
-
i_event
-
i_context
-
i_caller
-
i_data
Trigger an event within the context of the CommBroker thus reducing DOM capture / bubble.
Parameters:
-
i_event
Event -
i_context
Event -
i_caller
Event -
i_data
Event
Returns:
none
getAllServices
()
Object
Expose all services and data members.
Returns:
m_services
getService
-
i_name
Get a registered service.
Parameters:
-
i_name
String
Returns:
m_services member
getValue
-
i_name
Get a registered data member.
Parameters:
-
i_name
String
Returns:
m_services member
initialize
()
Constructor
listen
-
events
-
func
Listen to events within the context of the CommBroker thus reducing DOM capture / bubble. Once the even is triggered func will get called back.
Parameters:
-
events
Event -
func
Function
Returns:
none
listenOnce
-
events
-
func
Listen only once to an event and unbind. Once the event is triggered func will get called back.
Parameters:
-
events
Event -
func
Function
Returns:
none
listenWithNamespace
-
events
-
caller
-
call
Listen to events within the context of the CommBroker thus reducing DOM capture / bubble. However we only listen within the namespace of a unique context id so we can remove it later for a specific listener instance.
Parameters:
-
events
Event -
caller
Object -
call
Functionback
Returns:
none
setService
-
i_name
-
i_service
Register a service that others can query.
Parameters:
-
i_name
String -
i_service
Object
Returns:
none
setValue
-
i_name
-
i_value
-
i_fireEvent
Register a data member that others can query.
Parameters:
-
i_name
String -
i_value
Object -
i_fireEvent
Event
Returns:
none
stopListen
-
events
-
func
Stop listening to an event.
Parameters:
-
events
Event -
func
Function
Returns:
none
stopListenWithNamespace
-
event
-
func
Stop listening to an event but only within the context of a specific listener instance.
Parameters:
-
event
String -
func
Function
Returns:
none