SlideShare ist ein Scribd-Unternehmen logo
1 von 50
IntelliMeet April, 14 
KnockoutJS and MVVM 
Manvendra SK 
Twitter: @Manvendra_SK
What Is KnockoutJS ? 
Rich client-side 
interactivity 
MVVM pattern 
Web browser support 
Separates behavior and structure 
Declarative bindings 
Observables 
6+ 2+
What Is The Problem ? 
Delete Underlying 
Data 
View 
What Is The Solution ? 
Delete Underlying 
Data 
View
What KnockoutJS Is Not ? 
Client side code 
Server code 
Database 
KnockoutJS
What Is MVVM ? 
Model View ViewModel
Core Observable Types 
Computed Observable 
Observable Array
How Knockout’s Observables Works ? 
Changes to 
Targets 
Notify 
Source 
Changes to 
Source 
Notify 
Targets 
Two-Way 
Data 
Binding 
Event 
Binding
Observable And Binding 
• Make Property on object an observable using 
ko.observable() method passing default value. 
• Call ko.applyBindings() method passing object to 
method. 
• Bind properties of ViewModel object to html elements using 
data-bind attribute any binding like text. More on this 
later. 
• You can make the object using a constructor. *
Observable Tricks 
• Any property that is declared observable is a function like 
getter and setter. 
• To access property use: vmObject.property() 
• To set property use: vmObject.property(_newValue) 
• Don’t ever use = operator to assign values. You’ll 
overwrite the observable.
Interactive Binding 
• We have used text binding. That was a non-interactive 
binding. 
• Interactive binding is when user interact with the page and 
hence the binding. 
• click is such a binding. 
• More on this later.
Computed Observable 
Define Your 
Own Derived 
Property 
When You 
Need A Value 
That Doesn’t 
Exist in Web 
Service 
Based On 
Other 
Properties and 
Observables 
Also Supports 
Data Binding
Computed Observable And Binding 
• Make Property on object an computed observable using 
ko.computed() method passing a anonymous function 
that returns computed value. 
• Bind to html elements using data-bind attribute.
Observable Array 
Notify When 
Items Are 
Added Or 
Removed 
Tracks Which 
Objects Are In 
The Array 
No Notification 
When Objects 
In The Array 
Change 
Bonus: Can 
Use Array 
Functions
Observable Array And Binding 
• Make Property on object an observable array using 
ko.observableArray() method passing an array literal. 
• Bind to html elements using data-bind attribute and 
foreach binding. 
• Binding contexts inside foreach: $root et al. More on this 
later. 
• mvObject.arrayProp() gives you native underlying array.
Observable Array Methods 
• push(), pop() 
• unshift(), shift(), slice() 
• remove(), removeAll(), destroy(), destroyAll() 
• sort(), reversed() 
• indexOf()
Built In Bindings 
Binding For 
Element 
Attributes 
Multiple 
Binding 
Expressions 
Built Into 
Knockout
Control Flow Bindings 
foreach if ifnot with 
text 
html visible css style attr 
click value event enable disable 
checked options selectedOptions hasfocus
Appearance Bindings 
foreach if ifnot with 
text 
html visible css style attr 
click value event enable disable 
checked options selectedOptions hasfocus
Interactive Bindings 
foreach if ifnot with 
text 
html visible css style attr 
click value event enable disable 
checked options selectedOptions hasfocus
Control Flow Bindings
foreach Binding
Binding Contexts 
• What if you need to access ViewModel object while iterating 
array using foreach binding? 
• $root : Top level ViewModel object. 
• $data : Refers to object for the current context. Like this 
keyword in JavaScript. Useful for atomic values like strings 
and numbers. 
• $index : Obviously index number of current item.
Binding Contexts 
• $parent : Refers to the parent ViewModel object. Typically 
used inside nested loops and when you need to access 
properties in the outer loop.
if And ifnot Bindings
with Binding 
• Used when you want to manually declare block scope to 
particular property of ViewModel.
Appearance Bindings
text Binding 
html Binding 
visible Binding 
attr Binding
style Binding 
css Binding
Interactive Bindings
click Binding 
• click binding is one of the simplest interactive binding. It 
just calls a method on your ViewModel when the user click 
the element passing function two arguments model and 
event. 
• vmObject.someMethod = function(model, event) { 
// do what ever you want here… 
};
value Binding 
• Similar to text binding. But this time user can update the 
value from the View and ViewModel will update accordingly. 
Thus value binding is two way binding.
event Binding 
• The event binding lets you listen for arbitrary DOM events 
on any HTML element. 
• As it can listen for multiple events, it requires an object to 
map events. Just like attr binding. 
• data-bind=“event: {mouseover: someMethod, 
mouseOut: someOtherMethod}”
event Binding 
• The function will take two arguments called data and 
event. 
• vmObject.someMethod = function(data, event) { 
// do what ever you want on happening 
// of this event… 
};
A Better event Binding
enable and disable Binding 
• Used to enable or disable some form element on some 
particular condition.
checked Binding 
• Used to select or deselect HTML’s selectable elements like 
check boxes and radio buttons. 
• We can also use arrays instead of true or false value in the 
observable. In this case only those check boxes will be 
selected whose value attribute value exist in the array. 
• Matches value attribute value of radio button to single 
value in observable.
options Binding 
• This binding is used to build options elements inside a 
select element from an observable array. 
• value binding is used to preselect or get the selected item 
in the select list. 
• optionsText binding is used to show the content on the 
view when using objects in the observable array instead of 
literals.
selectedOptions Binding 
• As a select list can be made to select multiple items so to 
retrieve or set all the selected items we need an array 
instead of using an atomic value. Thus instead of value 
binding we use selectedOptions binding.
hasfocus Binding 
• Allows us to put the focus on any element.
Interacting With Server 
Saving Data 
Mapping 
Data To 
ViewModel 
Loading 
Data
Mapping Data To ViewModel 
• Mapping plugin dynamically generates new observables.
Animation Inside Knockout 
• Don’t support animation from core, as it’s a view binding 
library not DOM manipulation library. 
• All Knockout’s automatic updates are immediately applied 
whenever underlying data changes.
List Callbacks 
• Knockout is a powerful user interface library on its own, but 
once you combine it with the animation capabilities of a 
framework like jQuery or MooTools, you’re ready to create 
truly stunning UIs with minimal markup. 
• The foreach binding has two callbacks named 
beforeRemove and afterAdd. These functions are 
executed before an item is removed from the list or after it’s 
been added to the list, respectively. This is our chance to put 
in animation logic before Knockout manipulates the DOM.
List Callbacks 
• These callbacks take a parameter named element which a 
reference to the element which Knockout is manipulating.
Custom Bindings 
• Okey, we’re having fun with foreach binding and its some 
level support for plugging in animation logic. But what 
about other bindings? They don’t support this already. So 
Custom Bindings is answer to the question. 
• We can make our own bindings by adding an object 
defining the binding to ko.bindingHandlers. This also 
happens to be where all of the built-in bindings are defined, 
too.
Custom Bindings 
• The object should have two methods namely init and 
update. 
• init method is called when Knockout first encounters the 
binding. So this callback should define the initial state for the 
view component and perform necessary setup actions like 
registering event listeners.
Custom Bindings 
• The update method executes whenever the associated 
observable changes. 
• Both methods take same two parameters namely element 
and valueAccessor. 
• The element parameter is the DOM element being bound, 
and valueAccessor is a function that will return the 
ViewModel property in question (here it is binding value).
Conclusion 
• Knockout.js is a pure JavaScript library that makes it 
incredibly easy to build dynamic, data-centric user 
interfaces. 
• We covered most of the Knockout.js API, but there are still a 
number of nuances left to discover. 
• Knockout.js provides plethora of extensibility opportunities 
for you to explore!
Questions 
?
Thanks...

