SlideShare a Scribd company logo
moving to modules
@mize
hi!
@mize
“moving to
modules”?
modules:
how do they work?
a unit of code…
…with an encapsulated definition
…that explicitly declares its dependencies
…whose instances can be mapped to different
identifiers that expose its interface
benefits
• Clean(er) global namespace
• Eases dependency management
• Reusability
• Testability
should i wait for
harmony?
—Sean Mize
“nope.”
goals of harmony
• Obviate need for globals
• Orthogonality from existing features
• Smooth refactoring from global code to modular code
• Smooth interoperability with existing JS module systems like AMD, CommonJS,
and Node.js
• Fast compilation
• Simplicity and usability
• Standardized protocol for sharing libraries
• Compatibility with browser and non-browser environments
• Easy asynchronous external loading
goals of harmony
• Obviate need for globals
• Orthogonality from existing features
• Smooth refactoring from global code to modular code
• Smooth interoperability with existing JS module
systems like AMD, CommonJS, and Node.js
• Fast compilation
• Simplicity and usability
• Standardized protocol for sharing libraries
• Compatibility with browser and non-browser environments
• Easy asynchronous external loading
no technical
excuse not to
migrate now
where do i start?
pick your poison
what do i need?
format and loader
node.js
/* makeItAwesome.js */!
var multiplier = require('multiplier').awesome;!
!
function makeItAwesome(value) {!
return value * multiplier;!
}!
!
exports = module.exports = makeItAwesome;
node.js
/* makeItAwesome.js */!
var multiplier = require('multiplier').awesome;!
!
function makeItAwesome(value) {!
return value * multiplier;!
}!
!
exports = module.exports = makeItAwesome;!
!
!
!
/* app.js */!
var makeItAwesome = require('makeItAwesome');!
var everything = require('status').good;!
!
everything = makeItAwesome(everything);
exports = module.exports = ?
/* makeItAwesome.js */!
var multiplier = require('multiplier').awesome;!
!
function makeItAwesome(value) {!
return value * multiplier;!
}!
!
exports = module.exports = makeItAwesome;!
!
!
!
/* Imagine this require() implementation */!
function (module, exports) {!
exports = some_func;!
// re-assigns exports, exports is no longer a shortcut,!
// and nothing is exported.!
module.exports = some_other_func;!
} (module, module.exports);
AMD
/* makeItAwesome.js */!
define(['multiplier/awesome'], function (multiplier) {!
function makeItAwesome(value) {!
return value * multiplier;!
};!
!
return makeItAwesome;!
});
AMD
/* makeItAwesome.js */!
define(['multiplier/awesome'], function (multiplier) {!
function makeItAwesome(value) {!
return value * multiplier;!
};!
!
return makeItAwesome;!
});!
!
!
!
/* app.js */!
define(['makeItAwesome', 'status/good'], function (makeItAwesome,
everything) {!
everything = makeItAwesome(everything);!
});
which?
Moving to Node?
☛ Node variant of CommonJS
Primarily in the browser?
☛ AMD + RequireJS, curl.js or similar
Need to share logic across both?
☛ You’ll need help.
ok, but what
about…
1. shave fewer yaks
2. choose approach
3. apply consistently
& clearly
pick your battles
useful questions
• What are your goals? What would be most
useful for your near-term needs?
• How quickly/completely can/do you need to
convert?
• F/E benefits or code reuse across stack?
• Are there other consumers of your libs?
migrate!
migrate!
1. Map your dependencies
migrate!
1. Map your dependencies
2. Load all of your files via loader
RequireJS shim
requirejs.config({!
baseUrl: '/src/js',!
paths: {!
'foo': 'legacy/foo'!
},!
shim: {!
'foo': {!
deps: ['bar'],!
exports: 'Foo',!
init: function (bar) {!
return this.Foo.noConflict();!
}!
}!
}!
});
migrate!
1. Map your dependencies
2. Load all of your files via loader
3. Walk your dependencies, wrapping or
converting as you go
[ interlude ]
possible sticking points
code sequence
/* Old - app.js */!
Foo.init();!
Bar.init(); // Bar depends on globals created during Foo.init()
code sequence
/* Old - app.js */!
Foo.init();!
Bar.init(); // Bar depends on globals created during Foo.init()!
!
!
!
/* Transitional - app.js */!
define(['foo', 'bar'], function (Foo, Bar) {!
Foo.init();!
Bar.init();!
});
code sequence
/* Old - app.js */!
Foo.init();!
Bar.init(); // Bar depends on globals created during Foo.init()!
!
!
!
/* Transitional - app.js */!
define(['foo', 'bar'], function (Foo, Bar) {!
Foo.init();!
Bar.init();!
});!
!
!
!
/* Final form - bar.js */!
define(['foo']), function (Foo) {!
// Former Foo.init logic is now part of Foo's module definition!
// so just do Bar stuff!
}
globals
You're using AMD, but others depending 

