SlideShare uma empresa Scribd logo
1 de 36
Bringing the light to the client
   with KnockoutJS

var speaker = {
   name: “Boyan Mihaylov”,
   company: “Ebita.dk”
};
About me

 Software Developer @ Ebita.dk
   Software architectures / system integration
   Best practices
   Web trends
 (Almost) Ms.c. in Computer Science @ The
  University of Copenhagen
 Teaching assistant @ UCPH
   Principles of Computer System Design
What‟s there for today?

   Why JavaScript
   Why MV* patterns
   What is KnockoutJS
   How it works
   Extensibility
Why is JavaScript so popular?

 Runs in the browser
   No 3rd-party software
 Considerably fast (in the latest browsers)
 Low entry barriers
   a.k.a. (reasonably) low learning curve
 Still in the game with HTML5
Why people hate JavaScript?

 “Few” programming misunderstandings
   Global variables
   The proper “this” in functions
   …
 Browser (in)compatibility
  Especially the blue guy
  behind
jQuery for the win!

 Rich API for DOM manipulation
   Traversing
   Event handling
   Animations
 Browser compatibility
Before & after jQuery

if (document.getElementById) ...
else if (document.layers) …        Before
else if (document.all) …



$(‟#my_id‟)                         After
But...




 Too much of a good thing is not a good thing
The rise of MV* patterns

 MV* stands for Model-View-(many variations)
   MVC (Model-View-Controller)
   MVVM (Model-View-ViewModel)
 Separation between the data and how it is
  displayed
MVC vs. MVVM

                                MVC      MVVM
                                                                User
        User
                  Determines                                 View
  Controller                              Passes
                                         calls to
                         View                                   Fires events
                                           ViewModel
                 State          Fires
                                                         Fires events
               queries          events

Manipulates                                Manipulates
                     Model                                    Model
MV* libraries & frameworks




          http://todomvc.com
What is KnockoutJS?

   MVVM JavaScript library
   MIT license
   No dependencies
   Supports all mainstream browsers
   Active community
Key concepts



     Declarative   Automatic UI
      bindings       refresh




    Dependency     Templating
      tracking
First steps: data binding (1)

 The magic of data-bind attribute
<span data-bind=“text: name”></span>

 Apply the bindings
ko.applyBindings(viewModel);
First steps: data binding (2)

 The syntax
  data-bind=“binding1: value1, binding2: value2,…”
 Pre-defined bindings
     text – displays text in an element (span, div, ....)
     value – for form elements (input, textarea, ...)
     click – associates a function
     visible – whether to display an element or not
     [ more on Knockout‟s website ]
Meet the observables

     var name = ko.observable(„Boyan‟);
 Functions
 Provide getters and setters
   name() is getter, name(„Peter‟) is setter
 Cache values
 Notify on changes
   name.subscribe(function(newValue) { … })
Computed observables (1)


var firstName = ko.observable(„Boyan‟);
var lastName = ko.observable(„Mihaylov‟);
var fullName = ko.computed(function() {
    return firstName() + „ „ + lastName();
});
Computed observables (2)

 Track dependencies
 Reevaluate on changes in the dependencies
 Can provide only getter or both getter and
  setter
 NOTE: Beware of circular dependencies
Observable arrays

      var names = ko.observableArray(
          ['Boyan', 'Peter', 'Elena']);

 Same as normal observables, but …
 Provide array utility functions
   push, pop, remove, slice, etc.
How to display an array?                       Indeed,
                                                how??

 Display each item in the array
 Meet the foreach binding
   Repeat the children template for each array item
   Efficient DOM manipulation - update only the
    changed parts
   Special context parameter - $parent
Extensibility: make it your way
Extend the observables

 Custom functionality associated with an
  observable
 What can we do?
   Validation
   Custom event
   …
        var age = ko.observable(10)
                .extend({ numeric: true });
Integration with other libraries

           Can we use
            Knockout
           with jQuery?




            I don‟t
                                   Yes, yes, yes!
            know…
Custom bindings (1)



<div data-bind="myBinding: data">…</div>
Custom bindings (2)

ko.bindingHandlers.myBinding = {
 // Set initial state for the DOM element
 // or register event handlers
 init: function(element, valueAccessor) { },

 // Whenever the value changes
 update: function(element, valueAccessor) { }
};
Custom bindings (3)

 Parameters
   element – the bound DOM element
   valueAccessor – a function, which returns the
    value (an observable or a plain value)
   allBindingsAccessor – a function, which returns all
    other bindings set to the element
   [ some more parameters on Knockout‟s website ]
Custom providers (1)

 Looks nice



   <div data-bind="text: name"></div>
Custom providers (2)

 Getting a bit messy

<div data-bind="text: name, visible:
  items().length > 0 && amICool(),
  customBinding: { item: 5 },
  click: showMeMoreCoolStuff"></div>
Custom providers (3)

 A complete disaster!

<div data-bind="text: name, visible:
  items().length > 0 && amICool(),
  customBinding: { item: 5, count: getGount
  }, click: showMeMoreCoolStuff, children: {
  showOnly: myChildren().length > 5,
  deleteOn: „mouseover‟ }, reset:
  „onleave‟"></div>
Custom providers (4)

   Don‟t like the data-bind attributes?
   Your markup is too messy?
   All designers in the company hate you?
   …
Custom providers (5)

 We have a solution for you!


var myBindingProvider = {
 // does a node have bindings?
 nodeHasBindings: function(node) { },
 // give me the bindings!
 getBindings: function(node, context) {}
};
Custom providers (6)

 Use id/class for attaching bindings
   Knockout.Unobtrusive plugin
 Store bindings in jQuery $.data on the
  elements
 Use more specific attributes
   e.g., data-bind-text, data-bind-image, …
Nice to read

 http://www.knockoutjs.com

 http://www.knockmeout.net

 http://groups.google.com/group/knockoutjs
Questions
Expect very soon: SharePoint Saturday!




  Saturday, June 8, 2013
  Same familiar format – 1 day filled with sessions
   focused on SharePoint technologies
  Best SharePoint professionals in the region
  Registrations will be open next week (15th)!
  www.SharePointSaturday.eu
Thanks to our Sponsors:
Diamond Sponsor:



Platinum Sponsors:




Gold Sponsors:



Swag Sponsors:

Media Partners:

Mais conteúdo relacionado

Mais procurados

Windows 8 Training Fundamental - 1
Windows 8 Training Fundamental - 1Windows 8 Training Fundamental - 1
Windows 8 Training Fundamental - 1Kevin Octavian
 
Anton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightAnton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightMichael Pustovit
 
Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"Fwdays
 
"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил АнохинFwdays
 
Data binding в массы! (1.2)
Data binding в массы! (1.2)Data binding в массы! (1.2)
Data binding в массы! (1.2)Yurii Kotov
 
JQuery New Evolution
JQuery New EvolutionJQuery New Evolution
JQuery New EvolutionAllan Huang
 
Client Side MVC & Angular
Client Side MVC & AngularClient Side MVC & Angular
Client Side MVC & AngularAlexe Bogdan
 
Final microsoft cloud summit - windows azure building block services
Final   microsoft cloud summit - windows azure building block servicesFinal   microsoft cloud summit - windows azure building block services
Final microsoft cloud summit - windows azure building block servicesstratospheres
 
Modular javascript
Modular javascriptModular javascript
Modular javascriptZain Shaikh
 
JDBC (JAVA Database Connectivity)
JDBC (JAVA Database Connectivity)JDBC (JAVA Database Connectivity)
JDBC (JAVA Database Connectivity)HimanshiSingh71
 
SE2016 Android Mikle Anokhin "Speed up application development with data bind...
SE2016 Android Mikle Anokhin "Speed up application development with data bind...SE2016 Android Mikle Anokhin "Speed up application development with data bind...
SE2016 Android Mikle Anokhin "Speed up application development with data bind...Inhacking
 
Deep dive into Android Data Binding
Deep dive into Android Data BindingDeep dive into Android Data Binding
Deep dive into Android Data BindingRadek Piekarz
 
Planbox Backbone MVC
Planbox Backbone MVCPlanbox Backbone MVC
Planbox Backbone MVCAcquisio
 

Mais procurados (19)

Matreshka.js
Matreshka.jsMatreshka.js
Matreshka.js
 
Windows 8 Training Fundamental - 1
Windows 8 Training Fundamental - 1Windows 8 Training Fundamental - 1
Windows 8 Training Fundamental - 1
 
Jquery beltranhomewrok
Jquery beltranhomewrokJquery beltranhomewrok
Jquery beltranhomewrok
 
Anton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightAnton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 light
 
Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"
 
"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин
 
Data binding в массы! (1.2)
Data binding в массы! (1.2)Data binding в массы! (1.2)
Data binding в массы! (1.2)
 
JQuery New Evolution
JQuery New EvolutionJQuery New Evolution
JQuery New Evolution
 
Client Web
Client WebClient Web
Client Web
 
Client Side MVC & Angular
Client Side MVC & AngularClient Side MVC & Angular
Client Side MVC & Angular
 
Final microsoft cloud summit - windows azure building block services
Final   microsoft cloud summit - windows azure building block servicesFinal   microsoft cloud summit - windows azure building block services
Final microsoft cloud summit - windows azure building block services
 
Modular javascript
Modular javascriptModular javascript
Modular javascript
 
JDBC (JAVA Database Connectivity)
JDBC (JAVA Database Connectivity)JDBC (JAVA Database Connectivity)
JDBC (JAVA Database Connectivity)
 
Dmytro Zaitsev Viper: make your mvp cleaner
Dmytro Zaitsev Viper: make your mvp cleanerDmytro Zaitsev Viper: make your mvp cleaner
Dmytro Zaitsev Viper: make your mvp cleaner
 
Codemotion appengine
Codemotion appengineCodemotion appengine
Codemotion appengine
 
SE2016 Android Mikle Anokhin "Speed up application development with data bind...
SE2016 Android Mikle Anokhin "Speed up application development with data bind...SE2016 Android Mikle Anokhin "Speed up application development with data bind...
SE2016 Android Mikle Anokhin "Speed up application development with data bind...
 
Deep dive into Android Data Binding
Deep dive into Android Data BindingDeep dive into Android Data Binding
Deep dive into Android Data Binding
 
Planbox Backbone MVC
Planbox Backbone MVCPlanbox Backbone MVC
Planbox Backbone MVC
 
Vaadin7
Vaadin7Vaadin7
Vaadin7
 

Destaque

Being a generalist and being great at what you do
Being a generalist and being great at what you doBeing a generalist and being great at what you do
Being a generalist and being great at what you doIgor Moochnick
 
Kolczatka australijska rozmnażanie
Kolczatka australijska  rozmnażanieKolczatka australijska  rozmnażanie
Kolczatka australijska rozmnażanieCzijos
 
FSIL-2020-Strategic-Plan
FSIL-2020-Strategic-PlanFSIL-2020-Strategic-Plan
FSIL-2020-Strategic-PlanGary Jackson
 
Plan de educacion ambiental
Plan de educacion ambientalPlan de educacion ambiental
Plan de educacion ambientalJuan Sierra
 
HI 83f -Agir en faveur des personnes handicapées et des groupes particulièrem...
HI 83f -Agir en faveur des personnes handicapées et des groupes particulièrem...HI 83f -Agir en faveur des personnes handicapées et des groupes particulièrem...
HI 83f -Agir en faveur des personnes handicapées et des groupes particulièrem...Bernard hardy
 
Ficha Descriptiva Redes Sociales en la Educación
Ficha Descriptiva Redes Sociales en la Educación Ficha Descriptiva Redes Sociales en la Educación
Ficha Descriptiva Redes Sociales en la Educación VICTOR VIERA BALANTA
 
The Mineral and Petroleum Resources Royalty Act, 28 of 2008 and the Mineral a...
The Mineral and Petroleum Resources Royalty Act, 28 of 2008 and the Mineral a...The Mineral and Petroleum Resources Royalty Act, 28 of 2008 and the Mineral a...
The Mineral and Petroleum Resources Royalty Act, 28 of 2008 and the Mineral a...Werksmans Attorneys
 
Global Expansion Summit - London - 17 oct 2016 - Bruno Bensaid
Global Expansion Summit - London - 17 oct 2016 - Bruno BensaidGlobal Expansion Summit - London - 17 oct 2016 - Bruno Bensaid
Global Expansion Summit - London - 17 oct 2016 - Bruno BensaidBruno Bensaid
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More ParanoidDavid Evans
 
Medio ambiente y nuevas tecnologias
Medio ambiente y nuevas tecnologiasMedio ambiente y nuevas tecnologias
Medio ambiente y nuevas tecnologiasMatias ascanio
 
Investigar Antecedentes, Hasta La Actualidad Que Organismos De Gobierno Evalú...
Investigar Antecedentes, Hasta La Actualidad Que Organismos De Gobierno Evalú...Investigar Antecedentes, Hasta La Actualidad Que Organismos De Gobierno Evalú...
Investigar Antecedentes, Hasta La Actualidad Que Organismos De Gobierno Evalú...Franklin Sosa Cifuentes
 
Untitled Presentation
Untitled PresentationUntitled Presentation
Untitled PresentationMonica Bonino
 

Destaque (20)

Freshman Resume Template
Freshman Resume TemplateFreshman Resume Template
Freshman Resume Template
 
Being a generalist and being great at what you do
Being a generalist and being great at what you doBeing a generalist and being great at what you do
Being a generalist and being great at what you do
 
Kolczatka australijska rozmnażanie
Kolczatka australijska  rozmnażanieKolczatka australijska  rozmnażanie
Kolczatka australijska rozmnażanie
 
Comercial da paz
Comercial da pazComercial da paz
Comercial da paz
 
FSIL-2020-Strategic-Plan
FSIL-2020-Strategic-PlanFSIL-2020-Strategic-Plan
FSIL-2020-Strategic-Plan
 
Hipervinculo2
Hipervinculo2Hipervinculo2
Hipervinculo2
 
Plan de educacion ambiental
Plan de educacion ambientalPlan de educacion ambiental
Plan de educacion ambiental
 
HI 83f -Agir en faveur des personnes handicapées et des groupes particulièrem...
HI 83f -Agir en faveur des personnes handicapées et des groupes particulièrem...HI 83f -Agir en faveur des personnes handicapées et des groupes particulièrem...
HI 83f -Agir en faveur des personnes handicapées et des groupes particulièrem...
 
Algoritmos Genéticos
Algoritmos GenéticosAlgoritmos Genéticos
Algoritmos Genéticos
 
Ficha Descriptiva Redes Sociales en la Educación
Ficha Descriptiva Redes Sociales en la Educación Ficha Descriptiva Redes Sociales en la Educación
Ficha Descriptiva Redes Sociales en la Educación
 
Teori piag
Teori piagTeori piag
Teori piag
 
Generador de números aleatorios
Generador de números aleatoriosGenerador de números aleatorios
Generador de números aleatorios
 
The Mineral and Petroleum Resources Royalty Act, 28 of 2008 and the Mineral a...
The Mineral and Petroleum Resources Royalty Act, 28 of 2008 and the Mineral a...The Mineral and Petroleum Resources Royalty Act, 28 of 2008 and the Mineral a...
The Mineral and Petroleum Resources Royalty Act, 28 of 2008 and the Mineral a...
 
Global Expansion Summit - London - 17 oct 2016 - Bruno Bensaid
Global Expansion Summit - London - 17 oct 2016 - Bruno BensaidGlobal Expansion Summit - London - 17 oct 2016 - Bruno Bensaid
Global Expansion Summit - London - 17 oct 2016 - Bruno Bensaid
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More Paranoid
 
Medio ambiente y nuevas tecnologias
Medio ambiente y nuevas tecnologiasMedio ambiente y nuevas tecnologias
Medio ambiente y nuevas tecnologias
 
FeatureOwner
FeatureOwnerFeatureOwner
FeatureOwner
 
Investigar Antecedentes, Hasta La Actualidad Que Organismos De Gobierno Evalú...
Investigar Antecedentes, Hasta La Actualidad Que Organismos De Gobierno Evalú...Investigar Antecedentes, Hasta La Actualidad Que Organismos De Gobierno Evalú...
Investigar Antecedentes, Hasta La Actualidad Que Organismos De Gobierno Evalú...
 
Untitled Presentation
Untitled PresentationUntitled Presentation
Untitled Presentation
 
Introducthion mvvm avec wpf
Introducthion mvvm avec wpfIntroducthion mvvm avec wpf
Introducthion mvvm avec wpf
 

Semelhante a Bringing the light to the client with KnockoutJS

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
 
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
 
MVC pattern for widgets
MVC pattern for widgetsMVC pattern for widgets
MVC pattern for widgetsBehnam Taraghi
 
Integration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDBIntegration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDBMichal Bigos
 
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVMAbhishek Sur
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its featuresAbhishek Sur
 
WPF - Controls &amp; Data
WPF - Controls &amp; DataWPF - Controls &amp; Data
WPF - Controls &amp; DataSharada Gururaj
 
Gitter marionette deck
Gitter marionette deckGitter marionette deck
Gitter marionette deckMike Bartlett
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applicationsIvano Malavolta
 
Single page webapps & javascript-testing
Single page webapps & javascript-testingSingle page webapps & javascript-testing
Single page webapps & javascript-testingsmontanari
 
Knockout Basics By Surekha Gadkari
Knockout Basics By Surekha GadkariKnockout Basics By Surekha Gadkari
Knockout Basics By Surekha GadkariSurekha Gadkari
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.jsBert Wijnants
 
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
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Domkaven yan
 

Semelhante a Bringing the light to the client with KnockoutJS (20)

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
 
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!
 
MVC pattern for widgets
MVC pattern for widgetsMVC pattern for widgets
MVC pattern for widgets
 
Fundaments of Knockout js
Fundaments of Knockout jsFundaments of Knockout js
Fundaments of Knockout js
 
Integration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDBIntegration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDB
 
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVM
 
Knockout js session
Knockout js sessionKnockout js session
Knockout js session
 
Knockout.js
Knockout.jsKnockout.js
Knockout.js
 
Knockoutjs
KnockoutjsKnockoutjs
Knockoutjs
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its features
 
WPF - Controls &amp; Data
WPF - Controls &amp; DataWPF - Controls &amp; Data
WPF - Controls &amp; Data
 
Gitter marionette deck
Gitter marionette deckGitter marionette deck
Gitter marionette deck
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
 
GWT MVP Case Study
GWT MVP Case StudyGWT MVP Case Study
GWT MVP Case Study
 
Single page webapps & javascript-testing
Single page webapps & javascript-testingSingle page webapps & javascript-testing
Single page webapps & javascript-testing
 
Knockout Basics By Surekha Gadkari
Knockout Basics By Surekha GadkariKnockout Basics By Surekha Gadkari
Knockout Basics By Surekha Gadkari
 
KnockoutJS and MVVM
KnockoutJS and MVVMKnockoutJS and MVVM
KnockoutJS and MVVM
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.js
 
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
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
 

Mais de Boyan Mihaylov

How WebAssembly is changing the Web and what it means for Angular
How WebAssembly is changing the Web and what it means for AngularHow WebAssembly is changing the Web and what it means for Angular
How WebAssembly is changing the Web and what it means for AngularBoyan Mihaylov
 
Crafting a robust deployment pipeline in finance
Crafting a robust deployment pipeline in financeCrafting a robust deployment pipeline in finance
Crafting a robust deployment pipeline in financeBoyan Mihaylov
 
Using improv techniques for better agile teams
Using improv techniques for better agile teamsUsing improv techniques for better agile teams
Using improv techniques for better agile teamsBoyan Mihaylov
 
Web assembly brings the web to a new era
Web assembly brings the web to a new eraWeb assembly brings the web to a new era
Web assembly brings the web to a new eraBoyan Mihaylov
 
Showdown CI/CD - TeamCity
Showdown CI/CD - TeamCityShowdown CI/CD - TeamCity
Showdown CI/CD - TeamCityBoyan Mihaylov
 
Stop the internet, i want to go offline
Stop the internet, i want to go offlineStop the internet, i want to go offline
Stop the internet, i want to go offlineBoyan Mihaylov
 
Is WebAssembly the killer of JavaScript?
Is WebAssembly the killer of JavaScript?Is WebAssembly the killer of JavaScript?
Is WebAssembly the killer of JavaScript?Boyan Mihaylov
 
Lean or agile, software architecture is fragile
Lean or agile, software architecture is fragileLean or agile, software architecture is fragile
Lean or agile, software architecture is fragileBoyan Mihaylov
 
Software architecture also needs agile
Software architecture also needs agileSoftware architecture also needs agile
Software architecture also needs agileBoyan Mihaylov
 
Agile software architecture
Agile software architectureAgile software architecture
Agile software architectureBoyan Mihaylov
 
Component-driven development with AngularJS
Component-driven development with AngularJSComponent-driven development with AngularJS
Component-driven development with AngularJSBoyan Mihaylov
 
Identifying methods for measuring emotions
Identifying methods for measuring emotionsIdentifying methods for measuring emotions
Identifying methods for measuring emotionsBoyan Mihaylov
 

Mais de Boyan Mihaylov (17)

How WebAssembly is changing the Web and what it means for Angular
How WebAssembly is changing the Web and what it means for AngularHow WebAssembly is changing the Web and what it means for Angular
How WebAssembly is changing the Web and what it means for Angular
 
Crafting a robust deployment pipeline in finance
Crafting a robust deployment pipeline in financeCrafting a robust deployment pipeline in finance
Crafting a robust deployment pipeline in finance
 
Using improv techniques for better agile teams
Using improv techniques for better agile teamsUsing improv techniques for better agile teams
Using improv techniques for better agile teams
 
Web assembly brings the web to a new era
Web assembly brings the web to a new eraWeb assembly brings the web to a new era
Web assembly brings the web to a new era
 
Showdown CI/CD - TeamCity
Showdown CI/CD - TeamCityShowdown CI/CD - TeamCity
Showdown CI/CD - TeamCity
 
Stop the internet, i want to go offline
Stop the internet, i want to go offlineStop the internet, i want to go offline
Stop the internet, i want to go offline
 
Shifting to agile
Shifting to agileShifting to agile
Shifting to agile
 
Is WebAssembly the killer of JavaScript?
Is WebAssembly the killer of JavaScript?Is WebAssembly the killer of JavaScript?
Is WebAssembly the killer of JavaScript?
 
Lean or agile, software architecture is fragile
Lean or agile, software architecture is fragileLean or agile, software architecture is fragile
Lean or agile, software architecture is fragile
 
Software architecture also needs agile
Software architecture also needs agileSoftware architecture also needs agile
Software architecture also needs agile
 
Flux architecture
Flux architectureFlux architecture
Flux architecture
 
AngularJS 2.0
AngularJS 2.0AngularJS 2.0
AngularJS 2.0
 
To SPA or not to SPA
To SPA or not to SPATo SPA or not to SPA
To SPA or not to SPA
 
The AngularJS way
The AngularJS wayThe AngularJS way
The AngularJS way
 
Agile software architecture
Agile software architectureAgile software architecture
Agile software architecture
 
Component-driven development with AngularJS
Component-driven development with AngularJSComponent-driven development with AngularJS
Component-driven development with AngularJS
 
Identifying methods for measuring emotions
Identifying methods for measuring emotionsIdentifying methods for measuring emotions
Identifying methods for measuring emotions
 

Último

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
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
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
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
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
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
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
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
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 

Último (20)

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
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
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
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 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
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
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
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
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 

Bringing the light to the client with KnockoutJS

  • 1. Bringing the light to the client with KnockoutJS var speaker = { name: “Boyan Mihaylov”, company: “Ebita.dk” };
  • 2. About me  Software Developer @ Ebita.dk  Software architectures / system integration  Best practices  Web trends  (Almost) Ms.c. in Computer Science @ The University of Copenhagen  Teaching assistant @ UCPH  Principles of Computer System Design
  • 3. What‟s there for today?  Why JavaScript  Why MV* patterns  What is KnockoutJS  How it works  Extensibility
  • 4. Why is JavaScript so popular?  Runs in the browser  No 3rd-party software  Considerably fast (in the latest browsers)  Low entry barriers  a.k.a. (reasonably) low learning curve  Still in the game with HTML5
  • 5. Why people hate JavaScript?  “Few” programming misunderstandings  Global variables  The proper “this” in functions  …  Browser (in)compatibility Especially the blue guy behind
  • 6. jQuery for the win!  Rich API for DOM manipulation  Traversing  Event handling  Animations  Browser compatibility
  • 7. Before & after jQuery if (document.getElementById) ... else if (document.layers) … Before else if (document.all) … $(‟#my_id‟) After
  • 8. But... Too much of a good thing is not a good thing
  • 9. The rise of MV* patterns  MV* stands for Model-View-(many variations)  MVC (Model-View-Controller)  MVVM (Model-View-ViewModel)  Separation between the data and how it is displayed
  • 10. MVC vs. MVVM MVC MVVM User User Determines View Controller Passes calls to View Fires events ViewModel State Fires Fires events queries events Manipulates Manipulates Model Model
  • 11. MV* libraries & frameworks http://todomvc.com
  • 12. What is KnockoutJS?  MVVM JavaScript library  MIT license  No dependencies  Supports all mainstream browsers  Active community
  • 13. Key concepts Declarative Automatic UI bindings refresh Dependency Templating tracking
  • 14. First steps: data binding (1)  The magic of data-bind attribute <span data-bind=“text: name”></span>  Apply the bindings ko.applyBindings(viewModel);
  • 15. First steps: data binding (2)  The syntax data-bind=“binding1: value1, binding2: value2,…”  Pre-defined bindings  text – displays text in an element (span, div, ....)  value – for form elements (input, textarea, ...)  click – associates a function  visible – whether to display an element or not  [ more on Knockout‟s website ]
  • 16. Meet the observables var name = ko.observable(„Boyan‟);  Functions  Provide getters and setters  name() is getter, name(„Peter‟) is setter  Cache values  Notify on changes  name.subscribe(function(newValue) { … })
  • 17. Computed observables (1) var firstName = ko.observable(„Boyan‟); var lastName = ko.observable(„Mihaylov‟); var fullName = ko.computed(function() { return firstName() + „ „ + lastName(); });
  • 18. Computed observables (2)  Track dependencies  Reevaluate on changes in the dependencies  Can provide only getter or both getter and setter  NOTE: Beware of circular dependencies
  • 19. Observable arrays var names = ko.observableArray( ['Boyan', 'Peter', 'Elena']);  Same as normal observables, but …  Provide array utility functions  push, pop, remove, slice, etc.
  • 20. How to display an array? Indeed, how??  Display each item in the array  Meet the foreach binding  Repeat the children template for each array item  Efficient DOM manipulation - update only the changed parts  Special context parameter - $parent
  • 22. Extend the observables  Custom functionality associated with an observable  What can we do?  Validation  Custom event  … var age = ko.observable(10) .extend({ numeric: true });
  • 23. Integration with other libraries Can we use Knockout with jQuery? I don‟t Yes, yes, yes! know…
  • 24. Custom bindings (1) <div data-bind="myBinding: data">…</div>
  • 25. Custom bindings (2) ko.bindingHandlers.myBinding = { // Set initial state for the DOM element // or register event handlers init: function(element, valueAccessor) { }, // Whenever the value changes update: function(element, valueAccessor) { } };
  • 26. Custom bindings (3)  Parameters  element – the bound DOM element  valueAccessor – a function, which returns the value (an observable or a plain value)  allBindingsAccessor – a function, which returns all other bindings set to the element  [ some more parameters on Knockout‟s website ]
  • 27. Custom providers (1)  Looks nice <div data-bind="text: name"></div>
  • 28. Custom providers (2)  Getting a bit messy <div data-bind="text: name, visible: items().length > 0 && amICool(), customBinding: { item: 5 }, click: showMeMoreCoolStuff"></div>
  • 29. Custom providers (3)  A complete disaster! <div data-bind="text: name, visible: items().length > 0 && amICool(), customBinding: { item: 5, count: getGount }, click: showMeMoreCoolStuff, children: { showOnly: myChildren().length > 5, deleteOn: „mouseover‟ }, reset: „onleave‟"></div>
  • 30. Custom providers (4)  Don‟t like the data-bind attributes?  Your markup is too messy?  All designers in the company hate you?  …
  • 31. Custom providers (5)  We have a solution for you! var myBindingProvider = { // does a node have bindings? nodeHasBindings: function(node) { }, // give me the bindings! getBindings: function(node, context) {} };
  • 32. Custom providers (6)  Use id/class for attaching bindings  Knockout.Unobtrusive plugin  Store bindings in jQuery $.data on the elements  Use more specific attributes  e.g., data-bind-text, data-bind-image, …
  • 33. Nice to read  http://www.knockoutjs.com  http://www.knockmeout.net  http://groups.google.com/group/knockoutjs
  • 35. Expect very soon: SharePoint Saturday!  Saturday, June 8, 2013  Same familiar format – 1 day filled with sessions focused on SharePoint technologies  Best SharePoint professionals in the region  Registrations will be open next week (15th)!  www.SharePointSaturday.eu
  • 36. Thanks to our Sponsors: Diamond Sponsor: Platinum Sponsors: Gold Sponsors: Swag Sponsors: Media Partners: