Skip to content

Instantly share code, notes, and snippets.

@theseyi
Forked from mxriverlynn/onShow.js
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theseyi/27ba67996fbd66969830 to your computer and use it in GitHub Desktop.
Save theseyi/27ba67996fbd66969830 to your computer and use it in GitHub Desktop.
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