Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the best way for showing a loading bar/spinner when a backbone collection is being fetched?
    text
    copied!<p>Good day!</p> <p>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:</p> <p><strong>Method 1:</strong> Override the backbone's sync method before the application starts, and trigger a 'syncing' event on that collection</p> <p><strong>Method 2:</strong> Override the backbone's fetch method before the application starts, and trigger a 'fetching' event on that collection</p> <p><strong>Method 3:</strong> When a collection is being defined, override the fetch() method and trigger an event 'fetching', so that any instance can be monitored for fetching</p> <p><strong>Method 4:</strong> Some people suggest using event aggregation so that when a view calls fetch() for a collection, that view triggers an event.</p> <p>Here is my situation:</p> <ul> <li>Lets say I have a collection C</li> <li>There are 2 views V1 and V2 that have access to it</li> <li>V1 can call fetch on C but V2 can't</li> <li>When C starts the fetch, only V2 is supposed to display a loading bar, and turn it off when reset() is called on C</li> <li>There can also be other views V3, V4 etc which might also need to the loading bar when C is being fetched</li> </ul> <p>What would be the best mechanism to to show the loading bar, keeping strict MVC pattern intact?</p> <p><strong>Option 1:</strong> Should the views listen to a 'syncing' event on the collection? Problem: If other fetch(), save() is called, the loading bar might display</p> <p><strong>Option 2:</strong> Should the views listen for a 'fetch()' event on the collection and act accordingly?</p> <p><strong>Option 3:</strong> Should one view inform another when it calls fetch() on a collection?</p> <p><strong>Option 4:</strong> Should the view call a fetching method on the window or an event aggregator?</p> <p>Other Methods and Options are also welcomed. Your suggestions and advice would be the best resource. Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload