SlideShare a Scribd company logo
MVVM for the Web

 Angular vs. Knockout



         VS.
                        @basarat
Why MVVM?

• Cleaner user interface
 •   (used to be Cleaner code only)
• Designer / Developer separation
What makes MVVM Work?

• Two way DataBinding for properties
    •    With some form of interception options
• Command binding
• Templates




•       Names change but concepts remain the same.
MVVM the Knockout Way
How MVVM works for XAML

• INotifyPropertyChanged (INPC)
• ICommand Interface and Command Property
• DataTemplates / ItemTemplates
Enter Knockoutjs

• By Steve Sanderson.
  •   Works at microsoft.
• Highly inspired and directed by what was
  already there in XAML world.
  •   Perhaps to ease XAML people into HTML.
Knockout ViewModel similar to INPC

ko.obervable



ko.computed




ko.obervableArray
Knockout INPC View

• XAML View (dependency
  properties):



• Knockout View (bindings):
Knockout Commands

• XAML



• Knockout (click and other
  bindings)
Knockout DataTemplates

• XAML




• knockout
Knockout uses concept of Bindings
Angular js?
MVVM with AngularJS : Observables

• Don’t need them. Means your objects do not
  need an INPC type of implementation.
• “KO dependency tracking is a clever feature for
  a problem which angular does not have” –
  heard on StackOverflow
How does it know if anything changed?

• Angular remembers the value and compares it
  to previous value.
• This is basic dirty checking. If there is a change
  in value, then it fires the change event.
• To know when angular should check the new
  value it we have scope.
Quick AngularJS tutorial

• http://jsfiddle.net/basarat/V9sYB/
Why Angular chose a different method?

• Better syntax, especially for templates
  •   Google plans to make it a web standard so browsers
      can do this natively.
• Change listeners fire immediately on
  setter, which is a problem, since the change
  listener can further change data, which fires
  more change events.
Quick AngularJS tutorial 2

• How browsers could support it
  natively
Angular js performance

• Humans are
  •   Slow – anything faster than 50ms is imperceptible
  •   Limited - can't really show more than about 2000
      pieces of information to a human
• Can you do 2000 comparisons in 50 ms even
  on slow browsers? That means that you have
  25us per comparison.
MVVM the Angular Way
Observables : ViewModel

•       https://github.com/basarat/ChessClock
•       Standard javascript properties your scope
•       Really good with Typescript




•       Angular folks call their framework MV* i.e.
    •     Model View Whatever
•       But like to name it Controller
Observables : The view

• {{property}} syntax
Filters

• Similar to XAML
  IValueConverter but One way
  binding for display
Commands

• The VM




• The View
Templates
Angular JS uses concept of directives
Which one should you use?


Performance
jsPref
http://jsperf.com/angularjs-vs-knockoutjs
Which one should you use?


Browser Support
Angular

• http://docs.angularjs.org/misc/faq
 •   We run our extensive test suite against the following
     browsers: Safari, Chrome, Firefox, Opera, IE8, IE9
     and mobile browsers (Android, Chrome Mobile, iOS
     Safari)
• Yahoo’s Class A browser
Knockout

•       http://knockoutjs.com/documentation/browser-
        support.html
    •    Mozilla Firefox 2.0+ (latest version tested = 3.6.8)
    •    Google Chrome (tested on version 5 for Windows and Mac;
         should work on older versions too)
    •    Microsoft Internet Explorer 6, 7, 8, 9, 10
    •    Apple Safari (tested on Windows Safari version 5, Mac OS X
         Safari version 3.1.2, and iPhone Safari for iOS 4; should work on
         newer/older versions too)
    •    Opera 10 for Windows
•       Knockout was also found to work on the following
        browsers (though we don’t recheck these for every
        release):
    •    Opera Mini
    •    Google Android OS browser (OS version 2.2)
Which one should you use?


Popularity Contest
Knockout vs. Angular

• Google Searches




• StackOverflow tags ( as of feb 2013)
  •   Knockout : 4,304
  •   Angular : 2,794
Decisive

• Stared on Github (as of feb 2013)
  •   https://github.com/angular/angular.js : 7072
  •   https://github.com/SteveSanderson/knockout : 3011
Which one should you use?


Debugging
Batarang

• Dedicated Debugging tool for
  angular.




• None for knockout as of yet.
Conclusion


The world really needs both
Choice (my opinion)

•   Performance : Angular
•   Legacy Browser (specifically IE) : Knockout
•   MS bubble : Knockout
•   Popularity : Angular
•   Debugging : Angular
•   Awesomest Web App Ever : Angular
Links

•       Help Knockout
    •     http://knockoutjs.com/documentation/introduction.html
•       Help Angular
    •     http://docs.angularjs.org/guide/concepts
    •     https://github.com/angular/angular.js/wiki/JsFiddle-Examples
•       Comparisons
    •     http://stackoverflow.com/questions/9682092/databinding-in-
          angularjs
    •     http://litebyte.net/blog/?p=135
    •     TODO App in both: http://addyosmani.github.com/todomvc/
Thank you

• http://basarat.com
• basaratali@gmail.com
• @basarat

More Related Content

PPTX
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
PDF
Choosing the best JavaScript framework/library/toolkit
PDF
JavaScript MV* Framework - Making the Right Choice
PDF
On Selecting JavaScript Frameworks (Women Who Code 10/15)
PPTX
AngularJS vs React JS vs Node JS: Which is Best For Web Development ?
PPTX
PDF
introduction to Vue.js 3
PDF
JS Framework Comparison - An infographic
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Choosing the best JavaScript framework/library/toolkit
JavaScript MV* Framework - Making the Right Choice
On Selecting JavaScript Frameworks (Women Who Code 10/15)
AngularJS vs React JS vs Node JS: Which is Best For Web Development ?
introduction to Vue.js 3
JS Framework Comparison - An infographic

What's hot (20)

PPTX
jQuery Conference 2012 keynote
PDF
Transforming Front-End Disaster Code™ Into A Maintainable Masterpiece
PDF
Spa with angular
PDF
jQuery Chicago 2014 - Next-generation JavaScript Testing
PPTX
Single Page Application (SPA) using AngularJS
PDF
Testing Mobile JavaScript
PDF
Building a Single-Page App: Backbone, Node.js, and Beyond
PDF
jQuery Keynote - Fall 2010
PDF
Going Node.js at Netflix
PPTX
ASP.NET MVC, AngularJS CRUD for Azerbaijan Technical University
PDF
General Assembly Workshop: Advanced JavaScript
PDF
Node PDX: Intro to Sails.js
PPTX
Modern Applications With Asp.net Core 5 and Vue JS 3
PPTX
Vue js for beginner
PPTX
Javascript Frameworks Comparison
PPT
Getting started with angular js
PPTX
Building great spa’s with angular js, asp.net mvc and webapi
PPTX
Frontend architecture design for large(r) team final
PDF
Testing Angular 2 Applications - Rich Web 2016
PPTX
Single Page WebApp Architecture
jQuery Conference 2012 keynote
Transforming Front-End Disaster Code™ Into A Maintainable Masterpiece
Spa with angular
jQuery Chicago 2014 - Next-generation JavaScript Testing
Single Page Application (SPA) using AngularJS
Testing Mobile JavaScript
Building a Single-Page App: Backbone, Node.js, and Beyond
jQuery Keynote - Fall 2010
Going Node.js at Netflix
ASP.NET MVC, AngularJS CRUD for Azerbaijan Technical University
General Assembly Workshop: Advanced JavaScript
Node PDX: Intro to Sails.js
Modern Applications With Asp.net Core 5 and Vue JS 3
Vue js for beginner
Javascript Frameworks Comparison
Getting started with angular js
Building great spa’s with angular js, asp.net mvc and webapi
Frontend architecture design for large(r) team final
Testing Angular 2 Applications - Rich Web 2016
Single Page WebApp Architecture
Ad

Viewers also liked (20)

