Wednesday, 14 November 2018

What is MVVM (Model View- ViewModel) in Knokout JS?

KnockoutJS is based on MVVM pattern. It is an architectural pattern used to design software applications.
MVVM was developed by Microsoft Architect John Gossman in 2005.
The biggest benefit of the model is that it separates the business logic from graphical user interface.
Derived from ViewModel Controller Pattern, this very model makes it very easy to manage and represent data by allowing you to handle underlying data easly.
The ViewModel and Model classes do not know that the view classes exist and the vice versa. Similarly, Model has no idea that both the View and ViewModel exist.

View is a Graphical User Interface created using markup language to represent data.
View is communicating to ViewModel layer through data binding. If any changes in ModelView layer automatically it will reflect to view layer. 

Model is domain data or business object, which holds real-time data. It’s responsible for managing state of the application in object(s).
It also comprises of business Logic which operates on the state.
Also it has a data access layer responsible for persisting and fetching model object.

View Model:
ViewModel is the main processing unit of the MVVM and holds dynamic data. It’s the one which binds Model and View together.
It retrieves data from the model (M) and exposes it to the view (V) as properties in a form that the view can easily can consume.
Note that this is not the UI itself: it does not have any concept of buttons or display styles.
In KO, view models are pure JavaScript objects that hold no knowledge of HTML.