Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose I want to implement MVC in JavaScript. I am not asking about MVC framewo

ID: 646185 • Letter: S

Question

Suppose I want to implement MVC in JavaScript. I am not asking about MVC frameworks. I am asking how to build it in principle.

Let's consider a search page of an e-commerce site, which works s follows:

User chooses a product and its attributes and press a "search" button.
Application sends the search request to the server, receives a list of products.
Application displays the list in the web page.
I think the Model holds a Query and list of Product objects and "publishes" such events as "query updated", "list of products updated", etc. The Model is not aware of DOM and server, or course.

View holds the entire DOM tree and "subscribes" to the Model events to update the DOM. Besides, it "publishes" such events as "user chose a product", "user pressed the search button" etc.

Controller does not hold any data. It "subscribes" to the View events, calls the server and updates the Model.

Does it make sense?

Explanation / Answer

What you say make sense and it's the approach used in HTML5 frameworks like Sencha Touch 2 (http://www.sencha.com/products/touch/).

MVC is a pattern and is not tied to any specific language, framework or class library. So it is possibile to use it with Javascript also, regardless of specific technology employed.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote