trigger loading view when collection or model fetched
backbone.js, marionette
Solution
A few days ago, Derick Bailey posted a possible solution in the Marionette Wiki: https://github.com/marionettejs/backbone.marionette/wiki/Displaying-A-%22loading-...%22-Message-For-A-Collection-Or-Composite-View
Problem
I've been using Marionette for a week now and it really made my life easier! Right now I need to be able to notify a user when a collection or model is being fetched, because some views take a significant amount of time to render/fetch. To give an example I've made a small mockup: When a user clicks on a category, a collection of all items within that category need to be loaded. Before The collection is fetched I want to display a loading view as seen in the image (view 1). What would be an elegant solution to implement this. I've found the following post where a user enables a fetch trigger: http://tbranyen.com/post/how-to-indicate-backbone-fetch-progress . This seems to work but not really like I wanted to. This is something I came up with: ``` var ItemThumbCollectionView = Backbone.Marionette.CollectionView.extend({ collection: new ItemsCollection(userId), itemView: ItemThumbView, initialize: function(){ this.collection.on("fetch", function() { //show loading view }, this); this.collection.on("reset", function() { //show final view }, this); this.collection.fetch(); Backbone.history.navigate('user/'+identifier); this.bindTo(this.collection, "reset", this.render, this) } }); ``` It would be nice though If I could have an optional attribute called 'LoadItemView' for example. Which would override the itemView during a fetch. Would this be a good practice in your opinion?