PDF
Proyecto Formativo
PDF
Currículo Nacional de la Educación Básica
PPTX
32 ways to make your blog suck less
DOC
Metodología de la investigacióm
PDF
"Protección de la salud mental luego del terremoto y tsunami del 27 de febrer...
PPT
Componentes de un Plan de Negocios
PDF
Proyectos_de_innovacion
PPSX
1ºBACH ECONOMÍA Repaso temas 5 6-7 (gh23)
ODP
Error messages
PDF
Gfpi f-019 guia de aprendizaje 01 tda orientar fpi
PDF
Análisis situacional integral de salud final
PPT
JULIOPARI - Elaborando un Plan de Negocios
PPTX
Training Schrijven voor het Web
PDF
PDF
El emprendedor y el empresario profesional cert
PPSX
1ºBACH Economía Tema 5 Oferta y demanda
PDF
Primer Paquete Económico 2017 Zacatecas (2/9)
PDF
Onderzoeksrapport acrs v3.0_definitief
DOCX
Como hacer un plan de negocios
Proyecto Formativo
Currículo Nacional de la Educación Básica
32 ways to make your blog suck less
Metodología de la investigacióm
"Protección de la salud mental luego del terremoto y tsunami del 27 de febrer...
Componentes de un Plan de Negocios
Proyectos_de_innovacion
1ºBACH ECONOMÍA Repaso temas 5 6-7 (gh23)
Error messages
Gfpi f-019 guia de aprendizaje 01 tda orientar fpi
Análisis situacional integral de salud final
JULIOPARI - Elaborando un Plan de Negocios
Training Schrijven voor het Web
El emprendedor y el empresario profesional cert
1ºBACH Economía Tema 5 Oferta y demanda
Primer Paquete Económico 2017 Zacatecas (2/9)
Onderzoeksrapport acrs v3.0_definitief
Como hacer un plan de negocios
Ad

Similar to Mvvm knockout vs angular (20)

PDF
Angular or Backbone: Go Mobile!
PPT
Angularjs for kolkata drupal meetup
PDF
One Weekend With AngularJS
PDF
Building Better Web Apps with Angular.js (SXSW 2014)
PPTX
Knockout.js & SignalR
PPTX
AngularJS
PDF
5 benefits of angular js
PDF
AngularJS Beginner Day One
PDF
Angularjs interview questions and answers
PDF
Ionic framework one day training
PDF
What are the reasons behind growing popularity of AngularJS.pdf
PDF
Beginning AngularJS
DOCX
Angular js getting started
PDF
Itroducing Angular JS
PDF
AngularJS: A framework to make your life easier
PDF
AngularJS - A Powerful Framework For Web Applications
PDF
angularjs-vs-angular-the-key-differences-between-javascript-and-typescript
PDF
Javascript Client & Server Architectures
PDF
AngularJS in Production (CTO Forum)
PDF
AngularJS for Beginners
Angular or Backbone: Go Mobile!
Angularjs for kolkata drupal meetup
One Weekend With AngularJS
Building Better Web Apps with Angular.js (SXSW 2014)
Knockout.js & SignalR
AngularJS
5 benefits of angular js
AngularJS Beginner Day One
Angularjs interview questions and answers
Ionic framework one day training
What are the reasons behind growing popularity of AngularJS.pdf
Beginning AngularJS
Angular js getting started
Itroducing Angular JS
AngularJS: A framework to make your life easier
AngularJS - A Powerful Framework For Web Applications
angularjs-vs-angular-the-key-differences-between-javascript-and-typescript
Javascript Client & Server Architectures
AngularJS in Production (CTO Forum)
AngularJS for Beginners

Mvvm knockout vs angular

  • 1. MVVM for the Web Angular vs. Knockout VS. @basarat
  • 2. Why MVVM? • Cleaner user interface • (used to be Cleaner code only) • Designer / Developer separation
  • 3. What makes MVVM Work? • Two way DataBinding for properties • With some form of interception options • Command binding • Templates • Names change but concepts remain the same.
  • 5. How MVVM works for XAML • INotifyPropertyChanged (INPC) • ICommand Interface and Command Property • DataTemplates / ItemTemplates
  • 6. Enter Knockoutjs • By Steve Sanderson. • Works at microsoft. • Highly inspired and directed by what was already there in XAML world. • Perhaps to ease XAML people into HTML.
  • 7. Knockout ViewModel similar to INPC ko.obervable ko.computed ko.obervableArray
  • 8. Knockout INPC View • XAML View (dependency properties): • Knockout View (bindings):
  • 9. Knockout Commands • XAML • Knockout (click and other bindings)
  • 11. Knockout uses concept of Bindings
  • 13. MVVM with AngularJS : Observables • Don’t need them. Means your objects do not need an INPC type of implementation. • “KO dependency tracking is a clever feature for a problem which angular does not have” – heard on StackOverflow
  • 14. How does it know if anything changed? • Angular remembers the value and compares it to previous value. • This is basic dirty checking. If there is a change in value, then it fires the change event. • To know when angular should check the new value it we have scope.
  • 15. Quick AngularJS tutorial • http://jsfiddle.net/basarat/V9sYB/
  • 16. Why Angular chose a different method? • Better syntax, especially for templates • Google plans to make it a web standard so browsers can do this natively. • Change listeners fire immediately on setter, which is a problem, since the change listener can further change data, which fires more change events.
  • 17. Quick AngularJS tutorial 2 • How browsers could support it natively
  • 18. Angular js performance • Humans are • Slow – anything faster than 50ms is imperceptible • Limited - can't really show more than about 2000 pieces of information to a human • Can you do 2000 comparisons in 50 ms even on slow browsers? That means that you have 25us per comparison.
  • 20. Observables : ViewModel • https://github.com/basarat/ChessClock • Standard javascript properties your scope • Really good with Typescript • Angular folks call their framework MV* i.e. • Model View Whatever • But like to name it Controller
  • 21. Observables : The view • {{property}} syntax
  • 22. Filters • Similar to XAML IValueConverter but One way binding for display
  • 25. Angular JS uses concept of directives
  • 26. Which one should you use? Performance
  • 28. Which one should you use? Browser Support
  • 29. Angular • http://docs.angularjs.org/misc/faq • We run our extensive test suite against the following browsers: Safari, Chrome, Firefox, Opera, IE8, IE9 and mobile browsers (Android, Chrome Mobile, iOS Safari) • Yahoo’s Class A browser
  • 30. Knockout • http://knockoutjs.com/documentation/browser- support.html • Mozilla Firefox 2.0+ (latest version tested = 3.6.8) • Google Chrome (tested on version 5 for Windows and Mac; should work on older versions too) • Microsoft Internet Explorer 6, 7, 8, 9, 10 • Apple Safari (tested on Windows Safari version 5, Mac OS X Safari version 3.1.2, and iPhone Safari for iOS 4; should work on newer/older versions too) • Opera 10 for Windows • Knockout was also found to work on the following browsers (though we don’t recheck these for every release): • Opera Mini • Google Android OS browser (OS version 2.2)
  • 31. Which one should you use? Popularity Contest
  • 32. Knockout vs. Angular • Google Searches • StackOverflow tags ( as of feb 2013) • Knockout : 4,304 • Angular : 2,794
  • 33. Decisive • Stared on Github (as of feb 2013) • https://github.com/angular/angular.js : 7072 • https://github.com/SteveSanderson/knockout : 3011
  • 34. Which one should you use? Debugging
  • 35. Batarang • Dedicated Debugging tool for angular. • None for knockout as of yet.
  • 37. Choice (my opinion) • Performance : Angular • Legacy Browser (specifically IE) : Knockout • MS bubble : Knockout • Popularity : Angular • Debugging : Angular • Awesomest Web App Ever : Angular
  • 38. Links • Help Knockout • http://knockoutjs.com/documentation/introduction.html • Help Angular • http://docs.angularjs.org/guide/concepts • https://github.com/angular/angular.js/wiki/JsFiddle-Examples • Comparisons • http://stackoverflow.com/questions/9682092/databinding-in- angularjs • http://litebyte.net/blog/?p=135 • TODO App in both: http://addyosmani.github.com/todomvc/