API Docs for: 1.0.0
Show:

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);

Methods

addView

(
  • view
  • eventNames
)

Adds module as one that the mediator should be listening for events.

Parameters:

  • view Backbone.View
  • eventNames String

assignCallbackToDispatcher

(
  • eventName
  • callbackName
  • dispatcher
)
private

Assigns a callback to the passed dispatcher for the event to be fired.

Parameters:

  • eventName String
  • callbackName String
  • dispatcher Object

destroy

()

destroys a mediator and removes all listeners.

getView

(
  • attribute
)

Returns a view that has the same value/key pairs provided

Parameters:

  • attribute Object

    Key/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:

  • name String

    User 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:

  • eventName Object
  • module Object

hasView

(
  • view
)

Returns boolean for whether the mediator contains a view or not.

Parameters:

  • view Backbone.View

initialize

()

Called for any modules that extend the Mediator prototype.

processEvents

(
  • events
)
private

Runs through all of the events that the mediator should be listening for.

Parameters:

  • events Object

processViewEvents

(
  • events
)
private

Processes all of the viewEvents passes in through the mediator config options

Parameters:

  • events String

removeView

(
  • view
)

Removes module from one that the mediator should be listening for.

Parameters:

  • view Backbone.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.