SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
10.
Example: Underscore.js
var posts = [{
id: 1,
title: 'JavaScript is cool'
}, {
id: 2,
title: 'The Web is the platform'
}];
_.pluck(posts, 'title');
// ['JavaScript is cool', 'The Web is the platform']
17.
Isomorphic
JavaScript can be
environmentagnostic
or
shimmed per
environment .
18.
Environment-agnostic
Does not depend on browserspecific properties (window) or
server-specific properties
(process.env, req.cookies).
19.
Example: Handlebars.js
var template =
'<ul>'
'{{#each posts}}'
' <li>{{title}}</li>'
'{{/each}}'
'</ul>'
;
var templateFn = Handlebars.compile(template)
, html = templateFn({posts: posts});
// <ul>
//
<li>JavaScript is cool</li>
//
<li>The Web is the platform</li>
// </ul>
20.
Shimmed per environment
Provides shims for accessing
environment-specific properties so
module can expose a single API.
window.location.pathname
vs.
req.path
34.
Browserif
Package up CommonJS modules
for the browser.
Use ‘require()’ in the browser, the
same way you would on the server.
35.
Browserif
// app/template_renderer.js
var handlebars = require('handlebars');
module.exports = function(templatePath, data) {
var templateFn = require('./views/' + templatePath)
, html = templateFn(data);
return html;
};
Bundles a module and all its dependencies.
36.
Grunt
Task runner for automating build
and development workflow.
37.
Grunt
• Compile
Handlebars templates
• Run Browserify to package up
your shared app files
• Recompile files and restart Node
server on every change