SlideShare a Scribd company logo
1 of 30
Javascript MV*
 frameworks
  Kerry Buckley, FE Suffolk 27/8/12
MV*
Features
Client-server model
synchronisation
Event
handling
View templates
URL
routing
UI element
binding
che ibili ||b,n. nlineB HTML=" lay="" h="0" emoveC null;r place
 ild. {vis                       i                                 t        r
                 ,n=m m=1,k. a.inner le.disp yle.wid ="",n. =j=a=i m()).r ;ret
                                                                                      =           e
        =      )
 "),p hild(a e.zoo         = 2), 0].sty ),j.st erHTML =g=h=m h.rando pando] f((
 p endC a.styl Width!= =0,q[ "div"                 o .inn ]=u;o=l ry+Mat :a[f.e pando; [l
                                                                                          x          i
 li  ne", offset ight== ement( )===0), bles"                      jque pando]] ]&&f.ex on")e?k ?i
        =a. fsetHe eateEl 0)||0 +"Bub +(f.fn. .ex
 ocks ].of            r        , 1         [ t        "          [ f       p ando "functi eturn h c
       0
    q[ e&&(j   =c.c nRight on"),k "jQuery cache[a :a[f.ex c==                           ts;r urn;if( h
u= yl            argi "functi pando: ype?f. pando] |typeo g].eve )ret
                                                                            f         n




                Show me
 e dSt :0}).m ]==                x            T         x         |          [         ]          h [i]:
        h t     [ s     d :0,e =a.node j?a[f.e object" i[g]&&i if(!h[i elete ):b[
 nRig ypeof a {},uui a){a               a ,l= f c==" eturn pando; |h!=a?d expando ret
),  u=t cache: ction( cache: ypeo                   c])r o]:f.ex xpando| bute(f. )];if(b is[
                                                                                                     )
     nd({ ata:fun ,k=j?f. ));if(t s"&&!i[ pand                                                       h
xte asD            e         p           t         x          l eteE veAttri erCase( data(t ,d[
    ,h nodeTyp N=f.noo =="even g?b[f.e port.de remo
 0} a.                                                                                    .
                                                                           oLow h){d=f is[0],g hi
       =       JSO ;if(c= e:b,i= ;f.sup bute?b. eName.t engt
, i,j [l].to =d)              h            ]         i         d         . l        , k(th =b){d=t ?
      (k e(c)] g?f.cac =h[i][e oveAttr ta[a.no f(this ng(5)) (c==
   || as                                                                                           j[1]
 j       C       ,h= }var k :b.rem f.noDa ed"){i substri :"";if d===b&& eDat
c amel odeType turn        n do] var b= ndefin ase(g. ."+j[1] eturn                           hang c,b
   =b.n [i]))re [f.expa ame){                                                           r("c a(a,




                the code!
                                              "u
                                         a== .came =j   lC [1]?"             ;r       e
 g       h       b        N           f                              a ,d)) rHandl f.dat ),m(c
  (!l( delete (a.node (typeo &&(g=f );j[1] is[0], igge                                (           0
f       ?       f       i f           0          "        t h        t r         a,c, a(c,e,! (d));
 ando on(a){i =null; a-")=== plit(". ),d=k( ,c),b. f.data( eDat                              push d.ca
                d                                a         a         ,
u ncti ){var Of("dat r j=a.s is[0], a(this, "mark" f.remov ,!0):e. s"),
     a,c index });va ata(th f.dat "fx")+ !0):( ay(d) rogres );if(c=
on( ,g.                                                        ,         r
       e       s,a) (d=f.d "!",d), c=(c|| (c,e,g makeAr t("inp a="fx" turn
.nam ata(thi th&&                           (         a         .          f
                         [1]+ c){a&& ?f.dat (a,c,f c.unshi "&&(c=a n(a){r ){f.d
                                                                                     ,           e
               g
 {f.d is.len Data"+j n(a,              - 1;g f.data fx"&& tring unctio ction( a||
 b &&th r("set functio !0)||1) d)?e=               b ===" f a!="s queue:f ut(fun a=b),a= [g]
 Ha ndle _mark: c,e,b, Array( )),d&&( typeo                                    o
                                                                },de etTime &&(c=a, .data(e (?
                                                              )
      nd({ f.data( e||f.is shift( (a,c){ is,a)} is;s
 xte 0:(                                                                   ing" !0))&&f i,s=/^a :f
                              .            n        h           h        r
       ?      &&(! &&(d=c unctio ueue(t var c=t a!="st k,b,                                /          r
,g=a b,!0);d ess"              f           q        {                     ,         ea)$ nd({att th
              r         eue: "&&f.de tion() }typeof ta(e[g] |textar xte
      ,
a,c inprog nd({qu ess                      c        )          a         t         . e         c ess( va
      =" .exte progr               b ,fun (e,[e] )||f.d |selec w;f.fn n f.ac (a){
d== .fn                     eue( With            b,!0
                "i  n   qu                                 ject       /,v,      etur        tion       (o
Models

window.Todo = Backbone.Model.extend({
  idAttribute: "_id",

  defaults: function() {
     return {
        done: false,
        order: Todos.nextOrder()
     };
  },

  toggle: function() {
    this.save({done: !this.get("done")});
  }
});
Collections

window.TodoList = Backbone.Collection.extend({
  model: Todo,
  url: '/api/todos',

  done: function() {
     return this.filter(function(todo){
       return todo.get('done');
     });
  },

  remaining: function() {
    return this.without.apply(this, this.done());
  }
});
Client-server sync
get '/api/:thing' do
  DB.collection(params[:thing]).find.to_a.map{|t| from_bson_id(t)}.to_json
end

get '/api/:thing/:id' do
  from_bson_id(DB.collection(params[:thing]).find_one(to_bson_id(params[:id]))).to_json
end

post '/api/:thing' do
  oid = DB.collection(params[:thing]).insert(JSON.parse(request.body.read.to_s))
  "{"_id": "#{oid.to_s}"}"
end

delete '/api/:thing/:id' do
  DB.collection(params[:thing]).remove('_id' => to_bson_id(params[:id]))
end

put '/api/:thing/:id' do
  DB.collection(params[:thing]).update({'_id' => to_bson_id(params[:id])},
    {'$set' => JSON.parse(request.body.read.to_s).reject{|k,v| k == '_id'}})
end

def to_bson_id(id) BSON::ObjectId.from_string(id) end
def from_bson_id(obj) obj.merge({'_id' => obj['_id'].to_s}) end
Views & events
window.TodoView = Backbone.View.extend({
  tagName: "li",
  template: _.template($('#item-template').html()),
  events: {
     "click .check"             : "toggleDone",
     "dblclick div.todo-text"   : "edit",
     "click span.todo-destroy"  : "clear",
     "keypress .todo-input"     : "updateOnEnter"
  },

 initialize: function() {
    this.model.bind('change', this.render, this);
    this.model.bind('destroy', this.remove, this);
 },

 render: function() {
    $(this.el).html(this.template(this.model.toJSON()));
    this.setText();
    return this;
 },

 toggleDone: function() {
    this.model.toggle();
 },

 edit: function() {
    $(this.el).addClass("editing");
    this.input.focus();
 },

  // ...
});
View templates

<script id="item-template" type="text/template">
  <div class="todo <%= done ? 'done' : '' %>">
  <div class="display">
    <input class="check" type="checkbox" <%= done ? 'checked="checked"' : '' %> />
    <div class="todo-text"></div>
    <span id="todo-destroy"></span>
  </div>
  <div class="edit">
    <input class="todo-input" type="text" value="" />
  </div>
  </div>
</script>
URL routing
var Workspace = Backbone.Router.extend({
  routes: {
     "help":                 "help",   // #help
     "search/:query":        "search", // #search/kiwis
     "search/:query/p:page": "search"  // #search/kiwis/p7
  },

  help: function() {
     ...
  },

  search: function(query, page) {
    ...
  }
});
UI element binding
UI element binding

<form action="#">
  New item:

  <input />

  <button type="submit">Add</button>

  <p>Your items:</p>

  <select multiple="multiple">
  </select>
</form>
UI element binding

<form action="#" data-bind="submit: addItem">
  New item:

  <input data-bind='value: itemToAdd, valueUpdate: "afterkeydown"' />

  <button type="submit"
    data-bind="enable: itemToAdd().length > 0">Add</button>

  <p>Your items:</p>

  <select multiple="multiple" data-bind="options: items">
  </select>
</form>
UI element binding

var SimpleListModel = function(items) {
    this.items = ko.observableArray(items);

     this.itemToAdd = ko.observable("");

     this.addItem = function() {
         if (this.itemToAdd() !== "") {
             this.items.push(this.itemToAdd());
             this.itemToAdd("");
         }
     }.bind(this);
};

ko.applyBindings(new SimpleListModel(["Alpha", "Beta", "Gamma"]));
Any
questions
Image credits
•   http://geekswithblogs.net/dlussier/archive/2009/11/21/136454.aspx

•   http://www.flickr.com/photos/anhonorablegerman/6133053209

•   http://www.flickr.com/photos/ksayer/5614813544

•   http://www.flickr.com/photos/camafghanistancam/4905314342

•   http://www.flickr.com/photos/duncan/4222224278

•   http://www.flickr.com/photos/scissorhands33/3430164569

•   http://www.flickr.com/photos/patlet/53104695

•   http://www.flickr.com/photos/omcoc/6751047205

More Related Content

What's hot

Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeStripe
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeMongoDB
 
Using a mobile phone as a therapist - Superweek 2018
Using a mobile phone as a therapist - Superweek 2018Using a mobile phone as a therapist - Superweek 2018
Using a mobile phone as a therapist - Superweek 2018Peter Meyer
 
WordPressでIoTをはじめよう
WordPressでIoTをはじめようWordPressでIoTをはじめよう
WordPressでIoTをはじめようYuriko IKEDA
 
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 AutumnGoptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 AutumnMasashi Shibata
 
Jscex: Write Sexy JavaScript (中文)
Jscex: Write Sexy JavaScript (中文)Jscex: Write Sexy JavaScript (中文)
Jscex: Write Sexy JavaScript (中文)jeffz
 
MongoDB全機能解説2
MongoDB全機能解説2MongoDB全機能解説2
MongoDB全機能解説2Takahiro Inoue
 
MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤Takahiro Inoue
 
Get started with YUI
Get started with YUIGet started with YUI
Get started with YUIAdam Lu
 
Webinar: What's New in Aggregation
Webinar: What's New in AggregationWebinar: What's New in Aggregation
Webinar: What's New in AggregationMongoDB
 
Groovy collection api
Groovy collection apiGroovy collection api
Groovy collection apitrygvea
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScriptniklal
 
The Ring programming language version 1.8 book - Part 65 of 202
The Ring programming language version 1.8 book - Part 65 of 202The Ring programming language version 1.8 book - Part 65 of 202
The Ring programming language version 1.8 book - Part 65 of 202Mahmoud Samir Fayed
 
ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions Dr. Volkan OBAN
 
The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202Mahmoud Samir Fayed
 

What's hot (20)

Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
 
Using a mobile phone as a therapist - Superweek 2018
Using a mobile phone as a therapist - Superweek 2018Using a mobile phone as a therapist - Superweek 2018
Using a mobile phone as a therapist - Superweek 2018
 
WordPressでIoTをはじめよう
WordPressでIoTをはじめようWordPressでIoTをはじめよう
WordPressでIoTをはじめよう
 
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 AutumnGoptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
 
Jscex: Write Sexy JavaScript (中文)
Jscex: Write Sexy JavaScript (中文)Jscex: Write Sexy JavaScript (中文)
Jscex: Write Sexy JavaScript (中文)
 
MongoDB全機能解説2
MongoDB全機能解説2MongoDB全機能解説2
MongoDB全機能解説2
 
MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Get started with YUI
Get started with YUIGet started with YUI
Get started with YUI
 
teste
testeteste
teste
 
Webinar: What's New in Aggregation
Webinar: What's New in AggregationWebinar: What's New in Aggregation
Webinar: What's New in Aggregation
 
Oh Composable World!
Oh Composable World!Oh Composable World!
Oh Composable World!
 
Groovy collection api
Groovy collection apiGroovy collection api
Groovy collection api
 
Millionways
MillionwaysMillionways
Millionways
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
 
The Ring programming language version 1.8 book - Part 65 of 202
The Ring programming language version 1.8 book - Part 65 of 202The Ring programming language version 1.8 book - Part 65 of 202
The Ring programming language version 1.8 book - Part 65 of 202
 
ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions
 
The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196The Ring programming language version 1.7 book - Part 73 of 196
The Ring programming language version 1.7 book - Part 73 of 196
 
The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.8 book - Part 75 of 202
 

Viewers also liked

Testing http calls with Webmock and VCR
Testing http calls with Webmock and VCRTesting http calls with Webmock and VCR
Testing http calls with Webmock and VCRKerry Buckley
 
Adastral Park code retreat introduction
Adastral Park code retreat introductionAdastral Park code retreat introduction
Adastral Park code retreat introductionKerry Buckley
 
Single Responsibility Principle @ Clean Code Alliance Meetup
Single Responsibility Principle @ Clean Code Alliance MeetupSingle Responsibility Principle @ Clean Code Alliance Meetup
Single Responsibility Principle @ Clean Code Alliance MeetupEyal Golan
 

Viewers also liked (7)

TDD refresher
TDD refresherTDD refresher
TDD refresher
 
BDD with cucumber
BDD with cucumberBDD with cucumber
BDD with cucumber
 
7li7w devcon5
7li7w devcon57li7w devcon5
7li7w devcon5
 
Testing http calls with Webmock and VCR
Testing http calls with Webmock and VCRTesting http calls with Webmock and VCR
Testing http calls with Webmock and VCR
 
Adastral Park code retreat introduction
Adastral Park code retreat introductionAdastral Park code retreat introduction
Adastral Park code retreat introduction
 
Jasmine
JasmineJasmine
Jasmine
 
Single Responsibility Principle @ Clean Code Alliance Meetup
Single Responsibility Principle @ Clean Code Alliance MeetupSingle Responsibility Principle @ Clean Code Alliance Meetup
Single Responsibility Principle @ Clean Code Alliance Meetup
 

Similar to Javasccript MV* frameworks

Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For GoogleEleanor McHugh
 
C Code and the Art of Obfuscation
C Code and the Art of ObfuscationC Code and the Art of Obfuscation
C Code and the Art of Obfuscationguest9006ab
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programmingLukasz Dynowski
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Er Ritu Aggarwal
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meetMario Fusco
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab filesNitesh Dubey
 
Cbgapi 002
Cbgapi 002Cbgapi 002
Cbgapi 002kmilo1_7
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」Ken'ichi Matsui
 
C tech questions
C tech questionsC tech questions
C tech questionsvijay00791
 
Artificial intelligence
Artificial intelligenceArtificial intelligence
Artificial intelligenceAditya Sharma
 

Similar to Javasccript MV* frameworks (20)

ADA FILE
ADA FILEADA FILE
ADA FILE
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For Google
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
 
C Code and the Art of Obfuscation
C Code and the Art of ObfuscationC Code and the Art of Obfuscation
C Code and the Art of Obfuscation
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programming
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
F(1)
F(1)F(1)
F(1)
 
TRICK
TRICKTRICK
TRICK
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
 
C programs
C programsC programs
C programs
 
Python
PythonPython
Python
 
Scala best practices
Scala best practicesScala best practices
Scala best practices
 
Cbgapi 002
Cbgapi 002Cbgapi 002
Cbgapi 002
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
 
C++ programs
C++ programsC++ programs
C++ programs
 
C tech questions
C tech questionsC tech questions
C tech questions
 
Artificial intelligence
Artificial intelligenceArtificial intelligence
Artificial intelligence
 

More from Kerry Buckley

Ruby nooks & crannies
Ruby nooks & cranniesRuby nooks & crannies
Ruby nooks & cranniesKerry Buckley
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test communityKerry Buckley
 
What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)Kerry Buckley
 
MongoMapper lightning talk
MongoMapper lightning talkMongoMapper lightning talk
MongoMapper lightning talkKerry Buckley
 
The secret life of bees
The secret life of beesThe secret life of bees
The secret life of beesKerry Buckley
 
Background processing
Background processingBackground processing
Background processingKerry Buckley
 
Katas, Contests and Coding Dojos
Katas, Contests and Coding DojosKatas, Contests and Coding Dojos
Katas, Contests and Coding DojosKerry Buckley
 
Kanban and Iterationless Working
Kanban and Iterationless WorkingKanban and Iterationless Working
Kanban and Iterationless WorkingKerry Buckley
 
Software Development Trends
Software Development TrendsSoftware Development Trends
Software Development TrendsKerry Buckley
 
Kanban and Iterationless Working
Kanban and Iterationless WorkingKanban and Iterationless Working
Kanban and Iterationless WorkingKerry Buckley
 
Behaviour-Driven Development
Behaviour-Driven DevelopmentBehaviour-Driven Development
Behaviour-Driven DevelopmentKerry Buckley
 
REST: putting the web back in to web services
REST: putting the web back in to web servicesREST: putting the web back in to web services
REST: putting the web back in to web servicesKerry Buckley
 

More from Kerry Buckley (20)

Ruby nooks & crannies
Ruby nooks & cranniesRuby nooks & crannies
Ruby nooks & crannies
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test community
 
What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)
 
Functional ruby
Functional rubyFunctional ruby
Functional ruby
 
MongoMapper lightning talk
MongoMapper lightning talkMongoMapper lightning talk
MongoMapper lightning talk
 
Ruby
RubyRuby
Ruby
 
Cloud
CloudCloud
Cloud
 
The secret life of bees
The secret life of beesThe secret life of bees
The secret life of bees
 
Background processing
Background processingBackground processing
Background processing
 
Katas, Contests and Coding Dojos
Katas, Contests and Coding DojosKatas, Contests and Coding Dojos
Katas, Contests and Coding Dojos
 
Rack
RackRack
Rack
 
Doing REST Right
Doing REST RightDoing REST Right
Doing REST Right
 
Kanban and Iterationless Working
Kanban and Iterationless WorkingKanban and Iterationless Working
Kanban and Iterationless Working
 
Software Development Trends
Software Development TrendsSoftware Development Trends
Software Development Trends
 
TDD
TDDTDD
TDD
 
Kanban and Iterationless Working
Kanban and Iterationless WorkingKanban and Iterationless Working
Kanban and Iterationless Working
 
TDD, BDD and mocks
TDD, BDD and mocksTDD, BDD and mocks
TDD, BDD and mocks
 
Behaviour-Driven Development
Behaviour-Driven DevelopmentBehaviour-Driven Development
Behaviour-Driven Development
 
REST: putting the web back in to web services
REST: putting the web back in to web servicesREST: putting the web back in to web services
REST: putting the web back in to web services
 
Git
GitGit
Git
 

Recently uploaded

Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfalexjohnson7307
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Skynet Technologies
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...FIDO Alliance
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfFIDO Alliance
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch TuesdayIvanti
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxFIDO Alliance
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTopCSSGallery
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxFIDO Alliance
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...FIDO Alliance
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxFIDO Alliance
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfFIDO Alliance
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfFIDO Alliance
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe中 央社
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuidePixlogix Infotech
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewDianaGray10
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingScyllaDB
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfFIDO Alliance
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...FIDO Alliance
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Hiroshi SHIBATA
 

Recently uploaded (20)

Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 

Javasccript MV* frameworks

  • 1. Javascript MV* frameworks Kerry Buckley, FE Suffolk 27/8/12
  • 2.
  • 3.
  • 4. MV*
  • 5.
  • 6.
  • 13. che ibili ||b,n. nlineB HTML=" lay="" h="0" emoveC null;r place ild. {vis i t r ,n=m m=1,k. a.inner le.disp yle.wid ="",n. =j=a=i m()).r ;ret = e = ) "),p hild(a e.zoo = 2), 0].sty ),j.st erHTML =g=h=m h.rando pando] f(( p endC a.styl Width!= =0,q[ "div" o .inn ]=u;o=l ry+Mat :a[f.e pando; [l x i li ne", offset ight== ement( )===0), bles" jque pando]] ]&&f.ex on")e?k ?i =a. fsetHe eateEl 0)||0 +"Bub +(f.fn. .ex ocks ].of r , 1 [ t " [ f p ando "functi eturn h c 0 q[ e&&(j =c.c nRight on"),k "jQuery cache[a :a[f.ex c== ts;r urn;if( h u= yl argi "functi pando: ype?f. pando] |typeo g].eve )ret f n Show me e dSt :0}).m ]== x T x | [ ] h [i]: h t [ s d :0,e =a.node j?a[f.e object" i[g]&&i if(!h[i elete ):b[ nRig ypeof a {},uui a){a a ,l= f c==" eturn pando; |h!=a?d expando ret ), u=t cache: ction( cache: ypeo c])r o]:f.ex xpando| bute(f. )];if(b is[ ) nd({ ata:fun ,k=j?f. ));if(t s"&&!i[ pand h xte asD e p t x l eteE veAttri erCase( data(t ,d[ ,h nodeTyp N=f.noo =="even g?b[f.e port.de remo 0} a. . oLow h){d=f is[0],g hi = JSO ;if(c= e:b,i= ;f.sup bute?b. eName.t engt , i,j [l].to =d) h ] i d . l , k(th =b){d=t ? (k e(c)] g?f.cac =h[i][e oveAttr ta[a.no f(this ng(5)) (c== || as j[1] j C ,h= }var k :b.rem f.noDa ed"){i substri :"";if d===b&& eDat c amel odeType turn n do] var b= ndefin ase(g. ."+j[1] eturn hang c,b =b.n [i]))re [f.expa ame){ r("c a(a, the code! "u a== .came =j lC [1]?" ;r e g h b N f a ,d)) rHandl f.dat ),m(c (!l( delete (a.node (typeo &&(g=f );j[1] is[0], igge ( 0 f ? f i f 0 " t h t r a,c, a(c,e,! (d)); ando on(a){i =null; a-")=== plit(". ),d=k( ,c),b. f.data( eDat push d.ca d a a , u ncti ){var Of("dat r j=a.s is[0], a(this, "mark" f.remov ,!0):e. s"), a,c index });va ata(th f.dat "fx")+ !0):( ay(d) rogres );if(c= on( ,g. , r e s,a) (d=f.d "!",d), c=(c|| (c,e,g makeAr t("inp a="fx" turn .nam ata(thi th&& ( a . f [1]+ c){a&& ?f.dat (a,c,f c.unshi "&&(c=a n(a){r ){f.d , e g {f.d is.len Data"+j n(a, - 1;g f.data fx"&& tring unctio ction( a|| b &&th r("set functio !0)||1) d)?e= b ===" f a!="s queue:f ut(fun a=b),a= [g] Ha ndle _mark: c,e,b, Array( )),d&&( typeo o },de etTime &&(c=a, .data(e (? ) nd({ f.data( e||f.is shift( (a,c){ is,a)} is;s xte 0:( ing" !0))&&f i,s=/^a :f . n h h r ? &&(! &&(d=c unctio ueue(t var c=t a!="st k,b, / r ,g=a b,!0);d ess" f q { , ea)$ nd({att th r eue: "&&f.de tion() }typeof ta(e[g] |textar xte , a,c inprog nd({qu ess c ) a t . e c ess( va =" .exte progr b ,fun (e,[e] )||f.d |selec w;f.fn n f.ac (a){ d== .fn eue( With b,!0 "i n qu ject /,v, etur tion (o
  • 14.
  • 15.
  • 16.
  • 17.
  • 18. Models window.Todo = Backbone.Model.extend({ idAttribute: "_id", defaults: function() { return { done: false, order: Todos.nextOrder() }; }, toggle: function() { this.save({done: !this.get("done")}); } });
  • 19. Collections window.TodoList = Backbone.Collection.extend({ model: Todo, url: '/api/todos', done: function() { return this.filter(function(todo){ return todo.get('done'); }); }, remaining: function() { return this.without.apply(this, this.done()); } });
  • 20. Client-server sync get '/api/:thing' do DB.collection(params[:thing]).find.to_a.map{|t| from_bson_id(t)}.to_json end get '/api/:thing/:id' do from_bson_id(DB.collection(params[:thing]).find_one(to_bson_id(params[:id]))).to_json end post '/api/:thing' do oid = DB.collection(params[:thing]).insert(JSON.parse(request.body.read.to_s)) "{"_id": "#{oid.to_s}"}" end delete '/api/:thing/:id' do DB.collection(params[:thing]).remove('_id' => to_bson_id(params[:id])) end put '/api/:thing/:id' do DB.collection(params[:thing]).update({'_id' => to_bson_id(params[:id])}, {'$set' => JSON.parse(request.body.read.to_s).reject{|k,v| k == '_id'}}) end def to_bson_id(id) BSON::ObjectId.from_string(id) end def from_bson_id(obj) obj.merge({'_id' => obj['_id'].to_s}) end
  • 21. Views & events window.TodoView = Backbone.View.extend({ tagName: "li", template: _.template($('#item-template').html()), events: { "click .check" : "toggleDone", "dblclick div.todo-text" : "edit", "click span.todo-destroy" : "clear", "keypress .todo-input" : "updateOnEnter" }, initialize: function() { this.model.bind('change', this.render, this); this.model.bind('destroy', this.remove, this); }, render: function() { $(this.el).html(this.template(this.model.toJSON())); this.setText(); return this; }, toggleDone: function() { this.model.toggle(); }, edit: function() { $(this.el).addClass("editing"); this.input.focus(); }, // ... });
  • 22. View templates <script id="item-template" type="text/template"> <div class="todo <%= done ? 'done' : '' %>"> <div class="display"> <input class="check" type="checkbox" <%= done ? 'checked="checked"' : '' %> /> <div class="todo-text"></div> <span id="todo-destroy"></span> </div> <div class="edit"> <input class="todo-input" type="text" value="" /> </div> </div> </script>
  • 23. URL routing var Workspace = Backbone.Router.extend({ routes: { "help": "help", // #help "search/:query": "search", // #search/kiwis "search/:query/p:page": "search" // #search/kiwis/p7 }, help: function() { ... }, search: function(query, page) { ... } });
  • 24.
  • 26. UI element binding <form action="#"> New item: <input /> <button type="submit">Add</button> <p>Your items:</p> <select multiple="multiple"> </select> </form>
  • 27. UI element binding <form action="#" data-bind="submit: addItem"> New item: <input data-bind='value: itemToAdd, valueUpdate: "afterkeydown"' /> <button type="submit" data-bind="enable: itemToAdd().length > 0">Add</button> <p>Your items:</p> <select multiple="multiple" data-bind="options: items"> </select> </form>
  • 28. UI element binding var SimpleListModel = function(items) { this.items = ko.observableArray(items); this.itemToAdd = ko.observable(""); this.addItem = function() { if (this.itemToAdd() !== "") { this.items.push(this.itemToAdd()); this.itemToAdd(""); } }.bind(this); }; ko.applyBindings(new SimpleListModel(["Alpha", "Beta", "Gamma"]));
  • 30. Image credits • http://geekswithblogs.net/dlussier/archive/2009/11/21/136454.aspx • http://www.flickr.com/photos/anhonorablegerman/6133053209 • http://www.flickr.com/photos/ksayer/5614813544 • http://www.flickr.com/photos/camafghanistancam/4905314342 • http://www.flickr.com/photos/duncan/4222224278 • http://www.flickr.com/photos/scissorhands33/3430164569 • http://www.flickr.com/photos/patlet/53104695 • http://www.flickr.com/photos/omcoc/6751047205

Editor's Notes

  1. \n
  2. Some expectation-setting: this is a master.\n
  3. This is me.\n
  4. C might be controller or collection.\nMore similar than they are different\n
  5. Rich or single page web apps. Just JQuery can become messy.\nTight coupling between app and DOM is bad.\n
  6. \n
  7. \n
  8. \n
  9. Associate page events with actions on your models\n
  10. HTML views for each page element. Bind to attributes\n
  11. Allows bookmarking (hashbangs or history API)\n
  12. Automatic updating of elements on page when model changes, and vice versa.\n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. Sinatra app (Rails would be simpler). Methods on model and collection automatically make AJAX calls.\n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n