SlideShare a Scribd company logo
1 of 12
Knockout.js
 Jon Hoguet, MyWebGrocer
      March 12, 2012
Jon Who?
Bottom Line Upfront
• What is Knockout
   o MVVM framework for Javascript
      • Observable View Models
      • Declarative and Templated Views
      • Enables simpler, reusable, frontend and cleaner communication with
        backend

• Geek or Presenter (definitely Geek)
   o Slow me down
   o Ask questions
   o Give me feedback so I can get better

• Goal
   o Scratch the surface of knockout
Model serialized   Model serialized
  as HTML          as Form / Query
                   string Dictionary




                   Must know how
                    model was
                     serialized
• But we’ve always done it that way – why not…
   • Complex communication interface (send one thing and receive
      another)
   • Model Binding against a dictionary seems simple but quickly gets
                           Model serialized                 Model serialized
      complex (object graphs, as HTML
                               arrays)
                                                            as Form / Query
   • View is now server side (Razor, C#) AND client side (javascript, css)
                                                           string Dictionary
      creating coupling between these layers
   • View ultimately ‘lives’ in the DOM not in CLR / Razor
   • Client side code is coupled to the view and not the model
        • Difficult to reuse code in mobile, etc.




                                                           Must know how
                                                            model was
                                                             serialized
Interface is now
consistently JSON


                    Javascript is now
                     responsible for
                    presenting JSON
                          and
                     communicating
                      JSON back to
                         server
• Much cleaner communication interface
• Can write multiple presentation layers (ie. mobile) on top of the same
  communication interface
• Model binding is radically easier (Json Model Binder)
                                    Interface is now
                                   consistently JSON


                                                               Javascript is now
                                                                responsible for
                                                               presenting JSON
                                                                     and
                                                                communicating
                                                                 JSON back to
                                                                    server
MV-WHAT…
MVVM         View Model
Server Model
               JSON Model




                              View
Demo
•   Prototype
•   Baby steps
    o   Observable
    o   View model
    o   Model
    o   Array
•   Ugh, where’s the View (look at prototype)
    o   View
    o   View Array (clean up entry should be ViewModel)
    o   Its all connected
    o   Templates (edit / view, table / list) (before / after / cleanup)
    o   Computed (simple, prototype)
    o   More bindings (css, if and value, value options, click, event, more click)
•   Actions
    o   Root ViewModel (with / root)
    o   Strategy for dealing with server (get)
•   Binding Handlers
    o   Editable
    o   If view code is bleeding into your view model – its time for a binding handler
            • Ie – animations,
•   ASP.NET
    o   JSON
    o   WEB API
    o   Bundles
Gotchas
• Dates –
   o http://feedproxy.google.com/~r/ScottHanselman/~3/MTbztRtN2l8/OnTheNight
     mareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx Mapping

• Don’t self close tags – unless there will never be anything
  inside that tag – its tempting…

• Careful that you don’t ‘un-observe’ an item by not
  setting properly

• Be mindful of whether it is observable or not

• Template is a string….

• Misleading errors
Resources
• Will post slides / code
• http://jsfiddle.net/
   o Decompose a problem using this sandbox
• http://knockoutjs.com/
   o Interactive tutorials – experience them
• http://www.knockmeout.net/
   o Tons of experience captured in this blog
• http://channel9.msdn.com/Events/MIX/MIX11/FRM0
  8
   o Great video from early days of Knockout
• http://channel9.msdn.com/Events/TechDays/TechD
  ays-2012-Belgium/199
   o Recent video of Knockout + Web Api + Upshot = Amazing!

More Related Content

What's hot

Dom selecting & jQuery
Dom selecting & jQueryDom selecting & jQuery
Dom selecting & jQueryKim Hunmin
 
JsViews - Next Generation jQuery Templates
JsViews - Next Generation jQuery TemplatesJsViews - Next Generation jQuery Templates
JsViews - Next Generation jQuery TemplatesBorisMoore
 
ME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS FundamentalsME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS FundamentalsAviran Cohen
 
Modern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScriptModern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScriptmartinlippert
 
Tikal's Backbone_js introduction workshop
Tikal's Backbone_js introduction workshopTikal's Backbone_js introduction workshop
Tikal's Backbone_js introduction workshopTikal Knowledge
 
jQuery and Ruby Web Frameworks
jQuery and Ruby Web FrameworksjQuery and Ruby Web Frameworks
jQuery and Ruby Web FrameworksYehuda Katz
 
Introduction to backbone_js
Introduction to backbone_jsIntroduction to backbone_js
Introduction to backbone_jsMohammed Saqib
 
Incremental DOM and Recent Trend of Frontend Development
Incremental DOM and Recent Trend of Frontend DevelopmentIncremental DOM and Recent Trend of Frontend Development
Incremental DOM and Recent Trend of Frontend DevelopmentAkihiro Ikezoe
 
Docker Up and Running for Web Developers
Docker Up and Running for Web DevelopersDocker Up and Running for Web Developers
Docker Up and Running for Web DevelopersAmr Fawzy
 
Bringing the light to the client with KnockoutJS
Bringing the light to the client with KnockoutJSBringing the light to the client with KnockoutJS
Bringing the light to the client with KnockoutJSBoyan Mihaylov
 
The 5 Layers of Web Accessibility
The 5 Layers of Web AccessibilityThe 5 Layers of Web Accessibility
The 5 Layers of Web AccessibilityDirk Ginader
 

What's hot (20)

Dom selecting & jQuery
Dom selecting & jQueryDom selecting & jQuery
Dom selecting & jQuery
 
JsViews - Next Generation jQuery Templates
JsViews - Next Generation jQuery TemplatesJsViews - Next Generation jQuery Templates
JsViews - Next Generation jQuery Templates
 
ME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS FundamentalsME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS Fundamentals
 
Introduction to backbone js
Introduction to backbone jsIntroduction to backbone js
Introduction to backbone js
 
Modern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScriptModern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScript
 
Tikal's Backbone_js introduction workshop
Tikal's Backbone_js introduction workshopTikal's Backbone_js introduction workshop
Tikal's Backbone_js introduction workshop
 
Backbone js-slides
Backbone js-slidesBackbone js-slides
Backbone js-slides
 
jQuery and Ruby Web Frameworks
jQuery and Ruby Web FrameworksjQuery and Ruby Web Frameworks
jQuery and Ruby Web Frameworks
 
Introduction to backbone_js
Introduction to backbone_jsIntroduction to backbone_js
Introduction to backbone_js
 
Javascript tutorial
Javascript tutorialJavascript tutorial
Javascript tutorial
 
Incremental DOM and Recent Trend of Frontend Development
Incremental DOM and Recent Trend of Frontend DevelopmentIncremental DOM and Recent Trend of Frontend Development
Incremental DOM and Recent Trend of Frontend Development
 
Docker Up and Running for Web Developers
Docker Up and Running for Web DevelopersDocker Up and Running for Web Developers
Docker Up and Running for Web Developers
 
Javascript by geetanjali
Javascript by geetanjaliJavascript by geetanjali
Javascript by geetanjali
 
Bringing the light to the client with KnockoutJS
Bringing the light to the client with KnockoutJSBringing the light to the client with KnockoutJS
Bringing the light to the client with KnockoutJS
 
ActiveDOM
ActiveDOMActiveDOM
ActiveDOM
 
Knockoutjs
KnockoutjsKnockoutjs
Knockoutjs
 
Introduction to Umbraco
Introduction to UmbracoIntroduction to Umbraco
Introduction to Umbraco
 
The 5 Layers of Web Accessibility
The 5 Layers of Web AccessibilityThe 5 Layers of Web Accessibility
The 5 Layers of Web Accessibility
 
Angular js 101
Angular js 101Angular js 101
Angular js 101
 
Basics of VueJS
Basics of VueJSBasics of VueJS
Basics of VueJS
 

Viewers also liked

Knockout.js presentation
Knockout.js presentationKnockout.js presentation
Knockout.js presentationScott Messinger
 
Knockout (support slides for presentation)
Knockout (support slides for presentation)Knockout (support slides for presentation)
Knockout (support slides for presentation)Aymeric Gaurat-Apelli
 
Knockout js
Knockout jsKnockout js
Knockout jshhassann
 
Knockout JS Development - a Quick Understanding
Knockout JS Development - a Quick UnderstandingKnockout JS Development - a Quick Understanding
Knockout JS Development - a Quick UnderstandingUdaya Kumar
 
#2 Hanoi Magento Meetup - Part 2: Knockout JS
#2 Hanoi Magento Meetup - Part 2: Knockout JS#2 Hanoi Magento Meetup - Part 2: Knockout JS
#2 Hanoi Magento Meetup - Part 2: Knockout JSHanoi MagentoMeetup
 
Download presentation
Download presentationDownload presentation
Download presentationwebhostingguy
 
Slideshare Powerpoint presentation
Slideshare Powerpoint presentationSlideshare Powerpoint presentation
Slideshare Powerpoint presentationelliehood
 

Viewers also liked (14)

Knockout.js
Knockout.jsKnockout.js
Knockout.js
 
Knockout.js presentation
Knockout.js presentationKnockout.js presentation
Knockout.js presentation
 
Knockout.js explained
Knockout.js explainedKnockout.js explained
Knockout.js explained
 
knockout.js
knockout.jsknockout.js
knockout.js
 
Knockout js (Dennis Haney)
Knockout js (Dennis Haney)Knockout js (Dennis Haney)
Knockout js (Dennis Haney)
 
Knockout js
Knockout jsKnockout js
Knockout js
 
Knockout (support slides for presentation)
Knockout (support slides for presentation)Knockout (support slides for presentation)
Knockout (support slides for presentation)
 
Knockout js
Knockout jsKnockout js
Knockout js
 
KnockoutJS and MVVM
KnockoutJS and MVVMKnockoutJS and MVVM
KnockoutJS and MVVM
 
Knockout.js
Knockout.jsKnockout.js
Knockout.js
 
Knockout JS Development - a Quick Understanding
Knockout JS Development - a Quick UnderstandingKnockout JS Development - a Quick Understanding
Knockout JS Development - a Quick Understanding
 
#2 Hanoi Magento Meetup - Part 2: Knockout JS
#2 Hanoi Magento Meetup - Part 2: Knockout JS#2 Hanoi Magento Meetup - Part 2: Knockout JS
#2 Hanoi Magento Meetup - Part 2: Knockout JS
 
Download presentation
Download presentationDownload presentation
Download presentation
 
Slideshare Powerpoint presentation
Slideshare Powerpoint presentationSlideshare Powerpoint presentation
Slideshare Powerpoint presentation
 

Similar to Introduction to Knockoutjs

Kann JavaScript elegant sein?
Kann JavaScript elegant sein?Kann JavaScript elegant sein?
Kann JavaScript elegant sein?jbandi
 
What is Mean Stack Development ?
What is Mean Stack Development ?What is Mean Stack Development ?
What is Mean Stack Development ?Balajihope
 
Meanstack Introduction by Kishore Chandra
Meanstack Introduction by Kishore ChandraMeanstack Introduction by Kishore Chandra
Meanstack Introduction by Kishore ChandraKishore Chandra
 
Lightweight webdev
Lightweight webdevLightweight webdev
Lightweight webdevdamianofusco
 
AngularJS UTOSC
AngularJS UTOSCAngularJS UTOSC
AngularJS UTOSCroboncode
 
Canopy view of single-page applications (SPAs)
Canopy view of single-page applications (SPAs)Canopy view of single-page applications (SPAs)
Canopy view of single-page applications (SPAs)Benjamin Howarth
 
Javascript Client & Server Architectures
Javascript Client & Server ArchitecturesJavascript Client & Server Architectures
Javascript Client & Server ArchitecturesPedro Melo Pereira
 
Teaching old java script new tricks
Teaching old java script new tricksTeaching old java script new tricks
Teaching old java script new tricksSimon Sturmer
 
Workshop Intro: FrontEnd General Overview
Workshop Intro: FrontEnd General OverviewWorkshop Intro: FrontEnd General Overview
Workshop Intro: FrontEnd General OverviewVisual Engineering
 
RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015Ben Lesh
 
Get Started with JavaScript Frameworks
Get Started with JavaScript FrameworksGet Started with JavaScript Frameworks
Get Started with JavaScript FrameworksChristian Gaetano
 
10 Years of JavaScript
10 Years of JavaScript10 Years of JavaScript
10 Years of JavaScriptMike de Boer
 
An introduction to Node.js
An introduction to Node.jsAn introduction to Node.js
An introduction to Node.jsKasey McCurdy
 
MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!Roberto Messora
 
JDD2015: Java Everywhere Again—with DukeScript - Jaroslav Tulach
JDD2015: Java Everywhere Again—with DukeScript - Jaroslav TulachJDD2015: Java Everywhere Again—with DukeScript - Jaroslav Tulach
JDD2015: Java Everywhere Again—with DukeScript - Jaroslav TulachPROIDEA
 

Similar to Introduction to Knockoutjs (20)

Kann JavaScript elegant sein?
Kann JavaScript elegant sein?Kann JavaScript elegant sein?
Kann JavaScript elegant sein?
 
What is Mean Stack Development ?
What is Mean Stack Development ?What is Mean Stack Development ?
What is Mean Stack Development ?
 
Meanstack Introduction by Kishore Chandra
Meanstack Introduction by Kishore ChandraMeanstack Introduction by Kishore Chandra
Meanstack Introduction by Kishore Chandra
 
MEAN Stack
MEAN StackMEAN Stack
MEAN Stack
 
MEAN Stack
MEAN StackMEAN Stack
MEAN Stack
 
Lightweight webdev
Lightweight webdevLightweight webdev
Lightweight webdev
 
AngularJS UTOSC
AngularJS UTOSCAngularJS UTOSC
AngularJS UTOSC
 
Canopy view of single-page applications (SPAs)
Canopy view of single-page applications (SPAs)Canopy view of single-page applications (SPAs)
Canopy view of single-page applications (SPAs)
 
Javascript Client & Server Architectures
Javascript Client & Server ArchitecturesJavascript Client & Server Architectures
Javascript Client & Server Architectures
 
Teaching old java script new tricks
Teaching old java script new tricksTeaching old java script new tricks
Teaching old java script new tricks
 
Workshop Intro: FrontEnd General Overview
Workshop Intro: FrontEnd General OverviewWorkshop Intro: FrontEnd General Overview
Workshop Intro: FrontEnd General Overview
 
RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015
 
Json
JsonJson
Json
 
Get Started with JavaScript Frameworks
Get Started with JavaScript FrameworksGet Started with JavaScript Frameworks
Get Started with JavaScript Frameworks
 
10 Years of JavaScript
10 Years of JavaScript10 Years of JavaScript
10 Years of JavaScript
 
An introduction to Node.js
An introduction to Node.jsAn introduction to Node.js
An introduction to Node.js
 
WTA-MODULE-4.pptx
WTA-MODULE-4.pptxWTA-MODULE-4.pptx
WTA-MODULE-4.pptx
 
Training: MVVM Pattern
Training: MVVM PatternTraining: MVVM Pattern
Training: MVVM Pattern
 
MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!
 
JDD2015: Java Everywhere Again—with DukeScript - Jaroslav Tulach
JDD2015: Java Everywhere Again—with DukeScript - Jaroslav TulachJDD2015: Java Everywhere Again—with DukeScript - Jaroslav Tulach
JDD2015: Java Everywhere Again—with DukeScript - Jaroslav Tulach
 

Recently uploaded

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 

Recently uploaded (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 

Introduction to Knockoutjs

  • 1. Knockout.js Jon Hoguet, MyWebGrocer March 12, 2012
  • 3. Bottom Line Upfront • What is Knockout o MVVM framework for Javascript • Observable View Models • Declarative and Templated Views • Enables simpler, reusable, frontend and cleaner communication with backend • Geek or Presenter (definitely Geek) o Slow me down o Ask questions o Give me feedback so I can get better • Goal o Scratch the surface of knockout
  • 4. Model serialized Model serialized as HTML as Form / Query string Dictionary Must know how model was serialized
  • 5. • But we’ve always done it that way – why not… • Complex communication interface (send one thing and receive another) • Model Binding against a dictionary seems simple but quickly gets Model serialized Model serialized complex (object graphs, as HTML arrays) as Form / Query • View is now server side (Razor, C#) AND client side (javascript, css) string Dictionary creating coupling between these layers • View ultimately ‘lives’ in the DOM not in CLR / Razor • Client side code is coupled to the view and not the model • Difficult to reuse code in mobile, etc. Must know how model was serialized
  • 6. Interface is now consistently JSON Javascript is now responsible for presenting JSON and communicating JSON back to server
  • 7. • Much cleaner communication interface • Can write multiple presentation layers (ie. mobile) on top of the same communication interface • Model binding is radically easier (Json Model Binder) Interface is now consistently JSON Javascript is now responsible for presenting JSON and communicating JSON back to server
  • 9. MVVM View Model Server Model JSON Model View
  • 10. Demo • Prototype • Baby steps o Observable o View model o Model o Array • Ugh, where’s the View (look at prototype) o View o View Array (clean up entry should be ViewModel) o Its all connected o Templates (edit / view, table / list) (before / after / cleanup) o Computed (simple, prototype) o More bindings (css, if and value, value options, click, event, more click) • Actions o Root ViewModel (with / root) o Strategy for dealing with server (get) • Binding Handlers o Editable o If view code is bleeding into your view model – its time for a binding handler • Ie – animations, • ASP.NET o JSON o WEB API o Bundles
  • 11. Gotchas • Dates – o http://feedproxy.google.com/~r/ScottHanselman/~3/MTbztRtN2l8/OnTheNight mareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx Mapping • Don’t self close tags – unless there will never be anything inside that tag – its tempting… • Careful that you don’t ‘un-observe’ an item by not setting properly • Be mindful of whether it is observable or not • Template is a string…. • Misleading errors
  • 12. Resources • Will post slides / code • http://jsfiddle.net/ o Decompose a problem using this sandbox • http://knockoutjs.com/ o Interactive tutorials – experience them • http://www.knockmeout.net/ o Tons of experience captured in this blog • http://channel9.msdn.com/Events/MIX/MIX11/FRM0 8 o Great video from early days of Knockout • http://channel9.msdn.com/Events/TechDays/TechD ays-2012-Belgium/199 o Recent video of Knockout + Web Api + Upshot = Amazing!

Editor's Notes

  1. We all bleed red…Load habitometerLoad fiddlesClose google talk, email, etc.Increase font sizeSwagConfirm timelineCurious about MyWebGrocer
  2. Now transferring data – not presentation…. Which means… we can put another presentation (mobile, etc.) no top
  3. Now transferring data – not presentation…. Which means… we can put another presentation (mobile, etc.) no top
  4. How about validationHow about back buttonHow about complex view modelsHow about to / from serverInlineAJAXWep API
  5. Observables Introduce ko.observable()Subscribe and alert, timeout, alert starting valueCan have an initial value to ko.observable()Subscribe can see before and afterIntroduce ko.observableArrayhow to properly initialize and ‘clear’ them (null, [])Note that for push we call on observable array – while length we call on the actual array
  6. TemplatingBe careful … template name is a stringReusableEasily switch between templatesDisplay more than one template
  7. ko.bindingHandlers['editable'] = {    init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext){        var node = $(element);        var span = $('<span></span>');        node.append(span);        //ko.bindingHandlers.text.init(span[0], valueAccessor, allBindingsAccessor, viewModel, bindingContext);                var text = $('<input type="text" />');        text.hide();        node.append(text);        ko.bindingHandlers.value.init(text[0], valueAccessor, allBindingsAccessor, viewModel, bindingContext);        text.blur(function(){           text.hide();           span.show();                     });                node.click(function(){            if (span.is(':visible')){                span.hide();                text.show();                text.focus();            }        });    },    update: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext){        var node = $(element);        var span = node.find('span');        var text = node.find('input');        ko.bindingHandlers.text.update(span[0],valueAccessor, allBindingsAccessor, viewModel, bindingContext);        ko.bindingHandlers.value.update(text[0],valueAccessor, allBindingsAccessor, viewModel, bindingContext);            }};