Skip to content

Instantly share code, notes, and snippets.

@mxriverlynn
Created June 5, 2012 03:52
Show Gist options
  • Save mxriverlynn/2872526 to your computer and use it in GitHub Desktop.
Save mxriverlynn/2872526 to your computer and use it in GitHub Desktop.
onShow promise for Marionette child views in a collection view
ItemView = Marionette.ItemView.extend({
// ...
onShow: function(){
// I am guaranteed to be called from the CollectionView
// because the CollectionView registers me in a promise
}
});
CollectionView = Marionette.CollectionView.extend({
initialize: function(){
this.onShowCallbacks = new Marionette.Callbacks();
},
onShow: function(){
this.onShowCallbacks.run();
},
appendHtml: function(cv, iv){
cv.append(iv.el);
// promise to run 'onShow' if it exists
if (iv.hasOwnProperty("onShow")){
this.onShowCallbacks.add(iv.onShow);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment