JavascriptMVC: Another choice of web framework
-
Upload
alive-kuo -
Category
Technology
-
view
3.059 -
download
1
description
Transcript of JavascriptMVC: Another choice of web framework
![Page 1: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/1.jpg)
JavascriptMVCAnother choose of web framework
Alive C. Kuo
![Page 2: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/2.jpg)
About me
● 2010.01.04 ~ 2012.05.31 VIVOTEK Inc.,software engineer
● 2012.06.01 ~ *Mozilla Corp.,Front end enigeer
● ~1.5year web application experience● email: [email protected]
![Page 3: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/3.jpg)
Life is a struggle
● Web application is hard to design and implement
● Framework○ Client side
■ YUI■ extjs■ backbone■ knockout■ ...
○ Server side■ zk■ RoR■ shtml■ ...
![Page 4: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/4.jpg)
jQuery
● It is a library, not a framework.● High performance to DOM scripting● Easy to use with method chain● http://jquery.com● But, there's something we need it lacks..
![Page 5: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/5.jpg)
What jQuery lack
● Cross plugin communication● Ajax gateway● Web application management● js/css/html files/directories management● jQuery,
will not teach you how to org your (huge) web application.
![Page 6: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/6.jpg)
Life is a struggle (CONT.)
● Just survey it.○ Work hard every day.
![Page 7: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/7.jpg)
ExtJS
● http://www.sencha.com/products/extjs/● The initial version is forked from YUI2.● PROS
○ Beautiful and uniform and windows-like UI styles● CONS
○ Customization is hard to do.○ NO MIT. It is a commercial product.
![Page 8: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/8.jpg)
YUI
● http://developer.yahoo.com/yui/● PROS
○ uniform UI styles○ YQuery is suitable for cross-domain query.○ Many F2E in Yahoo! will maintain it.
● CONS○ Also customization.
![Page 9: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/9.jpg)
backbone.js
● http://documentcloud.github.com/backbone/● A MVC framework known to Mobile● PROS
○ Resource more than javascripMVC!● CONS
○ Just MVC layer. NO preset UI layer implementation○ Documentation seems difficult to understand.
![Page 10: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/10.jpg)
javascriptMVC
● http://javascriptmvc.com● PROS
○ MIT license○ Clear documentation○ Nearly total solution to build a web application
● CONS○ Less resource in Taiwan○ No preset UI layer implementation
![Page 11: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/11.jpg)
Successful story
![Page 12: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/12.jpg)
Why I choose javascriptMVC finally?
● clientside MVC - Meet my requirement on embedded system.
● I just couldn't figure out backbone's documentation and example.
![Page 13: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/13.jpg)
Life is a struggle. (CONT.)
● But, I still spend serveral days to read whole of its document and its forum.
● Try to understand why and how.
![Page 14: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/14.jpg)
Nice features in javascriptMVC
● Clear models/views/controllers and class inheritance
● CRUD Model layer● Native event delegation● View with Embedded js● Fixture● Library dependancy solution● Build process● Less CSS integration● OpenAjax pubsub● A basic application/project/product
management
![Page 15: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/15.jpg)
Struggle and the Way
Case By Case
![Page 16: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/16.jpg)
CSS Struggles - Collision
● a.cssdiv.data {
background-color: red;}
● b.cssdiv.data {
background-color: white;}
![Page 17: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/17.jpg)
CSS struggles - One Level Statement/Rule Weight
● div.viewcell > div.plugin span.title span {}● CSS rule has weights.● CSS solutions:
○ SASS○ Compass○ LessCSS
![Page 18: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/18.jpg)
CSS Super Language
● SASS/Compass○ Mixin, Variable, Sprite helper, Functions, CSS3
Helpers○ jsfiddle(http://jsfiddle.net) supports SASS!
● LESS○ http://lesscss.org○ Javascript evaluable○ Less feature than SASS○ Both server side(Rhino or Node.js) & client side
(Need compilation)
![Page 19: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/19.jpg)
LESS
@company_blue: #0186d1;@focus_width: 100;div#content {
div.title {background-color: @company_blue;&:hover,&:active {
width: @focus_width;}
}}
![Page 20: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/20.jpg)
Data Struggle - I don't want to know the details
● Backend service○ CGI○ fast cgi/wsgi○ URL command○ Dbus○ Gconf○ Web service○ Tunnel message○ JSON/XML○ ...
![Page 21: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/21.jpg)
CRUD
● Create/Read/Update/Delete is most common for every kind of data access.
● Implement and wrapper your backend service for CRUD.○ DataModel.create()○ DataModel.update()○ DataModel.delete()○ DataModel.read()
![Page 22: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/22.jpg)
$.Model
● CRUD functions, overwrittable● Event callback whenever data is
○ created○ deleted○ updated○ and if you like, custom event on model is creatable.
● DOM embeddable○ <div <%= model %></div>
● Validation in data model layer
![Page 23: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/23.jpg)
Plugin/Widget/UI component Struggle
● None loosely coupled.● No cross function communication.● DOM renew and event rebind
○ a long long string in your javascript like■ $('#div').html('<div class="event"><span class="
name"></span><span class="icon"></span></div>')
![Page 24: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/24.jpg)
$.Controller features
● OpenAjax PubSub○ Not jQuery.pubsub, but the similar thing they could
do.● DOM manipulation is delegated to $.View()● Native event delegation
○ jQuery.on()○ 'button#save click': function(el, ev){
} ● FAST!
![Page 25: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/25.jpg)
$.View features
● Seperate HTML from your javascript codes.● Reusable, cachable● Logic (javascript) in HTML
○ http://embeddedjs.com○ <ul>
<% for(var i=0; i<supplies.length; i++) {%><li><%= supplies[i] %></li><% } %></ul>
![Page 26: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/26.jpg)
Library struggle - dependancy
● Case○ jQuery.scrollbars(http://www.aplweb.co.uk/blog/js/scrollbars-v2/) depends on
the following libraries■ jQuery■ jQuery.event.drag■ jQuery.resize■ mousehold■ mousewheel
○ So, hardcode in your <head>.
<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>
![Page 27: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/27.jpg)
Library struggle (CONT.)
● When your web application grows, more and more external libraries is used.
● The result will be a non-maintainable <head/>
![Page 28: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/28.jpg)
StealJS
● Library dependancy solution○ Part of stealJS is something like requireJS.○ By concurrent ajax request.○ steal('jquery').then
('jquery/ui','jquery/event/mousewheel').then('./lol.css', function(){
//....});
● Code generator○ ./js jquery/templates/controller A.B.C
● Compile scripts● (Customizable) build process● Compile *.less into one whole css
![Page 29: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/29.jpg)
Ajax struggle
● You can do nothing without server. Do you?● Multi ajax request solution
![Page 30: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/30.jpg)
Deferred Model
● Since jQuery 1.5, ajax is implemented as a deferred object.
● Models CRUD support deferred operation.● $.fixture
○ Create a deferred instead of sending XMLHttpRequest to the server, but to the function you preferred.
![Page 31: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/31.jpg)
Form operation
● Using formParams(), retrieve data from a form is easier.
● You do not to collect value one by one input.
![Page 32: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/32.jpg)
The end?
● No, you will face problems if you want to start building a large web application using javascriptMVC.
● So how could I organize my application?
![Page 33: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/33.jpg)
Next Topic:
● Let's rock on JavascriptMVC○ How to start coding with JavascriptMVC?○ What JavascriptMVC document lacks○ A framework based on JavascriptMVC○ Some common rules.○ An example
![Page 34: JavascriptMVC: Another choice of web framework](https://reader034.fdocuments.net/reader034/viewer/2022052523/5558bd3fd8b42a7e298b516d/html5/thumbnails/34.jpg)
Javascript is beautiful.Let's use it to get the world better.