on your lib don't (yet).
globals
You're using AMD, but others depending 

on your lib don't (yet).
!
!
(function (root, factory) {!
if (typeof define === 'function' && define.amd) {!
// AMD. Register as an anonymous module.!
define(['b'], factory);!
} else {!
// Browser globals!
root.amdWeb = factory(root.b);!
}!
}(this, function (b) {!
// use b in some fashion.!
// ...!
return amdWeb;!
}));
migrate!
1. Map your dependencies
2. Load all of your files via loader
3. Walk your dependencies, wrapping or
converting as you go
4. Profit!
clean up
clean up
• Package management
• Optimize
• Great time to incorporate grunt (or gulp!) 

w/ linting/validation into your workflow
• Add tests!
don’t wait for
harmony.
!
write better
code now.
thank you!
@mize

More Related Content

What's hot

Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
Adam Wiggins
 
Intro to Rails
Intro to Rails Intro to Rails
Intro to Rails
epiineg1
 
Silex, the microframework
Silex, the microframeworkSilex, the microframework
Silex, the microframework
Inviqa
 
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
rivierarb
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
sickill
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
LaunchAny
 
Bullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkBullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkVance Lucas
 
All That Jazz
All  That  JazzAll  That  Jazz
All That Jazz
Nick Carter
 
PROCESS WARP「プロセスがデバイス間で移動する」仕組みを作る
PROCESS WARP「プロセスがデバイス間で移動する」仕組みを作るPROCESS WARP「プロセスがデバイス間で移動する」仕組みを作る
PROCESS WARP「プロセスがデバイス間で移動する」仕組みを作る
祐司 伊藤
 
Unit Testing With Javascript
Unit Testing With JavascriptUnit Testing With Javascript
Unit Testing With Javascript
thedumbterminal
 
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Alberto Perdomo
 
Express JS
Express JSExpress JS
Express JS
Alok Guha
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web frameworktaggg
 
My Robot Poops - In JavaScript (with web sockets)
My Robot Poops - In JavaScript (with web sockets)My Robot Poops - In JavaScript (with web sockets)
My Robot Poops - In JavaScript (with web sockets)Matthew Schiffman
 
Oro meetup #4
Oro meetup #4Oro meetup #4
Oro meetup #4
Oleg Zinchenko
 
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
 
Mojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tMojolicious: what works and what doesn't
Mojolicious: what works and what doesn't
Cosimo Streppone
 
Ruby application based on http
Ruby application based on httpRuby application based on http
Ruby application based on http
Richard Huang
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
arman o
 
System webpack-jspm
System webpack-jspmSystem webpack-jspm
System webpack-jspmJesse Warden
 

What's hot (20)

Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
 
Intro to Rails
Intro to Rails Intro to Rails
Intro to Rails
 
Silex, the microframework
Silex, the microframeworkSilex, the microframework
Silex, the microframework
 
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012Ruby C extensions at the Ruby drink-up of Sophia, April 2012
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
 
Bullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkBullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-Framework
 
All That Jazz
All  That  JazzAll  That  Jazz
All That Jazz
 
PROCESS WARP「プロセスがデバイス間で移動する」仕組みを作る
PROCESS WARP「プロセスがデバイス間で移動する」仕組みを作るPROCESS WARP「プロセスがデバイス間で移動する」仕組みを作る
PROCESS WARP「プロセスがデバイス間で移動する」仕組みを作る
 
Unit Testing With Javascript
Unit Testing With JavascriptUnit Testing With Javascript
Unit Testing With Javascript
 
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
 
Express JS
Express JSExpress JS
Express JS
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
 
My Robot Poops - In JavaScript (with web sockets)
My Robot Poops - In JavaScript (with web sockets)My Robot Poops - In JavaScript (with web sockets)
My Robot Poops - In JavaScript (with web sockets)
 
Oro meetup #4
Oro meetup #4Oro meetup #4
Oro meetup #4
 
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)
 
Mojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tMojolicious: what works and what doesn't
Mojolicious: what works and what doesn't
 
Ruby application based on http
Ruby application based on httpRuby application based on http
Ruby application based on http
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
 
System webpack-jspm
System webpack-jspmSystem webpack-jspm
System webpack-jspm
 

Viewers also liked

Common JavaScript Modules
Common JavaScript ModulesCommon JavaScript Modules
Common JavaScript ModulesKris Kowal
 
MelbJS Nov2014 - CommonJS & Mocking with Jest
MelbJS Nov2014 - CommonJS & Mocking with JestMelbJS Nov2014 - CommonJS & Mocking with Jest
MelbJS Nov2014 - CommonJS & Mocking with Jest
James Hunter
 
A nodejs application
A nodejs applicationA nodejs application
A nodejs application
Robbie Clutton
 
How to use CommonJS and AMD Modules now and in the browser!
How to use CommonJS and AMD Modules now and in the browser!How to use CommonJS and AMD Modules now and in the browser!
How to use CommonJS and AMD Modules now and in the browser!Samuel Breed
 
The future of server side JavaScript
The future of server side JavaScriptThe future of server side JavaScript
The future of server side JavaScriptOleg Podsechin
 
JavaScript Modules Done Right
JavaScript Modules Done RightJavaScript Modules Done Right
JavaScript Modules Done Right
Mariusz Nowak
 
AgileLIVE Webinar: Measuring the Success of Your Agile Transformation - Part 2
AgileLIVE Webinar: Measuring the Success of Your Agile Transformation - Part 2AgileLIVE Webinar: Measuring the Success of Your Agile Transformation - Part 2
AgileLIVE Webinar: Measuring the Success of Your Agile Transformation - Part 2
VersionOne
 
Make It Fast - Using Modern Browser Performance APIs to Monitor and Improve t...
Make It Fast - Using Modern Browser Performance APIs to Monitor and Improve t...Make It Fast - Using Modern Browser Performance APIs to Monitor and Improve t...
Make It Fast - Using Modern Browser Performance APIs to Monitor and Improve t...
Nicholas Jansma
 
Advanced Arel: When ActiveRecord Just Isn't Enough
Advanced Arel: When ActiveRecord Just Isn't EnoughAdvanced Arel: When ActiveRecord Just Isn't Enough
Advanced Arel: When ActiveRecord Just Isn't Enough
Cameron Dutro
 
Javascript Module Patterns
Javascript Module PatternsJavascript Module Patterns
Javascript Module Patterns
Nicholas Jansma
 
Modularize all the things
Modularize all the thingsModularize all the things
Modularize all the things
Ruy Adorno
 
CommonJS: JavaScript Everywhere
CommonJS: JavaScript EverywhereCommonJS: JavaScript Everywhere
CommonJS: JavaScript Everywhere
Kris Kowal
 
CommonJSの話
CommonJSの話CommonJSの話
CommonJSの話
terurou
 
