Created
June 5, 2012 03:52
-
-
Save mxriverlynn/2872526 to your computer and use it in GitHub Desktop.
onShow promise for Marionette child views in a collection view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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