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 8531969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:36:19+00:00 2026-06-11T09:36:19+00:00

I have a very complex Backbone application with many views/Models and collections. at times

  • 0

I have a very complex Backbone application with many views/Models and collections.

at times when user clicks a button I need to update multiple collections and update certain views.

In order to manage the collections I’ve handled most events in my router. The sequence of events is as follows:

user clicks a link/button and view triggers an event:

 this.model.trigger('someEvent');

the model listening to the event, updates itself if necessary and notifies the router through my eventbus

eventbus.trigger('globalEVent');

My router is listening to global events, fetches collections/models from a cached storage and updates the necessary collections and models.

This has worked really well so far but

I have just too many events and my router code is becoming hard to manage. My question is there a way to handle events outside of the router and still access methods inside the router? is my approach correct or is there a more elegant solution I haven’t considered?

Update:

Here’s how I do it now:

in Router I call this method in my initialize():

        registerModules : function() {
           var self = this;
           Backbone.trigger(Events.RegisterModule, function(moduleRoutes) {

           _.each(moduleRoutes, function(moduleRoute) {
               self.routeDetails[moduleRoute.name] = {
                  buildPageUrl: moduleRoute.buildPageUrl,
                  fragment :  moduleRoute.fragment
               }
               self.route(moduleRoute.fragment, moduleRoute.name, moduleRoute.action);
           });

           });
        },

Then I have regular self-exec blocks for each module/page which self registers (simplified version):

(function() {

   var module = {

            loadAndDisplay: function() {},
            saveAndContinue: function(model) {

                Backbone.trigger(Events.ChangePage, model.get('nextPage'));

            },
            registerEvents: function() {},
            _init: function() {
                module.registerEvents();
                var self = this,
                    routes =  [{
                        fragment: Constants.FRAGMENT,
                        name: Constants.PAGE_NAME,
                        buildPageUrl:  function() {
                            return Constants.FRAGMENT;
                        },
                        action: module.loadAndDisplay
                    }];

                Backbone.on(Events.RegisterModule, function(registerCallback) {
                    registerCallback.call(registerCallback, routes);
                });
            }
        };

    module._init();    

})();

Of course your Router script should load before your module code. It works great for my needs. With this design I have separated router / modules completely and they have no knowledge of each other either. Each will handle it’s own events/data etc. Shared logic goes in router.

  • 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-11T09:36:20+00:00Added an answer on June 11, 2026 at 9:36 am

    You should split you router functionality into different classes. In our Marionette based application we using a RegionManager to handle all the view related stuff, like change views in different areas, open overlays etc and a StateMachine. The router itself just trigger different events, like state:change or region:change where the manager classes listen to.

    Doing it tis way, you can have a different manager classes that handle a special aspect of your app. Let the router to what he is build for: listen on location change events and notify the app about it. The router should not have other logic then this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very complex controller with a very complex set of views and
I have a very complex system (100+ threads) which need to send email without
I have a very complex function in as3. The function is composed of many
I have a very complex application (let's say enterprise application) deployed in Websphere 7
I have a very complex cross-platform application. Recently my team and I have been
I have a very complex Flash application (think Photoshop in Flash). There is a
Have a web-page with very complex structure and javascript logic with many ajax calls,
I have a very complex Oracle view based on other materialized views, regular views
I have a very complex input message whose node names and values I need
I have a very complex web app project I want to re-structure. Naturally, it

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.