Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8728193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:34:41+00:00 2026-06-13T08:34:41+00:00

Good day! Recently I have been into backbone/require, and getting to learn some really

  • 0

Good day!

Recently I have been into backbone/require, and getting to learn some really cool stuff. I am trying to learn what is the best practice for showing the loading bar/spinner when a backbone collection is being fetched. Here are some strategies that I found as being used, for triggering a fetch/syncing event on the collection:

Method 1: Override the backbone’s sync method before the application starts, and trigger a ‘syncing’ event on that collection

Method 2: Override the backbone’s fetch method before the application starts, and trigger a ‘fetching’ event on that collection

Method 3: When a collection is being defined, override the fetch() method and trigger an event ‘fetching’, so that any instance can be monitored for fetching

Method 4: Some people suggest using event aggregation so that when a view calls fetch() for a collection, that view triggers an event.

Here is my situation:

  • Lets say I have a collection C
  • There are 2 views V1 and V2 that have access to it
  • V1 can call fetch on C but V2 can’t
  • When C starts the fetch, only V2 is supposed to display a loading bar, and turn it off when reset() is called on C
  • There can also be other views V3, V4 etc which might also need to the loading bar when C is being fetched

What would be the best mechanism to to show the loading bar, keeping strict MVC pattern intact?

Option 1: Should the views listen to a ‘syncing’ event on the collection? Problem: If other fetch(), save() is called, the loading bar might display

Option 2: Should the views listen for a ‘fetch()’ event on the collection and act accordingly?

Option 3: Should one view inform another when it calls fetch() on a collection?

Option 4: Should the view call a fetching method on the window or an event aggregator?

Other Methods and Options are also welcomed. Your suggestions and advice would be the best resource. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:34:42+00:00Added an answer on June 13, 2026 at 8:34 am

    In a context of Backbone.View, as an example:

    initialize: function() {
       this.state_loading();
    
       // assuming this.collection is your collection which is not fetched yet...       
       this.collection.bind('reset', this.state_loaded, this);
       this.collection.fetch();
    },
    
    state_loading: function() {
       this.el.addClass('st-loading');
    },
    
    state_loaded: function() {
       this.el.removeClass('st-loading');
    }
    

    Now class .st-loading on the View element will simply display a spinner wherever you need, e.g.

    .ajax-spinner { backgrund: url('...'); display: none; }
    .st-loading .ajax-spinner { display: block; }
    

    Now thoughts about your options:

    Method 1: Don’t override libraries. Next guy working on your code in production will curse you for that.

    Method 2: You are better off triggering custom events on collection, you don’t need to override any native Backbone methods. Again, this type of hacking is done only when you can’t come up with good solutions.

    Method 3: I guess your idea is that EVERY time something is loading you want to show a spinner? I would feel sorry for your users.

    Method 4: If this is happening inside one view, you don’t need to use event hubs. In the end, you can trigger custom event on a collection, and parent widget can subscribe to it. Another consideration is that you would most likely need to show spinner in different types of elements, and you would need to pass reference or selector for them for different views. Now if you want to have a universal solution, of course you can give your spinners same class application wide, but then you’ll have a hell of headache if one day you want to remove them. You’re definitely better off keeping these things localized to your views.

    We have similar situation in a large app which is Backbone-driven. And for this purpose we have an extension which we apply to views that need to display a spinner. It looks somewhat like this:

    var state_loading: function() {
      if (arguments.length === 0 || arguments[0] === true) {
        this.el.addClass('st-loading');
      } else {
        this.el.removeClass('st-loading');
      }
    }
    
    var SomeView = Backbone.View.extend({
      initialize: function(options) {
        this.options = _.extend({}, this.options || {}, options || {});
        this.collection = this.options.collection;
        this.collection.bind('reset', this.render, this);
        this.state_loading(true);
        this.collection.fetch();
      },
    
      render: function() {
        this.state_loading(false);
        // your code...
      }
    });
    
    _.extend(SomeView.prototype, state_loading);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good Day, I have a PL-SQL query as follows. I'm trying to execute a
Good day, I have a gen_server process which does some long-running state-updating tasks periodically
Good day, to stackoverflow community. I have run into a bug with regard to
I have been recently looking into NServiceBus, as I thought messaging would be a
Good day, I have recently started playing with RingoJS along with Stick middleware and
Good Day, I am new to android and using Eclipse 3.7.2. I have been
Good day, I have a class that implements the LoaderCallbacks, and hence have the
Good day I have a custom TextBox that has a IndicatorTextBox.ui.xml file as well
Good day, I have like 15 images I need to be buttons. I have
Good Day, I have a simple working routine in Perl that swaps two words:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.