SlideShare a Scribd company logo
[Coscup 2012] JavascriptMVC
JavascriptMVC
JavascriptMVC
  Another javascript MVC framework
Me

                    Alive

• Mozilla Corp. Taiwan, Frontend engineer
• ~1.5 year experience on web
• https://github.com/alivedise
• email: alegnadise@gmail.com
        alive@mozilla.com
[Coscup 2012] JavascriptMVC
Mozilla is hiring!
You




• A web developer
• Use lots of jQuery plugins in your site
• Javascript newbie
• Building a complex web application
• Hate backend stuff
Developing web
application is a
   struggle.
[Coscup 2012] JavascriptMVC
BackboneJS is much more known to people.




Amazing! They have their own backboneConf!
http://backboneconf.com/
But I would love to
provide another choice
         to you
[Coscup 2012] JavascriptMVC
Successfull story: Grooveshark.com
http://javascriptmvc.com
• PROS
  o MIT license
  o Clear documentation
  o Nearly total solution to build a web
    application
• CONS
  o Less known, less resource (in Taiwan)
  o No preset UI layer implementation
Clear&models/
views/controllers&                         Na9ve&event&      View&with&
    and&class&       CRUD&Model&layer&
                                            delega9on&      Embedded&js&
   inheritance&


                          Library&
                                                              {LESS}&CSS&
     Fixture&          dependancy&        Build&process&
                                                             integra9on&
                         solu9on&


                          A&basic&
                        applica9on/
OpenAjax&pubsub&      project/product&   Model&Valida9on&   Form&Paramize&
                       management&
Class
$.Class('Monster',
{
   count: 0
},
{
   init: function( name ) {
      // saves name on the monster instance
      this.name = name;
      this.health = 10;
      this.constructor.count++;
   },
   eat: function( smallChildren ){
      this.health += smallChildren;
   },
   fight: function() {
      this.health -= 2;
   }
});

hydra = new Monster('hydra');
dragon = new Monster('dragon');

hydra.name        // -> hydra
Monster.count     // -> 2
Monster.shortName // -> 'Monster'

hydra.eat(2);     // health = 12

dragon.fight();   // health = 8
CSS collision




/* a.css */
div.data {
! background-color: red;
}
/* b.css */
div.data {
! background-color: white;
}
{LESS}

@company_blue: #0186d1;
@focus_width: 100;
div#content {
  div.title {
    background-color: @company_blue;
      &:hover,&:active {
        width: @focus_width;
    }
  }
}

