SlideShare a Scribd company logo
1 of 40
Download to read offline
A piece of sugar in your
client-side development
        Nicolas Blanco
        Novagile team
JavaScript ?
JavaScript ?
HTML 5
<form>
  <input type=‘text’ ... />

<input type=‘checkbox’ ... />

<input type=‘password’ ... />

 <input type=‘submit’ ... />
<form>
<form>
<form>
           <input type=‘text’ ... />

<input type=‘text’ placeholder=‘Entrez votre
                nom...’ ... />

     <input type=‘text’ autofocus ... />

      <input type=‘text’ required ... />

   <input type=‘text’ pattern=’[0-9]’ ... />
<form>
<input type=‘email’ ... />

 <input type=‘url’ ... />

<input type=‘search’ ... />
<form>

<input type=‘number’
       min=’0’
      max=’10’
    step=’2’ ... />
<form>
<input type=‘range’
      min=’0’
     max=’10’
   step=’2’ ... />
<form>
     <input type="date" ... />
       <type="month" ... />
     <input type="week" ... />
     <input type="time" ... />
   <input type="datetime" ... />
<input type="datetime-local" ... />
<form>
<form>




 flowplayer

≠ jQuery UI
<form>
jQuery Tools Form Validator

$(‘form.validator’).validator();
<form>
$(":date").dateinput();
<form>
HTML 5 new forms input
         +
   jQuery TOOLS
         =
MUST DO&HAVE!!!
    Obtrusive JavaScript ???
  <a href=’...’ onclick=‘...’ / ...>
   <form onsubmit=’...’ / ...>
                 =
MUST DO&HAVE!!!
   UNobtrusive JavaScript




   «Events» programming
MUST DO&HAVE!!!
MUST DO&HAVE!!!
MUST DO&HAVE!!!




Closure Compiler   YUI Compressor
So... JavaScript ?
CoffeeScript




« It’s just JavaScript! »
CoffeeScript
                               math = {
math =                           root: Math.sqrt,
 root: Math.sqrt                 square: square,
                                 cube: function(x) {
 square: square                    return x * square(x);
 cube: (x) -> x * square x       }
                               };

alert "I knew it!" if elvis?   if (typeof elvis != "undefined" && elvis !== null) {
                                 alert("I knew it!");
                               }
$(document).ready ->
 alert "hello world!"          $(document).ready(function() {
                                 alert("hello world!");
                               });
CoffeeScript
                        1.0
             Easy to convert JS => CS
                   «no conflict»
            Readable «compiled» code
          «compiled» code passes JSLint

                      Rails :
  automatic compilation with the Barista plugin
good architecture : CS code in the «app» directory
underscore.js




   Small < 4 kb!
underscore.js
            [1, 2, 3] => [2, 4, 6]


                      JS :

_([1, 2, 3]).map(function(n) { return n * 2; });

                     CS :

         _([1, 2, 3]).map (n) -> n * 2
underscore.js
HelloTemplate = _.template(‘<h1>Bonjour <%= first_name %> <%=
last_name %> !</h1>’)

greatRubyDev = { first_name: ‘Nicolas’, last_name: ‘Blanco’ }

HelloTemplate(greatRubyDev)


            <h1>Bonjour Nicolas Blanco !</h1>
Rich client
         Ajax
Communication with server
Rich client
backbone.js

         Small < 5 kb!
Framework & design independent
    Based on underscore.js
Book
id: 1

Book                  Book
id: 2                 View
          Library
Book
id: 3    Collection
                      Library
Book                   View
id: 4
                      Views
Models
Backbone.js
          events

Book       «change»
id: 1

                         «change»
               Library     «add»
                         «remove»
backbone.js
Work best with JSON REST API by convention

                   /books
   # => GET : retrieve collection of books
       # => POST : create new book

                 /book/3
      # => GET : retrieve book id = 3
       # => PUT : update book id = 3
     # => DELETE : destroy book id = 3
backbone.js
 Book = Backbone.Model.extend()



myBook = new Book { author: ‘Victor
   Hugo’, title: ‘Les Misérables’ }

       myBook.get(‘author’)
         myBook.set(...)
        myBook.toJSON()
backbone.js
Library = Backbone.Collection.extend
           model: Book
           url: ‘/books’

    myLibrary = new Library()
        myLibrary.fetch()
         myLibrary.at(0)
   myLibrary.each (book) -> ...
   myLibrary.map (book) -> ...
 myBook.save() // if validations pass
backbone.js
BookView = Backbone.View.extend
            tagName: ‘li’
            className: ‘book’
            template: _.template ‘<%= author %> - <%= title %>’
            initialize: ->
              _.bindAll this, ‘render’
              this.model.bind ‘change’, this.render


             render: ->
              $(this.el).html(this.template(this.model.toJSON()))
              this
backbone.js

myBookView = new BookView(model: myBook)

myBookView.render() // <li class=‘book’>Victor Hugo - Les
Misérables</li>

myBook.set { author: ‘Nicolas’ } // triggers ‘change’ event
Thank you!
     follow me on twitter :
           @slainer68

More Related Content

What's hot

Turn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modulesTurn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modulesjerryorr
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web frameworktaggg
 
iPhone Appleless Apps
iPhone Appleless AppsiPhone Appleless Apps
iPhone Appleless AppsRemy Sharp
 
Java script+mvc+with+emberjs
Java script+mvc+with+emberjsJava script+mvc+with+emberjs
Java script+mvc+with+emberjsji guang
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsJarod Ferguson
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajaxbaygross
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsMike Subelsky
 
RSpec: Feature specs as checklist
RSpec: Feature specs as checklistRSpec: Feature specs as checklist
RSpec: Feature specs as checklistEdward Fox
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hopeMarcus Ramberg
 
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1Vagmi Mudumbai
 
Keep It Simple Security (Symfony cafe 28-01-2016)
Keep It Simple Security (Symfony cafe 28-01-2016)Keep It Simple Security (Symfony cafe 28-01-2016)
Keep It Simple Security (Symfony cafe 28-01-2016)Oleg Zinchenko
 
Extracting ruby gem
Extracting ruby gemExtracting ruby gem
Extracting ruby gemYura Tolstik
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
 
Introduction to AJAX In WordPress
Introduction to AJAX In WordPressIntroduction to AJAX In WordPress
Introduction to AJAX In WordPressCaldera Labs
 
Introduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersIntroduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersCaldera Labs
 

What's hot (20)

Turn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modulesTurn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modules
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
 
Mojolicious on Steroids
Mojolicious on SteroidsMojolicious on Steroids
Mojolicious on Steroids
 
iPhone Appleless Apps
iPhone Appleless AppsiPhone Appleless Apps
iPhone Appleless Apps
 
Java script+mvc+with+emberjs
Java script+mvc+with+emberjsJava script+mvc+with+emberjs
Java script+mvc+with+emberjs
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
 
Intro to jquery
Intro to jqueryIntro to jquery
Intro to jquery
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajax
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
RSpec: Feature specs as checklist
RSpec: Feature specs as checklistRSpec: Feature specs as checklist
RSpec: Feature specs as checklist
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
 
Keep It Simple Security (Symfony cafe 28-01-2016)
Keep It Simple Security (Symfony cafe 28-01-2016)Keep It Simple Security (Symfony cafe 28-01-2016)
Keep It Simple Security (Symfony cafe 28-01-2016)
 
Oro meetup #4
Oro meetup #4Oro meetup #4
Oro meetup #4
 
Extracting ruby gem
Extracting ruby gemExtracting ruby gem
Extracting ruby gem
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
Introduction to AJAX In WordPress
Introduction to AJAX In WordPressIntroduction to AJAX In WordPress
Introduction to AJAX In WordPress
 
A Gentle Introduction to Event Loops
A Gentle Introduction to Event LoopsA Gentle Introduction to Event Loops
A Gentle Introduction to Event Loops
 
Introduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersIntroduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress Developers
 

Similar to A piece of sugar in your client-side development

Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasminePaulo Ragonha
 
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Ben Lesh
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksHjörtur Hilmarsson
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 
Rails for Beginners - Le Wagon
Rails for Beginners - Le WagonRails for Beginners - Le Wagon
Rails for Beginners - Le WagonAlex Benoit
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone InteractivityEric Steele
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Railsrstankov
 
Dirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionDirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionAdam Trachtenberg
 
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...Ben Teese
 
Kick start with j query
Kick start with j queryKick start with j query
Kick start with j queryMd. Ziaul Haq
 
Unobtrusive JavaScript
Unobtrusive JavaScriptUnobtrusive JavaScript
Unobtrusive JavaScriptVitaly Baum
 
CoffeeScript Design Patterns
CoffeeScript Design PatternsCoffeeScript Design Patterns
CoffeeScript Design PatternsTrevorBurnham
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejsNick Lee
 
CoffeeScript, An Introduction for Nodejs developers
CoffeeScript, An Introduction for Nodejs developersCoffeeScript, An Introduction for Nodejs developers
CoffeeScript, An Introduction for Nodejs developersMehdi Valikhani
 
Working with Javascript in Rails
Working with Javascript in RailsWorking with Javascript in Rails
Working with Javascript in RailsSeungkyun Nam
 

Similar to A piece of sugar in your client-side development (20)

Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & Tricks
 
XQuery Rocks
XQuery RocksXQuery Rocks
XQuery Rocks
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Not your Grandma's XQuery
Not your Grandma's XQueryNot your Grandma's XQuery
Not your Grandma's XQuery
 
Rails for Beginners - Le Wagon
Rails for Beginners - Le WagonRails for Beginners - Le Wagon
Rails for Beginners - Le Wagon
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone Interactivity
 
MVS: An angular MVC
MVS: An angular MVCMVS: An angular MVC
MVS: An angular MVC
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
Dirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionDirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP Extension
 
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
 
Kick start with j query
Kick start with j queryKick start with j query
Kick start with j query
 
Unobtrusive JavaScript
Unobtrusive JavaScriptUnobtrusive JavaScript
Unobtrusive JavaScript
 
CoffeeScript Design Patterns
CoffeeScript Design PatternsCoffeeScript Design Patterns
CoffeeScript Design Patterns
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
CoffeeScript, An Introduction for Nodejs developers
CoffeeScript, An Introduction for Nodejs developersCoffeeScript, An Introduction for Nodejs developers
CoffeeScript, An Introduction for Nodejs developers
 
Working with Javascript in Rails
Working with Javascript in RailsWorking with Javascript in Rails
Working with Javascript in Rails
 
Php introduction
Php introductionPhp introduction
Php introduction
 

A piece of sugar in your client-side development

  • 1. A piece of sugar in your client-side development Nicolas Blanco Novagile team
  • 5. <form> <input type=‘text’ ... /> <input type=‘checkbox’ ... /> <input type=‘password’ ... /> <input type=‘submit’ ... />
  • 8. <form> <input type=‘text’ ... /> <input type=‘text’ placeholder=‘Entrez votre nom...’ ... /> <input type=‘text’ autofocus ... /> <input type=‘text’ required ... /> <input type=‘text’ pattern=’[0-9]’ ... />
  • 9. <form> <input type=‘email’ ... /> <input type=‘url’ ... /> <input type=‘search’ ... />
  • 10. <form> <input type=‘number’ min=’0’ max=’10’ step=’2’ ... />
  • 11. <form> <input type=‘range’ min=’0’ max=’10’ step=’2’ ... />
  • 12. <form> <input type="date" ... /> <type="month" ... /> <input type="week" ... /> <input type="time" ... /> <input type="datetime" ... /> <input type="datetime-local" ... />
  • 15. <form> jQuery Tools Form Validator $(‘form.validator’).validator();
  • 17. <form> HTML 5 new forms input + jQuery TOOLS =
  • 18. MUST DO&HAVE!!! Obtrusive JavaScript ??? <a href=’...’ onclick=‘...’ / ...> <form onsubmit=’...’ / ...> =
  • 19. MUST DO&HAVE!!! UNobtrusive JavaScript «Events» programming
  • 24. CoffeeScript « It’s just JavaScript! »
  • 25. CoffeeScript math = { math = root: Math.sqrt, root: Math.sqrt square: square, cube: function(x) { square: square return x * square(x); cube: (x) -> x * square x } }; alert "I knew it!" if elvis? if (typeof elvis != "undefined" && elvis !== null) { alert("I knew it!"); } $(document).ready -> alert "hello world!" $(document).ready(function() { alert("hello world!"); });
  • 26. CoffeeScript 1.0 Easy to convert JS => CS «no conflict» Readable «compiled» code «compiled» code passes JSLint Rails : automatic compilation with the Barista plugin good architecture : CS code in the «app» directory
  • 27. underscore.js Small < 4 kb!
  • 28. underscore.js [1, 2, 3] => [2, 4, 6] JS : _([1, 2, 3]).map(function(n) { return n * 2; }); CS : _([1, 2, 3]).map (n) -> n * 2
  • 29. underscore.js HelloTemplate = _.template(‘<h1>Bonjour <%= first_name %> <%= last_name %> !</h1>’) greatRubyDev = { first_name: ‘Nicolas’, last_name: ‘Blanco’ } HelloTemplate(greatRubyDev) <h1>Bonjour Nicolas Blanco !</h1>
  • 30. Rich client Ajax Communication with server
  • 32. backbone.js Small < 5 kb! Framework & design independent Based on underscore.js
  • 33. Book id: 1 Book Book id: 2 View Library Book id: 3 Collection Library Book View id: 4 Views Models
  • 34. Backbone.js events Book «change» id: 1 «change» Library «add» «remove»
  • 35. backbone.js Work best with JSON REST API by convention /books # => GET : retrieve collection of books # => POST : create new book /book/3 # => GET : retrieve book id = 3 # => PUT : update book id = 3 # => DELETE : destroy book id = 3
  • 36. backbone.js Book = Backbone.Model.extend() myBook = new Book { author: ‘Victor Hugo’, title: ‘Les Misérables’ } myBook.get(‘author’) myBook.set(...) myBook.toJSON()
  • 37. backbone.js Library = Backbone.Collection.extend model: Book url: ‘/books’ myLibrary = new Library() myLibrary.fetch() myLibrary.at(0) myLibrary.each (book) -> ... myLibrary.map (book) -> ... myBook.save() // if validations pass
  • 38. backbone.js BookView = Backbone.View.extend tagName: ‘li’ className: ‘book’ template: _.template ‘<%= author %> - <%= title %>’ initialize: -> _.bindAll this, ‘render’ this.model.bind ‘change’, this.render render: -> $(this.el).html(this.template(this.model.toJSON())) this
  • 39. backbone.js myBookView = new BookView(model: myBook) myBookView.render() // <li class=‘book’>Victor Hugo - Les Misérables</li> myBook.set { author: ‘Nicolas’ } // triggers ‘change’ event
  • 40. Thank you! follow me on twitter : @slainer68