Skip to content

Instantly share code, notes, and snippets.

Forked from brettjonesdev/app.js
Last active August 29, 2015 14:00
Show Gist options
  • Save stephanebachelier/11251356 to your computer and use it in GitHub Desktop.
Save stephanebachelier/11251356 to your computer and use it in GitHub Desktop.
var App = new Backbone.Marionette.Application();
main: '#main'
App.addInitializer(function() {
console.log('here'); MainLayout())
var MainLayout = Backbone.Marionette.Layout.extend({
template: '#main-layout-template',
regions: {
region1: '#region1'
//if I put this call inside onShow(), the onDomRefresh for the childview triggers. If it is called in onRender, it never triggers.
//This is because $(document).contains(view.$el); is false, because at show()-time for the ChildView, its parent has not yet been added to the DOM
//It would be really great if Marionette.Layout could trigger a dom refresh event check on children view (i.e. the currentView of its regions) in
//its own "show" event - this would make a child view's onDomRefresh much more robust and reliable. It is fairly common (at least for us) to
//have a Layout or similar parent view "show" its Children before it is itself "shown". This would be a great feature if a parent's show event
//could trigger dom refresh checks on its children views.
onRender: function() { CollectionView({
collection: [{
name: 'foo'
}, {
name: 'bar'
var CollectionView = Backbone.Marionette.CollectionView.extend({
template: '#childview-template',
onDomRefresh: function() {
//This never gets called if the view is shown inside a parent/layout view's onRender() method - only if called within the onShow() method.
console.log('CollectionView added to DOM!' );
var ItemView = Backbone.Marionette.ItemView.extend({
template: '#childview-template',
onDomRefresh: function() {
//This gets called
console.log('ItemView added to DOM!' );
$(document).ready(function() {
<title>Marionette onDomRefresh issue example</title>
<script type="text/javascript" src="src/libs/jquery-1.8.3.js"></script>
<script type="text/javascript" src="src/libs/underscore.js"></script>
<script type="text/javascript" src="src/libs/backbone.js"></script>
<script type="text/javascript" src="src/libs/backbone.marionette.js"></script>
<script type="text/javascript" src="src/libs/Handlebars.js"></script>
<script type="text/javascript" src="src/app.js"></script>
<script id="main-layout-template" type="text/html">
<h3>Main Layout</h3>
<div id="region1"></div>
<script id="childview-template" type="text/html">
<span>This is an ChildView</span>
<h1>Marionnete onDomRefresh issue example</h1>
<div id="main"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment