@olympum #mojito JSConfUS 2012
broken things
(yes, we are all broken)
NoJSConf
why?
networks
packet loss is a reality, especially in emerging countries
assume connected devices are only partially connected
spotty reachability is common on mobile networks
latency is not constant, 100kb are not 10*10kb
mobile
almost 6b mobile subscribers worldwide in 2011
277m mobile Internet users in China, 66% of Internet users
mobile web !== desktop web. mobile devices are only partially connected
not just latency limitations: battery life, bandwidth, processor, memory ...
never, ever, ever assume JavaScript will be available nor fully capable in the client device
do the right thing
progressive enhancement
code duplication
faced with duplication
developers implement only AJAX
and because networks can break
pages will break
we must remove duplication
fight duplication: server-side JavaScript to the rescue
we need to make client-side JavaScript and server-side JavaScript be equivalent
luckily YUI3 does the lion's share of the work
how?
browser
DOM
JS
client stuff
Node.JS
http
JS (V8)
server stuff
JavaScript (DOM/strings)
PHP (strings/DOM)
HTTP (strings)
model
YUI.add('galleryModelFlickr', function(Y) {
// register model in Y.mojito.models namespace.
Y.namespace('mojito.models').gallery = {
get_photos: function(callback){
Y.YQL (flickr_query, function(rawYql) {
if (null == rawYql || 0 == rawYql.query.count) {
callback ([]);
} else {
callback(rawYql.query.results);
}
}
};
}, '0.0.1', {requires: ['yql']});
view
<div>
<p>The user is from {{country}}.</p>
</div>
index.opera-mini.mu.html
index.iphone.mu.html
index.ipad.mu.html
...
controller
YUI.add('flickr', function(Y) {
Y.mojito.controller = {
index: function(ac) {
var gallery = ac.models.gallery;
gallery.get_photos (function(photos) {
ac.done (
{
ac.done(photos);
}
)'
});
}
};
}, '0.0.1', {requires: []});
ActionContext API
ac.models.*.getData();
ac.config.get('key');
ac.params.body('key');
ac.assets.addCss('./style.css');
ac.cookie.set('flavor', 'choco-chip');
ac.http.addHeader('x-foo', 'val');
ac.done('a string');
ac.error('oops');
dispatch
client
DOM
Binders
Proxy
server
http
Node.JS
Express
Use a spacebar or arrow keys to navigate