Search This Blog

Sunday, February 24, 2013

KnockoutJS and MVC

KnockoutJS is one of the great JavaScript libraries that follows MVVM design pattern. MVVM pattern is originated from Microsoft with Silverlight/WPF application development. KnockoutJS is the JavaScript implementation of this pattern.

These are some of the key benefits of developing web applications in MVVM pattern with KnockoutJS.

1. Provide a clear separation between UI and business/backend logics.

Model - Data objects in business/backend. (This is JSON data object returned from a RESTful service or AJAX call.)
View - User Interface.
View Model - Model of the view or represent data in the UI. This provides an abstraction of a view. View interacts with View Model through data binding.

2. Two way data bindings and automatic UI refresh - This means when UI changes, View Model updates automatically. When View Model changes, UI refreshes automatically.

3. Dependency Tracking - Knockout automatically detects and handles dependencies between properties and cascades changes accordingly.

Visual Studio MVC 4 Internet and Mobile application templates come with reference to KnockoutJS. So, this is an indication of Microsoft’s continuous support of KnockoutJS as the JavaScript MVVM library.