Weitere ähnliche Inhalte

Was ist angesagt?

Web Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing CombinationWeb Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing CombinationAndrew Rota
 
Angular js for beginners
Angular js for beginnersAngular js for beginners
Angular js for beginnersMunir Hoque
 
A brave new web - A talk about Web Components
A brave new web - A talk about Web ComponentsA brave new web - A talk about Web Components
A brave new web - A talk about Web ComponentsMichiel De Mey
 
Levent-Gurses' Introduction to Web Components & Polymer
Levent-Gurses' Introduction to Web Components & PolymerLevent-Gurses' Introduction to Web Components & Polymer
Levent-Gurses' Introduction to Web Components & PolymerErik Isaksen
 
Harness jQuery Templates and Data Link
Harness jQuery Templates and Data LinkHarness jQuery Templates and Data Link
Harness jQuery Templates and Data LinkBorisMoore
 
KnockOutjs from Scratch
KnockOutjs from ScratchKnockOutjs from Scratch
KnockOutjs from ScratchUdaya Kumar
 
ME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS FundamentalsME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS FundamentalsAviran Cohen
 
Kickstarting Node.js Projects with Yeoman
Kickstarting Node.js Projects with YeomanKickstarting Node.js Projects with Yeoman
Kickstarting Node.js Projects with YeomanPatrick Buergin
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS BasicsRavi Mone
 
Difference between java script and jquery
Difference between java script and jqueryDifference between java script and jquery
Difference between java script and jqueryUmar Ali
 
Web components
Web componentsWeb components
Web componentsGil Fink
 
Polymer and web component
Polymer and web componentPolymer and web component
Polymer and web componentImam Raza
 
AngularJS: an introduction
AngularJS: an introductionAngularJS: an introduction
AngularJS: an introductionLuigi De Russis
 
Why and How to Use Virtual DOM
Why and How to Use Virtual DOMWhy and How to Use Virtual DOM
Why and How to Use Virtual DOMDaiwei Lu
 
Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014Stéphane Bégaudeau
 
Angular js tutorial slides
Angular js tutorial slidesAngular js tutorial slides
Angular js tutorial slidessamhelman
 

Was ist angesagt? (20)

Web Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing CombinationWeb Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing Combination
 
Angular js for beginners
Angular js for beginnersAngular js for beginners
Angular js for beginners
 
A brave new web - A talk about Web Components
A brave new web - A talk about Web ComponentsA brave new web - A talk about Web Components
A brave new web - A talk about Web Components
 
Levent-Gurses' Introduction to Web Components & Polymer
Levent-Gurses' Introduction to Web Components & PolymerLevent-Gurses' Introduction to Web Components & Polymer
Levent-Gurses' Introduction to Web Components & Polymer
 
Harness jQuery Templates and Data Link
Harness jQuery Templates and Data LinkHarness jQuery Templates and Data Link
Harness jQuery Templates and Data Link
 
KnockOutjs from Scratch
KnockOutjs from ScratchKnockOutjs from Scratch
KnockOutjs from Scratch
 
ME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS FundamentalsME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS Fundamentals
 
Backbone js
Backbone jsBackbone js
Backbone js
 
Kickstarting Node.js Projects with Yeoman
Kickstarting Node.js Projects with YeomanKickstarting Node.js Projects with Yeoman
Kickstarting Node.js Projects with Yeoman
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
 
Difference between java script and jquery
Difference between java script and jqueryDifference between java script and jquery
Difference between java script and jquery
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Web components
Web componentsWeb components
Web components
 
Knockoutjs
KnockoutjsKnockoutjs
Knockoutjs
 
Web Components
Web ComponentsWeb Components
Web Components
 
Polymer and web component
Polymer and web componentPolymer and web component
Polymer and web component
 
AngularJS: an introduction
AngularJS: an introductionAngularJS: an introduction
AngularJS: an introduction
 
Why and How to Use Virtual DOM
Why and How to Use Virtual DOMWhy and How to Use Virtual DOM
Why and How to Use Virtual DOM
 
Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014
 
Angular js tutorial slides
Angular js tutorial slidesAngular js tutorial slides
Angular js tutorial slides
 

Andere mochten auch

Using mvvm on the web using knockoutjs & ignite ui
Using mvvm on the web using knockoutjs & ignite uiUsing mvvm on the web using knockoutjs & ignite ui
Using mvvm on the web using knockoutjs & ignite uiNish Anil
 
Knockout (support slides for presentation)
Knockout (support slides for presentation)Knockout (support slides for presentation)
Knockout (support slides for presentation)Aymeric Gaurat-Apelli
 
Introduction to Knockoutjs
Introduction to KnockoutjsIntroduction to Knockoutjs
Introduction to Knockoutjsjhoguet
 
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
 
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneJavascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneDeepu S Nath
 
Download presentation
Download presentationDownload presentation
Download presentationwebhostingguy
 
Slideshare Powerpoint presentation
Slideshare Powerpoint presentationSlideshare Powerpoint presentation
Slideshare Powerpoint presentationelliehood
 

Andere mochten auch (14)

Knockout.js explained
Knockout.js explainedKnockout.js explained
Knockout.js explained
 
Using mvvm on the web using knockoutjs & ignite ui
Using mvvm on the web using knockoutjs & ignite uiUsing mvvm on the web using knockoutjs & ignite ui
Using mvvm on the web using knockoutjs & ignite ui
 
Knockout js
Knockout jsKnockout js
Knockout js
 
knockout.js
knockout.jsknockout.js
knockout.js
 
Knockout js (Dennis Haney)
Knockout js (Dennis Haney)Knockout js (Dennis Haney)
Knockout js (Dennis Haney)
 
Knockout (support slides for presentation)
Knockout (support slides for presentation)Knockout (support slides for presentation)
Knockout (support slides for presentation)
 
Introduction to Knockoutjs
Introduction to KnockoutjsIntroduction to Knockoutjs
Introduction to Knockoutjs
 
Knockout.js
Knockout.jsKnockout.js
Knockout.js
 
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
 
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneJavascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
 
Download presentation
Download presentationDownload presentation
Download presentation
 
Slideshare Powerpoint presentation
Slideshare Powerpoint presentationSlideshare Powerpoint presentation
Slideshare Powerpoint presentation
 

Ähnlich wie KnockoutJS and MVVM

Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its featuresAbhishek Sur
 
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVMAbhishek Sur
 
Knockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockoutKnockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockoutAndoni Arroyo
 
Data Binding in Silverlight
Data Binding in SilverlightData Binding in Silverlight
Data Binding in SilverlightBoulos Dib
 
Knockoutjs databinding
Knockoutjs databindingKnockoutjs databinding
Knockoutjs databindingBoulos Dib
 
Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1Salesforce Developers
 
Flex3 Deep Dive Final
Flex3 Deep Dive FinalFlex3 Deep Dive Final
Flex3 Deep Dive FinalRJ Owen
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applicationsIvano Malavolta
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinBarry Gervin
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019iFour Technolab Pvt. Ltd.
 
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
 
WPF - Controls & Data
WPF - Controls & DataWPF - Controls & Data
WPF - Controls & DataSharada Gururaj
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015Hossein Zahed
 
Diving in the Flex Data Binding Waters
Diving in the Flex Data Binding WatersDiving in the Flex Data Binding Waters
Diving in the Flex Data Binding Watersmichael.labriola
 
SCWCD : Web tier design CHAP : 11
SCWCD : Web tier design CHAP : 11SCWCD : Web tier design CHAP : 11
SCWCD : Web tier design CHAP : 11Ben Abdallah Helmi
 
MVVM & Data Binding Library
MVVM & Data Binding Library MVVM & Data Binding Library
MVVM & Data Binding Library 10Clouds
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsJeff Durta
 

Ähnlich wie KnockoutJS and MVVM (20)

Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its features
 
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVM
 
Knockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockoutKnockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockout
 
Data Binding in Silverlight
Data Binding in SilverlightData Binding in Silverlight
Data Binding in Silverlight
 
Knockoutjs databinding
Knockoutjs databindingKnockoutjs databinding
Knockoutjs databinding
 
Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1
 
