Permalink
Browse files

Use regions, fixes zombie view bug

- Deleting verses now works as a result.
  • Loading branch information...
1 parent 0863f32 commit 5d225c772c87a820c72adfbd3b791f826522de6f @ismyrnow committed Feb 8, 2014
View
@@ -12,6 +12,8 @@
</head>
<body>
+ <div id="main"></div>
+
<script data-main="js/main" src="bower_components/requirejs/require.js"></script>
</body>
View
@@ -28,12 +28,17 @@ require.config({
deps : ['jquery','underscore', 'marionette-handlebars']
});
-require(['backbone', 'router', 'collections/versescollection'],
-function(Backbone, Router, VersesCollection) {
+require(['backbone', 'marionette', 'router', 'collections/versescollection'],
+function(Backbone, Marionette, Router, VersesCollection) {
'use strict';
+ window.App = new Marionette.Application();
+
+ App.addRegions({
+ mainRegion: 'body'
+ });
+
// Bootstrap verses collection and put it on the App namespace.
- window.App = {};
App.Verses = new VersesCollection();
App.Verses.fetch({
success: function() {
View
@@ -40,32 +40,30 @@ function (Backbone, VerseListView, VerseListModel, VersesCollection, VerseView,
})
});
- view.render();
+ App.mainRegion.show(view);
},
verse: function(id) {
var model = App.Verses.get(id);
var view = new VerseView({
- el: $('body'),
model: model
});
- view.render();
+ App.mainRegion.show(view);
},
newVerse: function() {
var view = new NewVerseView();
- view.render();
+ App.mainRegion.show(view);
},
editVerse: function(id) {
var model = App.Verses.get(id);
var view = new EditVerseView({
- el: $('body'),
model: model
});
- view.render();
+ App.mainRegion.show(view);
},
reset: function() {
@@ -8,8 +8,6 @@ function (Handlebars, Marionette, template, debounce) {
this.referenceChangedDebounced = debounce(this.referenceChanged, 1000);
window.Handlebars.registerHelper('select', this.selectHelper);
},
-
- el: $('body'),
template: template,
@@ -65,7 +63,9 @@ function (Handlebars, Marionette, template, debounce) {
var $el = $('<select />').html(options.fn(this));
$el.find('[value=' + value + ']').attr({'selected':'selected'});
return $el.html();
- }
+ },
+
+ onClose: function() { console.log("closing view")}
});
@@ -7,8 +7,6 @@ function (Handlebars, Marionette, template, debounce) {
initialize: function() {
this.referenceChangedDebounced = debounce(this.referenceChanged, 1000);
},
-
- el: $('body'),
template: template,
@@ -2,8 +2,6 @@ define(['backbone', 'handlebars', 'collections/versescollection', 'views/verseli
'use strict';
return Backbone.View.extend({
-
- el: $('body'),
template: template,
@@ -3,8 +3,6 @@ function (Handlebars, Marionette, template) {
'use strict';
return Marionette.ItemView.extend({
-
- el: $('body'),
template: template

0 comments on commit 5d225c7

Please sign in to comment.