Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding additional examples

  • Loading branch information...
commit c481c0993529d1fc5a2cf801e93006b3839e9058 1 parent fd1e616
@efeminella authored
Showing with 30 additions and 1 deletion.
  1. +30 −1 README.md
View
31 README.md
@@ -151,6 +151,36 @@ var Users = Backbone.Collection.extend(
});
```
+Modules can use different namespaced `EventBrokers` for different things...
+``` javascript
+// Register event/callbacks based on a hash and associated context
+var CartView = Backbone.View.extend(
+{
+ itemsBroker: Backbone.EventBroker.get('items'),
+ inventoryBroker: Backbone.EventBroker.get('inventory'),
+
+ initialize: function()
+ {
+ this.itemsBroker.register({
+ 'add' : 'select',
+ 'update' : 'update',
+ 'remove' : 'remove'
+ }, this );
+ this.inventoryBroker.register({
+ 'select' : 'select',
+ 'deselect' : 'deselect',
+ 'edit' : 'edit'
+ }, this );
+ },
+ add: function() { ... },
+ update: function() { ... },
+ remove: function() { ... },
+ select: function() { ... },
+ deselect: function() { ... },
+ edit: function() { ... }
+});
+```
+
### Determining if an EventBroker has been created
To test if an `EventBroker` has been created for a given `namespace`, invoke the `has` method:
@@ -158,7 +188,6 @@ To test if an `EventBroker` has been created for a given `namespace`, invoke the
// determines if an event broker for the given namespace exists
var EventBroker = Backbone.EventBroker;
EventBroker.get( 'roles' ); // returns the 'roles' EventBroker
-
EventBroker.has( 'roles' ); //true
EventBroker.has( 'users' ); //false
```
Please sign in to comment.
Something went wrong with that request. Please try again.