通用JS时代的模块机制和编译工具
通用JS时代的模块机制和编译工具通用JS时代的模块机制和编译工具
通用JS时代的模块机制和编译工具
Dexter Yang
 

Viewers also liked (15)

Draft3 part 3
Draft3 part 3Draft3 part 3
Draft3 part 3
 
Common JavaScript Modules
Common JavaScript ModulesCommon JavaScript Modules
Common JavaScript Modules
 
MelbJS Nov2014 - CommonJS & Mocking with Jest
MelbJS Nov2014 - CommonJS & Mocking with JestMelbJS Nov2014 - CommonJS & Mocking with Jest
MelbJS Nov2014 - CommonJS & Mocking with Jest
 
A nodejs application
A nodejs applicationA nodejs application
A nodejs application
 
How to use CommonJS and AMD Modules now and in the browser!
How to use CommonJS and AMD Modules now and in the browser!How to use CommonJS and AMD Modules now and in the browser!
How to use CommonJS and AMD Modules now and in the browser!
 
The future of server side JavaScript
The future of server side JavaScriptThe future of server side JavaScript
The future of server side JavaScript
 
JavaScript Modules Done Right
JavaScript Modules Done RightJavaScript Modules Done Right
JavaScript Modules Done Right
 
AgileLIVE Webinar: Measuring the Success of Your Agile Transformation - Part 2
AgileLIVE Webinar: Measuring the Success of Your Agile Transformation - Part 2AgileLIVE Webinar: Measuring the Success of Your Agile Transformation - Part 2
AgileLIVE Webinar: Measuring the Success of Your Agile Transformation - Part 2
 
Make It Fast - Using Modern Browser Performance APIs to Monitor and Improve t...
Make It Fast - Using Modern Browser Performance APIs to Monitor and Improve t...Make It Fast - Using Modern Browser Performance APIs to Monitor and Improve t...
Make It Fast - Using Modern Browser Performance APIs to Monitor and Improve t...
 
Advanced Arel: When ActiveRecord Just Isn't Enough
Advanced Arel: When ActiveRecord Just Isn't EnoughAdvanced Arel: When ActiveRecord Just Isn't Enough
Advanced Arel: When ActiveRecord Just Isn't Enough
 
Javascript Module Patterns
Javascript Module PatternsJavascript Module Patterns
Javascript Module Patterns
 
Modularize all the things
Modularize all the thingsModularize all the things
Modularize all the things
 
CommonJS: JavaScript Everywhere
CommonJS: JavaScript EverywhereCommonJS: JavaScript Everywhere
CommonJS: JavaScript Everywhere
 
CommonJSの話
CommonJSの話CommonJSの話
CommonJSの話
 
通用JS时代的模块机制和编译工具
通用JS时代的模块机制和编译工具通用JS时代的模块机制和编译工具
通用JS时代的模块机制和编译工具
 

Similar to Moving to modules

Transforming WebSockets
Transforming WebSocketsTransforming WebSockets
Transforming WebSockets
Arnout Kazemier
 
Modular JavaScript
Modular JavaScriptModular JavaScript
Modular JavaScript
Andrew Eisenberg
 
Fitc whats new in es6 for web devs
Fitc   whats new in es6 for web devsFitc   whats new in es6 for web devs
Fitc whats new in es6 for web devsFITC
 
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
jerryorr
 
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra  SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
Sencha
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web Devs
Rami Sayar
 
Introduction to JavaScript design patterns
Introduction to JavaScript design patternsIntroduction to JavaScript design patterns
Introduction to JavaScript design patterns
Jeremy Duvall
 
Migrating Babel from CommonJS to ESM
Migrating Babel     from CommonJS to ESMMigrating Babel     from CommonJS to ESM
Migrating Babel from CommonJS to ESM
Igalia
 
RubyConf Portugal 2014 - Why ruby must go!
RubyConf Portugal 2014 - Why ruby must go!RubyConf Portugal 2014 - Why ruby must go!
RubyConf Portugal 2014 - Why ruby must go!
Gautam Rege
 
