Java Reference
In-Depth Information
that may happen in the views. Most MVC implementations also tend to be more general-
ized in their implementation and avoid hard coding details about which elements are being
updated on the page (such as the reference to the " list " id in the example). Despite this, I
hope the example demonstrates how to separate code into the three distinct components of
MVC.
Note: Saving Data
Most web applications will need some form of persistence to save the in-
formation held in the models in order to maintain state. This could be done
using the Web Storage API that we covered in the last chapter . Another op-
tion that's often used in real-world applications is to send a JSON repres-
entation of the model to a back-end database using Ajax whenever a model
changes.
MVC Frameworks
MVC can take a lot of code to implement, and many frameworks have emerged that take
care of much of the setup code for you. One of the main features of MVC frameworks is
data binding, which is the process of linking the model and view together. As a result, a
large amount of boilerplate controller code is not needed as the framework takes care of
it all in the background for you. One-way data binding is when a change in the model
will automatically result in the view being updated, and two-way data binding is when a
change in the view automatically updates the model.
These methods are often accessed by a user via routes using the hashtag notation. The con-
troller will look for anything after a hashtag in a URL for information about what to do. For
example, the URL http://ninjatasks.com/user/23#add might be used to add a task, whereas
the URL http://ninjatasks.com/user/23#edit-task32 would be used to edit the task with an
id of 32.
The views are simply web pages written in HTML, although it is common to use templating
languages so that dynamic data can be inserted into the page (more about these in the sec-
tion that follows):
Ember is a framework designed to make building large web applications easier. It
does this by using common conventions that avoid the need for lots of set-up code,
though it can become more difficult if you don't follow these conventions.
Search WWH ::




Custom Search