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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:21:59+00:00 2026-06-01T22:21:59+00:00

I have an application that has a middle panel that always changes depending on

  • 0

I have an application that has a middle panel that always changes depending on what part of the application the user is looking at. These might be messages, transactions etc.

Then there are 4 ‘fixed’ panels at the 4 corners of the application around the middle panel that are mostly fixed for the lifetime of the application, but contain dynamically updated data and therefore need to be implemented using backbone.js

How do I structure such an application in backbone.js. It seems to defeat the “Do not repeat” rule to implement the intial rendering for all the side panels within every route in the router as I would end up repeating the same rendering code in every route.

How do I structure my code in this instance so that I don’t repeat code in multiple places.

  • 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-01T22:22:01+00:00Added an answer on June 1, 2026 at 10:22 pm

    JavaScript is like any other code: if you find yourself writing the same lines of code, extract them in to a function. If you find yourself needing to use the same function, extract it (and related functions and data) in to its own object.

    So, your router shouldn’t be calling your views and models directly. Instead, it should be delegating to other objects that can manipulate your views and objects.

    Additionally, since your going to set up the same basic page layout every time the app starts up, you might not want that code in the router. The layout happens whether or not the router fires, and no matter which route is fired. Sometimes it’s easier to put the layout code in another object, as well, and have the layout put in place before the router fires up.

    
    
    MyApplication = {
      layout: function(){
        var v1 = new View1();
        v1.render();
        $("something").html(v1.el);
    
        var v2 = new View2();
        v2.render();
        $("#another").html(v2.el);
      },
    
      doSomething: function(value){
        // do someething with the value
        // render another view, here
        var v3 = new View3();
        v3.render();
        $("#whatever").html(v3.el);
      }
    }
    
    MyRouter = Backbone.Router.extend({
      routes: {
        "some/route/:value": "someRoute"
      },
    
      someRoute: function(value){
        MyApplication.doSomething(value);
      }
    });
    
    // start it up
    MyApplication.layout();
    
    new MyRouter();
    
    Backbone.history.start();
    

    I’ve written a handful of articles relating to these things, which you might find useful:

    http://lostechies.com/derickbailey/2012/02/06/3-stages-of-a-backbone-applications-startup/

    http://lostechies.com/derickbailey/2011/08/30/dont-limit-your-backbone-apps-to-backbone-constructs/

    http://lostechies.com/derickbailey/2011/12/27/the-responsibilities-of-the-various-pieces-of-backbone-js/

    http://lostechies.com/derickbailey/2012/03/22/managing-layouts-and-nested-views-with-backbone-marionette/

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

Sidebar

Related Questions

I have an application that has many threads processing data. As part of this
I have application that has to check multiple data from user table, in order
I have an application that has a user log in and log out. On
We have an application that has to be flexible in how it displays it's
I have an application that has created a number of custom event log sources
I have an application that has Powershell 1 embedded into it, but we need
I have an application that has many different types of objects that each persist
We have an application that has one or more text console windows that all
I have an application that has several objects (about 50 so far, but growing).
I have an application that has two threads. The first one (the main thread)

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.