Javascript MVC in principle
Posted
by
Michael
on Programmers
See other posts from Programmers
or by Michael
Published on 2012-05-14T20:00:41Z
Indexed on
2012/05/30
16:59 UTC
Read the original article
Hit count: 265
JavaScript
|mvc
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?
© Programmers or respective owner