Book Image

WEB APP TESTING USING KNOCKOUT.JS

By : Roberto Messora
Book Image

WEB APP TESTING USING KNOCKOUT.JS

By: Roberto Messora

Overview of this book

Table of Contents (11 chapters)

The ViewModel in detail


A ViewModel is a pure-code representation of the View. We saw in the previous sections that it contains data to show and commands that handle events triggered by the user.

It's important to remember that a ViewModel shouldn't have any knowledge about the View and the UI. Pure-code representation means that a ViewModel shouldn't contain any reference to HTML markup elements (buttons, text-boxes, and so on.) but only pure JavaScript properties and methods.

Knockout.JS is a JavaScript implementation of the Model-View-ViewModel presentation design pattern whose objective is to promote a clear separation between the View and ViewModel. This principle is called Separation of Concerns.

Why is this so important? The answer is quite easy, because in this way a developer can achieve a real separation of responsibilities. The View is only responsible for presenting data to the user and reacting to her/his inputs. The ViewModel is also responsible for holding the data and providing...