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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:34:21+00:00 2026-05-30T22:34:21+00:00

My app view model is growing very large. How do I properly split it

  • 0

My app view model is growing very large. How do I properly split it up into files and namespaces? Do I create a second namespace object and have the view model be passed in as a parameter?

var BALL = {};
BALL.roll = function(avm) { // function code };
  • 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-05-30T22:34:23+00:00Added an answer on May 30, 2026 at 10:34 pm

    My personal preference is not to split up my applyBindings calls and instead work with a single global namespace branch off of this.

    My reasoning is that for multiple bindings to work correctly and not conflict you need to be very careful your selected target dom elements do not change. Unfortunately the markup has a nasty habit of changing over time which can get you in trouble with your viewModels later on.

    My general approach which i’ve used on a very large KO project has been

    1. One global top level namespace for the whole app eg myapp
    2. Split up separate functional blocks into separate files. Usually with their own distinct namespace. e.g. `myapp.navigation’
    3. If one namespace in particular gets too big split it into further sub namespaces or if that is not appropriate split the same namespace across multiple files.
    4. Mash all the files at the end to preserve performance.

    Some namespace code I’ve recently been using

    var Namespace = (function() {
        var namespace, global, root;
    
        namespace = function(identifier, contents) {
            if (!identifier || identifier.length == 0) {
                throw Error("A namespace identifier must be supplied");
            }
            global = window;
    
            // create the namespace
            var parts = identifier.split(".");
            for (var i = 0; i < parts.length; i += 1) {
                if (!global[parts[i]]) {
                    global[parts[i]] = {};
                }
                if (i == 0) {
                    root = global[parts[i]];
                }
                global = global[parts[i]];
            }
    
            // assign contents and bind
            if (contents) {
                global.$root = root;
                contents.call(global);
            }
        };
    
        return namespace;
    })();
    

    So in your myapp.navigation file you would have

    Namespace("myapp.navigation", function() {
         var self = this; // your myapp.navigation object
    
         this.someFunction = function() {
         }       
    });
    

    This is just shorthand for using a self invoking function to pass in a manually constructed namespace. It gives you a private closure and you are free to use multiple Namespace calls with the same namespace in different js file.

    Your applyBindings call can now always be

    ko.applyBindings(myapp);
    

    Hope this helps.

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

Sidebar

Related Questions

My app's main view has a uiwebview. It is white for a split second
in the django admin, in any app model, the diplay data (datagrid o view
I am using the Model View View-Model pattern for a WPF app. I have
When writing a MVVM WPF app, there's always a point where the view model
hello i'm building a wpf app with data grids, the pattern is model view
I am using Ninject to inject view model instances into the DataContext property of
In an MVC3 app, using jquery unobtrusive validation, and a view/model with a [Remote]
I'm building a winforms app utilizing passive-view MVP and Castle Windsor as an IoC
I am creating a nav-based app with a view that floats at the bottom
My app uses a landscape only view and requires the user to answer a

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.