Knockout Introduction
Knockout IntroductionKnockout Introduction
Knockout Introduction
 
Flex3 Deep Dive Final
Flex3 Deep Dive FinalFlex3 Deep Dive Final
Flex3 Deep Dive Final
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019
 
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
 
WPF - Controls & Data
WPF - Controls & DataWPF - Controls & Data
WPF - Controls & Data
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015
 
Diving in the Flex Data Binding Waters
Diving in the Flex Data Binding WatersDiving in the Flex Data Binding Waters
Diving in the Flex Data Binding Waters
 
SCWCD : Web tier design CHAP : 11
SCWCD : Web tier design CHAP : 11SCWCD : Web tier design CHAP : 11
SCWCD : Web tier design CHAP : 11
 
MVVM & Data Binding Library
MVVM & Data Binding Library MVVM & Data Binding Library
MVVM & Data Binding Library
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 

Kürzlich hochgeladen

CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 

Kürzlich hochgeladen (20)

Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 

KnockoutJS and MVVM

  • 1. IntelliMeet April, 14 KnockoutJS and MVVM Manvendra SK Twitter: @Manvendra_SK
  • 2. What Is KnockoutJS ? Rich client-side interactivity MVVM pattern Web browser support Separates behavior and structure Declarative bindings Observables 6+ 2+
  • 3. What Is The Problem ? Delete Underlying Data View What Is The Solution ? Delete Underlying Data View
  • 4. What KnockoutJS Is Not ? Client side code Server code Database KnockoutJS
  • 5. What Is MVVM ? Model View ViewModel
  • 6. Core Observable Types Computed Observable Observable Array
  • 7. How Knockout’s Observables Works ? Changes to Targets Notify Source Changes to Source Notify Targets Two-Way Data Binding Event Binding
  • 8. Observable And Binding • Make Property on object an observable using ko.observable() method passing default value. • Call ko.applyBindings() method passing object to method. • Bind properties of ViewModel object to html elements using data-bind attribute any binding like text. More on this later. • You can make the object using a constructor. *
  • 9. Observable Tricks • Any property that is declared observable is a function like getter and setter. • To access property use: vmObject.property() • To set property use: vmObject.property(_newValue) • Don’t ever use = operator to assign values. You’ll overwrite the observable.
  • 10. Interactive Binding • We have used text binding. That was a non-interactive binding. • Interactive binding is when user interact with the page and hence the binding. • click is such a binding. • More on this later.
  • 11. Computed Observable Define Your Own Derived Property When You Need A Value That Doesn’t Exist in Web Service Based On Other Properties and Observables Also Supports Data Binding
  • 12. Computed Observable And Binding • Make Property on object an computed observable using ko.computed() method passing a anonymous function that returns computed value. • Bind to html elements using data-bind attribute.
  • 13. Observable Array Notify When Items Are Added Or Removed Tracks Which Objects Are In The Array No Notification When Objects In The Array Change Bonus: Can Use Array Functions
  • 14. Observable Array And Binding • Make Property on object an observable array using ko.observableArray() method passing an array literal. • Bind to html elements using data-bind attribute and foreach binding. • Binding contexts inside foreach: $root et al. More on this later. • mvObject.arrayProp() gives you native underlying array.
  • 15. Observable Array Methods • push(), pop() • unshift(), shift(), slice() • remove(), removeAll(), destroy(), destroyAll() • sort(), reversed() • indexOf()
  • 16. Built In Bindings Binding For Element Attributes Multiple Binding Expressions Built Into Knockout
  • 17. Control Flow Bindings foreach if ifnot with text html visible css style attr click value event enable disable checked options selectedOptions hasfocus
  • 18. Appearance Bindings foreach if ifnot with text html visible css style attr click value event enable disable checked options selectedOptions hasfocus
  • 19. Interactive Bindings foreach if ifnot with text html visible css style attr click value event enable disable checked options selectedOptions hasfocus
  • 22. Binding Contexts • What if you need to access ViewModel object while iterating array using foreach binding? • $root : Top level ViewModel object. • $data : Refers to object for the current context. Like this keyword in JavaScript. Useful for atomic values like strings and numbers. • $index : Obviously index number of current item.
  • 23. Binding Contexts • $parent : Refers to the parent ViewModel object. Typically used inside nested loops and when you need to access properties in the outer loop.
  • 24. if And ifnot Bindings
  • 25. with Binding • Used when you want to manually declare block scope to particular property of ViewModel.
  • 27. text Binding html Binding visible Binding attr Binding
  • 28. style Binding css Binding
  • 30. click Binding • click binding is one of the simplest interactive binding. It just calls a method on your ViewModel when the user click the element passing function two arguments model and event. • vmObject.someMethod = function(model, event) { // do what ever you want here… };
  • 31. value Binding • Similar to text binding. But this time user can update the value from the View and ViewModel will update accordingly. Thus value binding is two way binding.
  • 32. event Binding • The event binding lets you listen for arbitrary DOM events on any HTML element. • As it can listen for multiple events, it requires an object to map events. Just like attr binding. • data-bind=“event: {mouseover: someMethod, mouseOut: someOtherMethod}”
  • 33. event Binding • The function will take two arguments called data and event. • vmObject.someMethod = function(data, event) { // do what ever you want on happening // of this event… };
  • 34. A Better event Binding
  • 35. enable and disable Binding • Used to enable or disable some form element on some particular condition.
  • 36. checked Binding • Used to select or deselect HTML’s selectable elements like check boxes and radio buttons. • We can also use arrays instead of true or false value in the observable. In this case only those check boxes will be selected whose value attribute value exist in the array. • Matches value attribute value of radio button to single value in observable.
  • 37. options Binding • This binding is used to build options elements inside a select element from an observable array. • value binding is used to preselect or get the selected item in the select list. • optionsText binding is used to show the content on the view when using objects in the observable array instead of literals.
  • 38. selectedOptions Binding • As a select list can be made to select multiple items so to retrieve or set all the selected items we need an array instead of using an atomic value. Thus instead of value binding we use selectedOptions binding.
  • 39. hasfocus Binding • Allows us to put the focus on any element.
  • 40. Interacting With Server Saving Data Mapping Data To ViewModel Loading Data
  • 41. Mapping Data To ViewModel • Mapping plugin dynamically generates new observables.
  • 42. Animation Inside Knockout • Don’t support animation from core, as it’s a view binding library not DOM manipulation library. • All Knockout’s automatic updates are immediately applied whenever underlying data changes.
  • 43. List Callbacks • Knockout is a powerful user interface library on its own, but once you combine it with the animation capabilities of a framework like jQuery or MooTools, you’re ready to create truly stunning UIs with minimal markup. • The foreach binding has two callbacks named beforeRemove and afterAdd. These functions are executed before an item is removed from the list or after it’s been added to the list, respectively. This is our chance to put in animation logic before Knockout manipulates the DOM.
  • 44. List Callbacks • These callbacks take a parameter named element which a reference to the element which Knockout is manipulating.
  • 45. Custom Bindings • Okey, we’re having fun with foreach binding and its some level support for plugging in animation logic. But what about other bindings? They don’t support this already. So Custom Bindings is answer to the question. • We can make our own bindings by adding an object defining the binding to ko.bindingHandlers. This also happens to be where all of the built-in bindings are defined, too.
  • 46. Custom Bindings • The object should have two methods namely init and update. • init method is called when Knockout first encounters the binding. So this callback should define the initial state for the view component and perform necessary setup actions like registering event listeners.
  • 47. Custom Bindings • The update method executes whenever the associated observable changes. • Both methods take same two parameters namely element and valueAccessor. • The element parameter is the DOM element being bound, and valueAccessor is a function that will return the ViewModel property in question (here it is binding value).
  • 48. Conclusion • Knockout.js is a pure JavaScript library that makes it incredibly easy to build dynamic, data-centric user interfaces. • We covered most of the Knockout.js API, but there are still a number of nuances left to discover. • Knockout.js provides plethora of extensibility opportunities for you to explore!