Skip to content

Commit

Permalink
added documentation for app wide events
Browse files Browse the repository at this point in the history
  • Loading branch information
liamks committed Feb 16, 2012
1 parent 09eaabf commit d78006e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app/templates/example.html
Expand Up @@ -32,6 +32,7 @@ <h1>Contents</h1>
<li><a data-bypass href="#namespace">Setting your namespace</a>
<li><a data-bypass href="#modules">Creating a module</a>
<li><a data-bypass href="#templates">Working with templates</a>
<li><a data-bypass href="#events">Working with Application Wide Events</a>
<li><a data-bypass href="#plugins">Working with libraries and plugins</a>
</ul>
<li><a data-bypass href="#custom-build">Using the build tool</a>
Expand Down Expand Up @@ -265,6 +266,33 @@ <h3 id="templates">Working with templates</h3>
</code></pre>
</p>

<h3 id="events">Working with Application Wide Events</h3>
<p>Application wide events provide a convenient way for modules to communicate with each other. <code>namespace.app</code> references a copy of the Backbone.Events object. <a href="http://documentcloud.github.com/backbone/#Events">More information on Backbone Events</a></p>

<p>
To bind a callback function to an event:
<pre><code>
//binding an annonymous function to the event 'all' with a context of <code>this</code>.
namespace.app.on('all', function(){...}, this);
</code></pre>
</p>

<p>
To remove a callback function (or many) from an event:
<pre><code>
namespace.app.off('change', doSomething); // Removes just the doSomething callback.
namespace.app.off('change'); // Removes all 'change' events.
namespace.app.off(); // Removes all events from the namespace.app object.
</code></pre>
</p>

<p>
To trigger an event:
<pre><code>
namespace.app.trigger('event', [*args]);
</code></pre>
</p>

<h3 id="plugins">Working with libraries and plugins</h3>
<p>Libraries and plugins are easily added to the application, by placing them inside the <code>assets/js/libs/</code> directory.
If you have many plugins in your application, it may make sense to create a separate folder such as <code>assets/js/plugins/</code>
Expand Down
10 changes: 10 additions & 0 deletions readme.md
Expand Up @@ -132,6 +132,16 @@ MyModule.Model = Backbone.Model.extend({ /* ... */ });
MyModule.Router = Backbone.Router.extend({ /* ... */ });
```

## Events ##

Application wide events provide a convenient way for modules to communicate with each other. `namespace.app` references a copy of the Backbone.Events object, providing access to `.on()`, `.off()`, and `.trigger()`, that are documented in (Backbone.js Events)[http://documentcloud.github.com/backbone/#Events]

For example, to add a callback to the 'all' event:

```javascript
namespace.app.on('all', function(){}, this);
```

## HTML5 History and Hash Based Navigation ##

Out the box Backbone Boilerplate enables `pushState`. It also supplies a script
Expand Down

0 comments on commit d78006e

Please sign in to comment.