Permalink
Browse files

Adding additional examples

  • Loading branch information...
1 parent fd1e616 commit c481c0993529d1fc5a2cf801e93006b3839e9058 @efeminella committed Apr 18, 2012
Showing with 30 additions and 1 deletion.
  1. +30 −1 README.md
View
@@ -151,14 +151,43 @@ 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:
``` javascript
// 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
```

0 comments on commit c481c09

Please sign in to comment.