Serializing EMF models with Xtext
Serializing EMF models with XtextSerializing EMF models with Xtext
Serializing EMF models with Xtext
meysholdt
 
uRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.orguRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.org
Agelos Pikoulas
 
Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)
Ran Mizrahi
 
Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Ran Mizrahi
 
Beyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascript
aglemann
 
Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)
Spike Brehm
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
偉格 高
 
Beginning Scala with Skinny Framework #jjug_ccc
Beginning Scala with Skinny Framework #jjug_cccBeginning Scala with Skinny Framework #jjug_ccc
Beginning Scala with Skinny Framework #jjug_ccc
Kazuhiro Sera
 

Similar to Moving to modules (20)

Transforming WebSockets
Transforming WebSocketsTransforming WebSockets
Transforming WebSockets
 
Modular JavaScript
Modular JavaScriptModular JavaScript
Modular JavaScript
 
Es.next
Es.nextEs.next
Es.next
 
Fitc whats new in es6 for web devs
Fitc   whats new in es6 for web devsFitc   whats new in es6 for web devs
Fitc whats new in es6 for web devs
 
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
 
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra  SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web Devs
 
Introduction to JavaScript design patterns
Introduction to JavaScript design patternsIntroduction to JavaScript design patterns
Introduction to JavaScript design patterns
 
Migrating Babel from CommonJS to ESM
Migrating Babel     from CommonJS to ESMMigrating Babel     from CommonJS to ESM
Migrating Babel from CommonJS to ESM
 
RubyConf Portugal 2014 - Why ruby must go!
RubyConf Portugal 2014 - Why ruby must go!RubyConf Portugal 2014 - Why ruby must go!
RubyConf Portugal 2014 - Why ruby must go!
 
Serializing EMF models with Xtext
Serializing EMF models with XtextSerializing EMF models with Xtext
Serializing EMF models with Xtext
 
uRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.orguRequire@greecejs: An introduction to http://uRequire.org
uRequire@greecejs: An introduction to http://uRequire.org
 
Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)
 
Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)
 
Beyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascript
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
 
Beginning Scala with Skinny Framework #jjug_ccc
Beginning Scala with Skinny Framework #jjug_cccBeginning Scala with Skinny Framework #jjug_ccc
Beginning Scala with Skinny Framework #jjug_ccc
 

Recently uploaded

Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 

Recently uploaded (20)

Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 

