Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose of Javascript MVC frameworks [closed]

I am wondering the purpose of Javascript MVC frameworks such as Backbone.js and Spine.js. As an avid/experienced Ruby on Rails developer, I never had a useful case where I needed another MVC layer for my application. It just seems rather silly to me. I heavily use unobtrusive Javascript for handling events and error handling logic but it doesn't go as far as creating classes and views for my views.

Pardon my ignorance in this area but I would definitely like to get this answered from experienced developers.

like image 254
Chris Ledet Avatar asked Nov 03 '11 04:11

Chris Ledet


People also ask

What is MVC framework JavaScript?

MVC frameworks are libraries that can be included alongside JavaScript to provide a layer of abstraction on top of the core language. Their goal is to help structure the code-base and separate the concerns of an application into three parts: Model - Represents the data of the application.

What were the major problems with MVC framework?

Major drawbacks of MVC in react js include manipulation of DOM which is very expensive and also at the cost of time and memory wastage. For implementing MVC, knowledge of multiple languages and technologies is required which requires enormous manpower having different expertise.

Is MVC pattern still used?

Today the MVC pattern is used for modern web applications because it allows the application to be scalable, maintainable, and easy to expand.


2 Answers

JavaScript MVC frameworks like Backbone.js are for adding structure to your front-end.

This is most useful when building [increasingly popular] single-page JavaScript apps (SPJA). If you're heavily using unobtrusive JavaScript, you're probably doing a fair amount of ajax for dynamic content to avoid refreshing the page on the user. SPJA's take this a step further by letting the user visit all areas of an app without ever refreshing the page. Without the structure provided by MVC frameworks, the client-side code can quickly get out of control.

like image 114
sghill Avatar answered Oct 03 '22 01:10

sghill


Having a dual MVC is absolutely redundant if your web frontend is simply the presentational layer ie. a view and all your data as well as application logic resides on the server.

However many of the modern complex web apps try to maximize the user experience by creating highly interactive frontends that dynamically communicate with the server using Ajax or similar alternatives eg. Flash AMF. In such cases in the fontend of your application, separating out the script portions that handle actual communication with server, providing proper provisions for managing the local data that has been fetched/cached in the client's system, user interaction event handling and history management. Once you begin to think about it, it quickly becomes apparent that having a separate MVC layer in the javascript code is a good idea because it fits well with the scenario and makes the code manageable.

For instance, in an application like Facebook a user interaction event like pressing L when a picture is enlarged, or clicking on the Like button actually map to the same action and therefore this action should be decoupled from the part that constructs the view and attaches event handlers. Actual sending the updated metadata information to the server can be again separated out because this portion can be re-utilized for any action that updates the metadata which needs to be communicated back to the server. Similarly validation of metadata is reusable across different user actions which update the metadata.

Through this example I hope to have communicated the concept of how MVC design fits in with web frontends.

like image 44
lorefnon Avatar answered Oct 03 '22 01:10

lorefnon