Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript MVC framework [closed]

Has anyone used Javascript MVC Framework(s) to develop a production web app? If so what has been your experience? Thanks

like image 473
user114385 Avatar asked Sep 10 '10 23:09

user114385


1 Answers

I haven't used any specific frameworks, but I have developed an MVC-based production web app, and it's not that hard to do it yourself with the help of some other libraries.

Firstly, for Views, a good starting point is to use javascript templates (like JavaScriptTemplates) to keep all HTML markup out of your javascript files and in seperate html files. This already helps a lot.

As for Controllers and Models, I simulate similar behavior with the help of JavaScript object oriented syntax, like this:

// Create namespace for this component
App.namespace = {};

// Populate namespace
App.namespace.some_name = function () {

    // Put private variables and functions here, e.g.:
    // var privateVarName = 'privateVarValue';

    return {

        // Put public variables and functions here, e.g.:
        // publicVarName: 'publicVarValue',
    };
}();

In this way you can keep components separate in a way that makes sense for your app. For example, I had a App.ui.views object, where interaction with javascript templates takes place. There was also a datastore object, which contained all the Objects that represent something out of the database or other information. My personal preference was to have more fine-grained separation of specific types of controllers (seperated into several files), because they can become quite a lot in a full-scale javascript application.

like image 170
Herman Schaaf Avatar answered Oct 23 '22 02:10

Herman Schaaf