<commit_before>Helper and utility classes that fill out Backbone for serious development.

Inspired by our projects and the Backbone.js on Rails book:
http://workshops.thoughtbot.com/backbone-js-on-rails

The book contains complete instructions and in-depth coverage of the internals
of CompositeView and Swappingrouter, and an example application that shows
their usage.

### SwappingRouter

A Router subclass the provides a standard way to swap one view for another.

This introduces a convention that all views have a `leave()` function,
responsible for unbinding and cleaning up the view. And the convention that
all actions underneath the same `Router` share the same root element, and
define it as `el` on the router.

Now, a `SwappingRouter` can take advantage of the `leave()` function, and
clean up any existing views before swapping to a new one.  It swaps into a new
view by rendering that view into its own `el`:

    swap: function(newView) {
      if (this.currentView && this.currentView.leave) {
        this.currentView.leave();
      }

      this.currentView = newView;
      this.currentView.render();
      $(this.el).empty().append(this.currentView.el);
    }<commit_msg>Better explanation of the utility classes based on feedback from <NAME>.<commit_after>There's no built-in garbage collection for Backbone’s event bindings, and 
forgetting to unbind can cause bugs and memory leaks.

Backbone Support currently provides two utility classes, SwappingRouter and CompositeView,
that introduce a `leave()` function, which unbinds and cleans up the view.
They should be used where views are instantiated (in Router instances and in composite views).

Inspired by our projects and the Backbone.js on Rails book:
http://workshops.thoughtbot.com/backbone-js-on-rails

The book contains complete instructions and in-depth coverage of the internals
of CompositeView and SwappingRouter, and an example application that shows
their usage.

### SwappingRouter

A Router subclass the provides a standard way to swap one view for another.

This introduces a convention that all views have a `leave()` function,
responsible for unbinding and cleaning up the view. And the convention that
all actions underneath the same `Router` share the same root element, and
define it as `el` on the router.

Now, a `SwappingRouter` can take advantage of the `leave()` function, and
clean up any existing views before swapping to a new one.  It swaps into a new
view by rendering that view into its own `el`:

    swap: function(newView) {
      if (this.currentView && this.currentView.leave) {
        this.currentView.leave();
      }

      this.currentView = newView;
      this.currentView.render();
      $(this.el).empty().append(this.currentView.el);
    }
{'fraction_non_alphanumeric': 0.06881564650488953, 'fraction_numerical': 0.0, 'mean_word_length': 4.133828996282528, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5021057', 'n_tokens_mistral': 739, 'n_tokens_neox': 705, 'n_words': 351}