Slide 1

Slide 1 text

KNOCKOUT.js - or - how I learned to stop hating - and - love the markup

Slide 2

Slide 2 text

@appfog console.appfog.com built with knockout @mattly matthew lyon

Slide 3

Slide 3 text

console.appfog.com

Slide 4

Slide 4 text

console.appfog.com

Slide 5

Slide 5 text

MVVM model view viewmodel a microsoft joint

Slide 6

Slide 6 text

MVP model view Presenter a martin fowler joint

Slide 7

Slide 7 text

“ viewmodel presenter MVVM is identical to Fowler’s presentation model; both feature an abstraction that contains a view’s state & behavior Josh Smith Microsoft MVP

Slide 8

Slide 8 text

{ name: “mattly”, cats: 6, hood: “king” } model

Slide 9

Slide 9 text

view

Slide 10

Slide 10 text

vm.hood = ko.observable( model.hood ); present

Slide 11

Slide 11 text

vm.cathood = ko.computed( Function (){ return cats() + “ in ” + hood(); present

Slide 12

Slide 12 text

function move(){ cats(0); hood( “buckman”); mediate

Slide 13

Slide 13 text

ko .applybindings( vm, $(‘#me’)[0] ); bind

Slide 14

Slide 14 text

it’s about the bindings

Slide 15

Slide 15 text

$(this) .find(‘.cats’) .text(int(cats)) bindings are not jquery wankery

Slide 16

Slide 16 text

ele.innerhtml = mustache( tmpl, vars); bindings are not template rendering

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

bindings are declarative

Slide 19

Slide 19 text

attr: property event: handler

Slide 20

Slide 20 text

pub/sub it’s for your markup

Slide 21

Slide 21 text

hood cats cathood

Slide 22

Slide 22 text

attributes forms events flow

Slide 23

Slide 23 text

visible text html attributes css {} style {} attr {}

Slide 24

Slide 24 text

attributes

Slide 25

Slide 25 text

value enable disable checked options selectedOptions forms

Slide 26

Slide 26 text

forms

Slide 27

Slide 27 text

click submit hasfocus event {} events

Slide 28

Slide 28 text

events

Slide 29

Slide 29 text

foreach with if ifnot flow

Slide 30

Slide 30 text

  • flow

Slide 31

Slide 31 text

  • wat

Slide 32

Slide 32 text

ko.subscribable ko.computed ko.observable ko.observablearray

Slide 33

Slide 33 text

ko.observablearray indexof slice push pop sort unshift shift reverse splice remove

Slide 34

Slide 34 text

  • ko.observablearray

Slide 35

Slide 35 text

not enough? go ahead and extend

Slide 36

Slide 36 text

jquery ui bootstrap components ko.binding handlers

Slide 37

Slide 37 text

bindinghandlers
jquery ui: slider

Slide 38

Slide 38 text

setters macros behavior ko.extenders

Slide 39

Slide 39 text

extenders ko.observable( dn).extend( validate(fqdn)

Slide 40

Slide 40 text

extenders

Slide 41

Slide 41 text

tests are easy without the dom

Slide 42

Slide 42 text

it(“has cathood”, function(){ expect( cathood()) .tomatch( /buckman/)

Slide 43

Slide 43 text

mockups with fake data are easy

Slide 44

Slide 44 text

> vm.cats(4) > cathood() “4 in king”

Slide 45

Slide 45 text

dependencies can sometimes be hard

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

integration with jquery plugins and the like is hard

Slide 48

Slide 48 text

uniform.js some bootstrap legacy jquery couldn’t use

Slide 49

Slide 49 text

want some more?

Slide 50

Slide 50 text

interactive tutorials