Moving to modules

  • 5. a unit of code… …with an encapsulated definition …that explicitly declares its dependencies …whose instances can be mapped to different identifiers that expose its interface
  • 6. benefits • Clean(er) global namespace • Eases dependency management • Reusability • Testability
  • 7. should i wait for harmony?
  • 9. goals of harmony • Obviate need for globals • Orthogonality from existing features • Smooth refactoring from global code to modular code • Smooth interoperability with existing JS module systems like AMD, CommonJS, and Node.js • Fast compilation • Simplicity and usability • Standardized protocol for sharing libraries • Compatibility with browser and non-browser environments • Easy asynchronous external loading
  • 10. goals of harmony • Obviate need for globals • Orthogonality from existing features • Smooth refactoring from global code to modular code • Smooth interoperability with existing JS module systems like AMD, CommonJS, and Node.js • Fast compilation • Simplicity and usability • Standardized protocol for sharing libraries • Compatibility with browser and non-browser environments • Easy asynchronous external loading
  • 11. no technical excuse not to migrate now
  • 12. where do i start?
  • 14. what do i need? format and loader
  • 15. node.js /* makeItAwesome.js */! var multiplier = require('multiplier').awesome;! ! function makeItAwesome(value) {! return value * multiplier;! }! ! exports = module.exports = makeItAwesome;
  • 16. node.js /* makeItAwesome.js */! var multiplier = require('multiplier').awesome;! ! function makeItAwesome(value) {! return value * multiplier;! }! ! exports = module.exports = makeItAwesome;! ! ! ! /* app.js */! var makeItAwesome = require('makeItAwesome');! var everything = require('status').good;! ! everything = makeItAwesome(everything);
  • 17. exports = module.exports = ? /* makeItAwesome.js */! var multiplier = require('multiplier').awesome;! ! function makeItAwesome(value) {! return value * multiplier;! }! ! exports = module.exports = makeItAwesome;! ! ! ! /* Imagine this require() implementation */! function (module, exports) {! exports = some_func;! // re-assigns exports, exports is no longer a shortcut,! // and nothing is exported.! module.exports = some_other_func;! } (module, module.exports);
  • 18. AMD /* makeItAwesome.js */! define(['multiplier/awesome'], function (multiplier) {! function makeItAwesome(value) {! return value * multiplier;! };! ! return makeItAwesome;! });
  • 19. AMD /* makeItAwesome.js */! define(['multiplier/awesome'], function (multiplier) {! function makeItAwesome(value) {! return value * multiplier;! };! ! return makeItAwesome;! });! ! ! ! /* app.js */! define(['makeItAwesome', 'status/good'], function (makeItAwesome, everything) {! everything = makeItAwesome(everything);! });
  • 20. which? Moving to Node? ☛ Node variant of CommonJS Primarily in the browser? ☛ AMD + RequireJS, curl.js or similar Need to share logic across both? ☛ You’ll need help.
  • 22. 1. shave fewer yaks 2. choose approach 3. apply consistently & clearly
  • 24. useful questions • What are your goals? What would be most useful for your near-term needs? • How quickly/completely can/do you need to convert? • F/E benefits or code reuse across stack? • Are there other consumers of your libs?
  • 26. migrate! 1. Map your dependencies
  • 27. migrate! 1. Map your dependencies 2. Load all of your files via loader
  • 28. RequireJS shim requirejs.config({! baseUrl: '/src/js',! paths: {! 'foo': 'legacy/foo'! },! shim: {! 'foo': {! deps: ['bar'],! exports: 'Foo',! init: function (bar) {! return this.Foo.noConflict();! }! }! }! });
  • 29. migrate! 1. Map your dependencies 2. Load all of your files via loader 3. Walk your dependencies, wrapping or converting as you go
  • 30. [ interlude ] possible sticking points
  • 31. code sequence /* Old - app.js */! Foo.init();! Bar.init(); // Bar depends on globals created during Foo.init()
  • 32. code sequence /* Old - app.js */! Foo.init();! Bar.init(); // Bar depends on globals created during Foo.init()! ! ! ! /* Transitional - app.js */! define(['foo', 'bar'], function (Foo, Bar) {! Foo.init();! Bar.init();! });
  • 33. code sequence /* Old - app.js */! Foo.init();! Bar.init(); // Bar depends on globals created during Foo.init()! ! ! ! /* Transitional - app.js */! define(['foo', 'bar'], function (Foo, Bar) {! Foo.init();! Bar.init();! });! ! ! ! /* Final form - bar.js */! define(['foo']), function (Foo) {! // Former Foo.init logic is now part of Foo's module definition! // so just do Bar stuff! }
  • 34. globals You're using AMD, but others depending 
 on your lib don't (yet).
  • 35. globals You're using AMD, but others depending 
 on your lib don't (yet). ! ! (function (root, factory) {! if (typeof define === 'function' && define.amd) {! // AMD. Register as an anonymous module.! define(['b'], factory);! } else {! // Browser globals! root.amdWeb = factory(root.b);! }! }(this, function (b) {! // use b in some fashion.! // ...! return amdWeb;! }));
  • 36. migrate! 1. Map your dependencies 2. Load all of your files via loader 3. Walk your dependencies, wrapping or converting as you go 4. Profit!
  • 38. clean up • Package management • Optimize • Great time to incorporate grunt (or gulp!) 
 w/ linting/validation into your workflow • Add tests!