Update 1/2012: A slimmer, more clean version of the application is now available in
new-version. For historical context you can still access the older app in
module-activator-version should you wish to use it.
The implementation includes:
- The Mediator pattern for centralized Pub/Sub
- Facade pattern for security/permissions
- RequireJS + AMD modules for organization and modular development
- Backbone.js for MV* structure
- jQuery 1.7.1
- Templating via Underscore
The application is broken down into AMD modules that contain distinct pieces of functionality (eg. views, models, collections, app-level modules). The views publish events of interest to the rest of the application and modules can then subscribe to these event notifications.
subscriptions go through a facade (or sandbox). What this does is check against the subscriber name and the 'channel/notifcation' it's attempting to subscribe to - if a subscriber doesn't have permissions to do this (something established through permissions.js), the subscription isn't allowed through. The rest of the application is however able to continue functioning.
For demonstration, see the permissions manager (permissions.js). By changing say, permissions -> renderDone -> todoCounter to be false, you can completely disable that component from displaying counts (because it isn't allowed to subscribe to that event). The rest of the Todo app can still however be used without issue. Nifty, eh?
The most important part of this application can be found in the
js/aura directory (mediator.js for centralized pub/sub and facade.js + permissions.js for permissions for sandboxing and security). The main directory contains the usual models/views/collections etc. whilst the modules.js file hosts the subscriber 'modules' consuming events broadcast (published) from the views.
I strongly recommend using the updated
new-version of the code. If however you opt for the
module-activator-version, note that
app/scripts/util contains a set of helpers for module loading and execution. Whilst that version of the app use theses helpers, they are by no means absolutely required for successfully creating Backbone applications using AMD modules.
For more information on writing applications using AMD modules see my guide.
The older module-activator-version is based on portions by Ryan Rauh