WordPress Websites for Engineers: Elevate Your Brand
Mantri Presentation One
1.
2. What is Mantri?
✓ Manages Web Application's Dependencies
✓ Leaves no footprint on production
✓ Offers a complete workflow
✓ IE6+
#mantrijs
mantrijs.com
3. What Dependencies?
● Multiple Javascript Files
● Each file can depend on other files
● Order of loading
● Order of evaluation
● Order of concatenating and building
#mantrijs
mantrijs.com
4. Why Manage?
● Automatic dependency resolution
● Enables large scale applications
● Collaboration between large teams
● Code scalability
● Better readability
#mantrijs
mantrijs.com
18. Module Definitions
CommonJS AMD Asynchronous Module Definition
● Used in node.js ● Extended browser support
● Supported in Browser ● Uses function factories
● Uses exports and module. ● Encapsulates each file in an
exports keywords anon function
[[ harmony:modules ]] ES6
● Spec is not out yet
● Doesn't support existing
definitions (yet?)
● Not a module loader
#mantrijs
mantrijs.com
19. Universal Module Definitions
...or how you can expose your library as a CommonJS or AMD module.
UMD module definitions can work anywhere, be it in the client, on the
server or anywhere else.
(function (root, factory) {
if (typeof exports === 'object') {
module.exports = factory();
} else if (typeof define === 'function' && define.amd) {
define(factory);
} else {
root.returnExports = factory();
}
}(this, function(){return app;}));
https://github.com/umdjs/umd/
#mantrijs
mantrijs.com
20. Using Namespaces
● Debugging from console
● Dead easy stubbing and mocking for testing
● Increases visibility and maintainability
● Scales smoothly
● Modern build flows decouple development from
production
#mantrijs
mantrijs.com
21. So Why Not Modules?
● The Web is not the server. Nor it will ever be.
● Module Definitions are not Module Loaders.
● Debugging requires inspector with break points.
● Stubbing for Testing is really hard.
● Nasty problems, lengthy troubleshooting.
● Overhead. ~+7.5% minified, ~+5.5% gzip
#mantrijs
mantrijs.com
22. Why not Namespaces?
● Can become verbose app.ui.combo.EventType Use an alias
● Namespace conflicts Use a wrapping IIFE
● Exposes internal methods Use a wrapping IIFE
● Modules are the future Use a wrapping IIFE, UMD
● Modules are cool
#mantrijs
mantrijs.com
23. Namespaces vs Modules
Tokens
● requires build goog.provide('app.views.main'');
● large scale ready goog.require('app.views.frontpage');
/* win */
● calculates once per build
Filenames
● no build requirement define('viewMain, ['app/views/frontpage'],
● can't move files or folders function (viewFrontpage) { /* .. */ });
easily
● calculates on each page
load
#mantrijs
mantrijs.com
25. Mantri Specifications
● Synchronous, app loads before DomContentLoaded
● No footprint on production
● Simple provide and require statements
● Available on NPM
#mantrijs
mantrijs.com
26. Mantri Specifications
● Wraps around Google Closure Tools
● Uses Grunt Task Manager
● Abstracts the complexity away
● Low entry barrier that scales seamlessly
#mantrijs
mantrijs.com