KEMBAR78
ASP.NET MVC - Knockoutjs and MVVM | PDF
KnockoutJS and MVVM
@d_danailov
ASP.NET MVC
Dimitar Danailov
Senior Developer at 158ltd.com
dimityr.danailov[at]gmail.com
Slideshare.net
Github
YouTube
Founder at VarnaIT
Github Code
Topics Today
โ— What is MVVM
โ— Why use MVVM
โ— Knockout.js
2005
Photo Credit:
http://upload.wikimedia.
org/wikipedia/commons/8/87/MVVMPattern.png
What is MVVM
โ— Model - View - ModelView
โ— Model = Data Class
โ— View = User Interface
โ— ViewModel (VM)
โ—‹ UI binds to this class
โ—‹ VM consumes services of Model
โ—‹ VM May expose services/properties of Model
What is MVVM
โ— View knows nothing about Model
โ— Model knows nothing about View
โ— Model knows nothing about View Model
โ— View Model knows nothing about View
โ— Communication from View to VM is via data binding
โ—‹ Lists for List Boxes and Grids
โ—‹ IsEnabled properties for Buttons
โ—‹ Data for Text Boxes
Why use MVVM
โ— Separate UI / Business / Data Logic
โ— Be able to swap out UI
โ—‹ Leave business rules/data logic in place
โ—‹ ASP.NET to Silverlight
โ—‹ WPF to Windows Phone
โ—‹ etc.
โ— Unit testing
โ— Write less UI code
Photo Credit:
http://s.allacronyms.com/2168932girl.png
Rich - client - side interactivity
What is KnockoutJS
MVVM pattern
Web Browser Support
Observable
Core Observable Types
Observable
Core Observable Types
Computed
Observable Array
Observable
Core Observable Types
Computed
Observable Array
Knockout in 3 steps
<input data-bind="value: code" placeholder="code" />
Declarative Binding
Knockout in 3 steps
var myViewModel = {
firstName: ko.observable('John')
}
Create an Observable
Knockout in 3 steps
ko.applyBindings(myViewModel);
Bind the ViewModel
to the View
How knockout's observable
works
Changes to Source
notify targets
How knockout's observable
works
Changes to Source
notify targets
Changes to targets
Notify Source
How knockout's observable
works
Changes to Source
notify targets
Changes to targets
Notify Source
Two - Way Data
Binding
How knockout's observable
works
Changes to Source
notify targets
Changes to targets
Notify Source
Two - Way Data
Binding
Event Binding
MVVM Summary
โ— MVVM is easy
โ— Just need an additional class
โ— Helps to understand the XAML data binding model
โ— Great for Testing and re-usability
โ— Donโ€™t worry about being โ€œ100% code behind freeโ€
Questions
Dimitar Danailov
Senior Developer at 158ltd.com
dimityr.danailov[at]gmail.com
Slideshare.net
Github
YouTube
Founder at VarnaIT
Github Code

ASP.NET MVC - Knockoutjs and MVVM