Rebar.Mediator Class
Simple implementation of the mediator pattern for use with Backbone.Views
Constructor
Rebar.Mediator
()
Example:
var mediator = new Mediator({
events:{
"appwide1":{
dispatcher:app
callback:"method"
}
},
initialize:function(options){
...
},
method:function(e){
...
},
handle:function(eventName,module){
...
}
});
mediator.addView(view,"event1 event2");
view.trigger("something",view);
mediator.removeView(view);
Item Index
Methods
Methods
addView
-
view -
eventNames
Adds module as one that the mediator should be listening for events.
Parameters:
-
viewBackbone.View -
eventNamesString
assignCallbackToDispatcher
-
eventName -
callbackName -
dispatcher
Assigns a callback to the passed dispatcher for the event to be fired.
Parameters:
-
eventNameString -
callbackNameString -
dispatcherObject
destroy
()
destroys a mediator and removes all listeners.
getView
-
attribute
Returns a view that has the same value/key pairs provided
Parameters:
-
attributeObjectKey/Value pair to use with an UnderscoreJS _.with look up
Example:
...
mediator.getView({name:"foo"});
getViewByName
-
name
Returns a view that has the same user defined name provided
Parameters:
-
nameStringUser defined view name
Example:
...
mediator.getView({name:"foo"});
handle
-
eventName -
module
Handler method that is called when one of the module the mediator is listening
for is fired. Should be overwritten in Mediator instances.
Parameters:
-
eventNameObject -
moduleObject
hasView
-
view
Returns boolean for whether the mediator contains a view or not.
Parameters:
-
viewBackbone.View
initialize
()
Called for any modules that extend the Mediator prototype.
processEvents
-
events
Runs through all of the events that the mediator should be listening for.
Parameters:
-
eventsObject
processViewEvents
-
events
Processes all of the viewEvents passes in through the mediator config options
Parameters:
-
eventsString
removeView
-
view
Removes module from one that the mediator should be listening for.
Parameters:
-
viewBackbone.View
Properties
_views
Array
private
Stores reference to all views added to the mediator.
view
Backbone.View
Reference to a single view who we'll be mediating for.
