The idea is you can still use Backbone.View
to structure components in the screen. Run the code below with each page render.
In CoffeeScript:
$ ->
for el in $('[data-view]')
$el = $ el
viewName = $el.data 'view'
view = window[viewName]
new view(el: el) if view?
In JavaScript:
$(function() {
$('[data-view]').each(function(el) {
var $el = $(el),
viewName = $el.data('view'),
view = window[viewName];
if (view) new view({el: el});
});
});
The assumption above is every view class is accessible from the window
namespace, and this goes against the visibility principles of AMD. I say: get over it.
Now in your markup, declare which view controls a certain piece of markup by doing:
<section class="new-post" data-view="NewPostView">
...
</section>
Voila. Backbone views working with regular page renders.