steal('steal/less').then('a.less',
'b.less').then(function() {
  // ...
});
Data chaos...
$.ajax({
  url: '/cgi-bin/character?id=1',
  dataType: 'json',
  type: 'post',
  success: function() {
    $.ajax('/data/item.json',
    dataType: 'json',
     type: 'post',
    success: function() {
      // .....
    },
    error: function() {
    }
  },
  error: function() {
  }
});
$.Model


• CRUD functions, overwrittable
• Event callback whenever data is
  o   created
    o deleted
    o updated
    o and if you like, custom event on model is
      creatable.
•   DOM embeddable
    o <div <%= model %></div>
•   Validation in data model layer
Data mess solution




$.when(
  Character.findOne({id: 1}),
  Item.findAll({char_id: 1})
  .done(function(){ /*...*/ });
When you have more and more jQuery plugins..




   • None loosely coupled.
   • No cross function communication.
   • DOM renew and event rebind
     oa long long string in your javascript like

$('#div').html('<div class="event"><span
class="name"></span><span class="icon"></span><span
class="content"></span><span class="screenshot"></
span></div>');
$.Controller - Event delegation function


$.Controller("Crazy",{

  // listens to all clicks on this element
  "click" : function(el, ev){},

  // listens to all mouseovers on
  // li elements withing this controller
  "li mouseover" : function(el, ev){}

  // listens to the window being resized
  "{window} resize" : function(window, ev){}
});
$.Controller - OpenAjax Pubsub

$.Controller("Listener", {
  "something.updated subscribe" : function(called,
data){
    console.log(data.name);
  }
});

// called elsewhere
$.Controller("Renewer", {
  init: function(){
    var data = { name: 'lol' };
    this.publish("something.updated", data);
  }
});
$.View




  • Seperate HTML from your javascript codes.
  • Reusable, cachable
  • Logic (javascript) in HTML
    o http://embeddedjs.com
<ul>
<% for(var i=0; i<supplies.length; i++) {%>
<li><%= supplies[i] %></li>
<% } %>
</ul>
header...



<script src="http://ajax.googleapis.com/ajax/libs/
jquery/1.6.2/jquery.min.js"></script>
<script src="http://threedubmedia.googlecode.com/
files/jquery.event.drag-2.0.min.js"></script>
<script src="http://github.com/cowboy/jquery-resize/
raw/v1.1/jquery.ba-resize.min.js"></script>
<script src="http://remysharp.com/demo/
mousehold.js"></script>
<script src="https://raw.github.com/brandonaaron/
jquery-mousewheel/master/jquery.mousewheel.js"></
script>
StealJS




          Library dependency solution
steal('jquery').then('jquery/resize','jquery/
mousehold','jquery/event/drag').then('./
my.css', function(){
/*...*/
});
More about...fixture
•You can do nothing without server.
 Do you?
• Multi ajax request solution
Deferred model
•Since jQuery 1.5, ajax is implemented as a
 deferred object.
•Models CRUD support deferred operation.

$.fixture
o Create a deferred instead of sending
  XMLHttpRequest to the server, but to the
  function you preferred.
$.fixture("/foobar.json", function(orig, settings,
headers){
  return [200, "success", {json: {foo: "bar" } },
{} ]
});



$.ajax({
  url: "/foobar.json",
  success: function(data) {
    console.log(data.json.foo);
  }
});
Q&A




      Javascript is beautiful.
Let's use it to get the world better.

More Related Content

PDF
HTML5: where flash isn't needed anymore
PDF
Assetic (Symfony Live Paris)
PDF
iPhone Appleless Apps
PDF
DOM Scripting Toolkit - jQuery
PPTX
jQuery Best Practice
PDF
Mojolicious, real-time web framework
PDF
Introducing Assetic: Asset Management for PHP 5.3
PDF
Mojolicious: what works and what doesn't
HTML5: where flash isn't needed anymore
Assetic (Symfony Live Paris)
iPhone Appleless Apps
DOM Scripting Toolkit - jQuery
jQuery Best Practice
Mojolicious, real-time web framework
Introducing Assetic: Asset Management for PHP 5.3
Mojolicious: what works and what doesn't

What's hot (20)

KEY
jQuery: Tips, tricks and hints for better development and Performance
PDF
Web Components With Rails
PDF
Webapps without the web
PDF
Drupal, meet Assetic
PDF
JavaScript for Flex Devs
PDF
Ember background basics
PDF
Responsive Design with WordPress
PDF
HTML5 JavaScript APIs
PDF
Javascript Frameworks for Joomla
PDF
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
PDF
In-depth changes to Drupal 8 javascript
PDF
Leave No One Behind with HTML5 - FFWD.PRO, Croatia
PDF
HOW TO UPLOAD AND DISPLAY IMAGE PHP HTML SQL
KEY
Building a real life application in node js
PDF
Mojolicious. Веб в коробке!
PDF
Yearning jQuery
PDF
jQuery (DrupalCamp Toronto)
PDF
Javascript is your (Auto)mate
KEY
Sprout core and performance
PDF
jQuery (BostonPHP)
jQuery: Tips, tricks and hints for better development and Performance
Web Components With Rails
Webapps without the web
Drupal, meet Assetic
JavaScript for Flex Devs
Ember background basics
Responsive Design with WordPress
HTML5 JavaScript APIs
Javascript Frameworks for Joomla
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
In-depth changes to Drupal 8 javascript
Leave No One Behind with HTML5 - FFWD.PRO, Croatia
HOW TO UPLOAD AND DISPLAY IMAGE PHP HTML SQL
Building a real life application in node js
Mojolicious. Веб в коробке!
Yearning jQuery
jQuery (DrupalCamp Toronto)
Javascript is your (Auto)mate
Sprout core and performance
jQuery (BostonPHP)
Ad

Viewers also liked (7)

PDF
JavascriptMVC: Another choice of web framework
PDF
[COSCUP 2013] Audio Competing
PDF
FXOS Window management 101
PPT
#FirefoxOS Web App development@CID Nyári Egyetem 2013
PDF
FirefoxOS Window Management
PPTX
Firefox OS Window management 201
PDF
Study: The Future of VR, AR and Self-Driving Cars
JavascriptMVC: Another choice of web framework
[COSCUP 2013] Audio Competing
FXOS Window management 101
#FirefoxOS Web App development@CID Nyári Egyetem 2013
FirefoxOS Window Management
Firefox OS Window management 201
Study: The Future of VR, AR and Self-Driving Cars
Ad

Similar to [Coscup 2012] JavascriptMVC (20)

KEY
User Interface Development with jQuery
PPT
Eugene Andruszczenko: jQuery
PPT
jQuery Presentation - Refresh Events
PDF
Javascript Web Applications Otx Alex Maccaw
PDF
MVC pattern for widgets
KEY
Sugarcoating your frontend one ViewModel at a time
PDF
fuser interface-development-using-jquery
KEY
An in-depth look at jQuery
PPTX
JavaScript!
PPTX
Jquery fundamentals
PPTX
Planbox Backbone MVC
PDF
Building a JavaScript Library
PDF
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
PDF
jQquerysummit - Large-scale JavaScript Application Architecture
PDF
Architecting non-trivial browser applications (Jazoon 2012)
PDF
Remy Sharp The DOM scripting toolkit jQuery
PDF
Building Real-World Dojo Web Applications
PPTX
OOP and JavaScript
PPTX
JS Essence
KEY
Week 4 - jQuery + Ajax
User Interface Development with jQuery
Eugene Andruszczenko: jQuery
jQuery Presentation - Refresh Events
Javascript Web Applications Otx Alex Maccaw
MVC pattern for widgets
Sugarcoating your frontend one ViewModel at a time
fuser interface-development-using-jquery
An in-depth look at jQuery
JavaScript!
Jquery fundamentals
Planbox Backbone MVC
Building a JavaScript Library
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQquerysummit - Large-scale JavaScript Application Architecture
Architecting non-trivial browser applications (Jazoon 2012)
Remy Sharp The DOM scripting toolkit jQuery
Building Real-World Dojo Web Applications
OOP and JavaScript
JS Essence
Week 4 - jQuery + Ajax

Recently uploaded (20)

PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
cuic standard and advanced reporting.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Machine learning based COVID-19 study performance prediction
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
KodekX | Application Modernization Development
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Spectroscopy.pptx food analysis technology
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Electronic commerce courselecture one. Pdf
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Advanced IT Governance
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
NewMind AI Weekly Chronicles - August'25 Week I
Transforming Manufacturing operations through Intelligent Integrations
cuic standard and advanced reporting.pdf
Network Security Unit 5.pdf for BCA BBA.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Monthly Chronicles - July 2025
Machine learning based COVID-19 study performance prediction
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
KodekX | Application Modernization Development
MYSQL Presentation for SQL database connectivity
Spectroscopy.pptx food analysis technology
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Per capita expenditure prediction using model stacking based on satellite ima...
Electronic commerce courselecture one. Pdf
GamePlan Trading System Review: Professional Trader's Honest Take
“AI and Expert System Decision Support & Business Intelligence Systems”
Dropbox Q2 2025 Financial Results & Investor Presentation
Advanced IT Governance

[Coscup 2012] JavascriptMVC

  • 3. JavascriptMVC Another javascript MVC framework
  • 4. Me Alive • Mozilla Corp. Taiwan, Frontend engineer • ~1.5 year experience on web • https://github.com/alivedise • email: [email protected] [email protected]
  • 7. You • A web developer • Use lots of jQuery plugins in your site • Javascript newbie • Building a complex web application • Hate backend stuff
  • 10. BackboneJS is much more known to people. Amazing! They have their own backboneConf! http://backboneconf.com/
  • 11. But I would love to provide another choice to you
  • 14. http://javascriptmvc.com • PROS o MIT license o Clear documentation o Nearly total solution to build a web application • CONS o Less known, less resource (in Taiwan) o No preset UI layer implementation
  • 15. Clear&models/ views/controllers& Na9ve&event& View&with& and&class& CRUD&Model&layer& delega9on& Embedded&js& inheritance& Library& {LESS}&CSS& Fixture& dependancy& Build&process& integra9on& solu9on& A&basic& applica9on/ OpenAjax&pubsub& project/product& Model&Valida9on& Form&Paramize& management&
  • 16. Class
  • 17. $.Class('Monster', { count: 0 }, { init: function( name ) { // saves name on the monster instance this.name = name; this.health = 10; this.constructor.count++; }, eat: function( smallChildren ){ this.health += smallChildren; }, fight: function() { this.health -= 2; } }); hydra = new Monster('hydra'); dragon = new Monster('dragon'); hydra.name // -> hydra Monster.count // -> 2 Monster.shortName // -> 'Monster' hydra.eat(2); // health = 12 dragon.fight(); // health = 8
  • 18. CSS collision /* a.css */ div.data { ! background-color: red; } /* b.css */ div.data { ! background-color: white; }
  • 19. {LESS} @company_blue: #0186d1; @focus_width: 100; div#content {   div.title {     background-color: @company_blue;       &:hover,&:active {         width: @focus_width;     }   } } steal('steal/less').then('a.less', 'b.less').then(function() {   // ... });
  • 21. $.ajax({   url: '/cgi-bin/character?id=1',   dataType: 'json', type: 'post',   success: function() {     $.ajax('/data/item.json',     dataType: 'json', type: 'post',     success: function() {       // .....     },     error: function() {     }   },   error: function() {   } });
  • 22. $.Model • CRUD functions, overwrittable • Event callback whenever data is o created o deleted o updated o and if you like, custom event on model is creatable. • DOM embeddable o <div <%= model %></div> • Validation in data model layer
  • 23. Data mess solution $.when( Character.findOne({id: 1}), Item.findAll({char_id: 1}) .done(function(){ /*...*/ });
  • 24. When you have more and more jQuery plugins.. • None loosely coupled. • No cross function communication. • DOM renew and event rebind oa long long string in your javascript like $('#div').html('<div class="event"><span class="name"></span><span class="icon"></span><span class="content"></span><span class="screenshot"></ span></div>');
  • 25. $.Controller - Event delegation function $.Controller("Crazy",{ // listens to all clicks on this element "click" : function(el, ev){}, // listens to all mouseovers on // li elements withing this controller "li mouseover" : function(el, ev){} // listens to the window being resized "{window} resize" : function(window, ev){} });
  • 26. $.Controller - OpenAjax Pubsub $.Controller("Listener", {   "something.updated subscribe" : function(called, data){     console.log(data.name);   } }); // called elsewhere $.Controller("Renewer", {   init: function(){     var data = { name: 'lol' };     this.publish("something.updated", data);   } });
  • 27. $.View • Seperate HTML from your javascript codes. • Reusable, cachable • Logic (javascript) in HTML o http://embeddedjs.com <ul> <% for(var i=0; i<supplies.length; i++) {%> <li><%= supplies[i] %></li> <% } %> </ul>
  • 28. header... <script src="http://ajax.googleapis.com/ajax/libs/ jquery/1.6.2/jquery.min.js"></script> <script src="http://threedubmedia.googlecode.com/ files/jquery.event.drag-2.0.min.js"></script> <script src="http://github.com/cowboy/jquery-resize/ raw/v1.1/jquery.ba-resize.min.js"></script> <script src="http://remysharp.com/demo/ mousehold.js"></script> <script src="https://raw.github.com/brandonaaron/ jquery-mousewheel/master/jquery.mousewheel.js"></ script>
  • 29. StealJS Library dependency solution steal('jquery').then('jquery/resize','jquery/ mousehold','jquery/event/drag').then('./ my.css', function(){ /*...*/ });
  • 31. •You can do nothing without server. Do you? • Multi ajax request solution
  • 32. Deferred model •Since jQuery 1.5, ajax is implemented as a deferred object. •Models CRUD support deferred operation. $.fixture o Create a deferred instead of sending XMLHttpRequest to the server, but to the function you preferred.
  • 33. $.fixture("/foobar.json", function(orig, settings, headers){   return [200, "success", {json: {foo: "bar" } }, {} ] }); $.ajax({ url: "/foobar.json", success: function(data) { console.log(data.json.foo); } });
  • 34. Q&A Javascript is beautiful. Let's use it to get the world better.

Editor's Notes