SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
What is Mantri?
✓ Manages Web Application's Dependencies

✓ Leaves no footprint on production

✓ Offers a complete workflow

✓ IE6+

                                         #mantrijs
                                      mantrijs.com
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
Why Manage?
● Automatic dependency resolution
● Enables large scale applications
● Collaboration between large teams
● Code scalability
● Better readability



                                         #mantrijs
                                      mantrijs.com
Mantri Development Cycle




                              #mantrijs
                           mantrijs.com
Page Load Breakout
Mantri Runtime
Starts Parsing

                                    mantriConf
                 Synchronous XHR
                                    .json


                  document.write    Vendor
                 ('<script>...');   Libs


                 Synchronous XHR    deps.js


                  document.write
                 ('<script>...');   Your
                                    Application

  Mantri Runtime Finishes
          Parsing




                                                     #mantrijs
                                                  mantrijs.com
Mantri 50k feet View
                                           $ mantri deps




          Resolves Deps ✓
  Concats app to one file ✓
Strips require statements ✓
            Compiles app ✓
     Optionally wraps app ✓
       Minifies third-party ✓
         Concatenates all ✓
                                $ mantri
                                build                         #mantrijs
                                                           mantrijs.com
Web Development with Mantri
The Natural Way




                     #mantrijs
                  mantrijs.com
Mantri Declarations
                         goog.provide('app');

                         goog.require('app.model.User');
                         goog.require('app.view.main');

                         var user = new app.model.User();




goog.provide('app.model.User');                   goog.provide('app.view.main');

goog.require('app.helpers');                      goog.require('app.view.front);
                                                  goog.require('app.view.about);
app.model.User = function() {                     goog.require('app.view.login);
  // ...




                                                                                #mantrijs
                                                                             mantrijs.com
Dependency Tree




                     #mantrijs
                  mantrijs.com
Mantri Uses Namespaces
goog.provide('app.views.frontpage');

// equals to
var app = app || {};
app.views = app.views || {};
app.views.frontpage = app.views.frontpage || {};

// and...
window.app === app;




                                                      #mantrijs
                                                   mantrijs.com
The HTML Document
<script src="js/libs/mantri.web.js"></script>




<script data-require="app" ...
<script data-config="/mantriConf.json" ...
<script data-deps="/deps.js" ...




                                                   #mantrijs
                                                mantrijs.com
Required Files
mantriConf.json              deps.js
● Declare third-party libs   ● Auto generated
● Dependency Config          ● Command line
● Build Config               ● Each time a declaration
                                changes




                                                     #mantrijs
                                                  mantrijs.com
Building Your Application
$ mantri build




✓ Grunt Task




                               #mantrijs
                            mantrijs.com
Workflow Concepts
Application Wrapping
"outputWrapper": "(function(){<%=output%>})();"




● IIFEs are cool
● "Hides" all previously global variables
● Explicit exposing




                                                     #mantrijs
                                                  mantrijs.com
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
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
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
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
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
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
Recap, Mantri Features
Mantri Specifications
● Synchronous, app loads before DomContentLoaded
● No footprint on production
● Simple provide and require statements
● Available on NPM




                                                  #mantrijs
                                               mantrijs.com
Mantri Specifications
● Wraps around Google Closure Tools
● Uses Grunt Task Manager
● Abstracts the complexity away
● Low entry barrier that scales seamlessly




                                                #mantrijs
                                             mantrijs.com
Thank You!


http://mantrijs.com

#mantrijs
@thanpolas
http://thanpol.as

Weitere ähnliche Inhalte

Andere mochten auch (6)

Intro to node.js web apps
Intro to node.js web appsIntro to node.js web apps
Intro to node.js web apps
 
HowTo Freelance
HowTo FreelanceHowTo Freelance
HowTo Freelance
 
Entities, the theory
Entities, the theoryEntities, the theory
Entities, the theory
 
Entities on Node.JS
Entities on Node.JSEntities on Node.JS
Entities on Node.JS
 
Metrics - Hands On
Metrics - Hands OnMetrics - Hands On
Metrics - Hands On
 
Intro to node.js
Intro to node.jsIntro to node.js
Intro to node.js
 

Ähnlich wie Mantri Presentation One

A Story about AngularJS modularization development
A Story about AngularJS modularization developmentA Story about AngularJS modularization development
A Story about AngularJS modularization developmentJohannes Weber
 
Asynchronous Module Definition (AMD)
Asynchronous Module Definition (AMD)Asynchronous Module Definition (AMD)
Asynchronous Module Definition (AMD)xMartin12
 
Java2day 2013 : Modern workflows for javascript integration
Java2day 2013 : Modern workflows for javascript integrationJava2day 2013 : Modern workflows for javascript integration
Java2day 2013 : Modern workflows for javascript integrationMite Mitreski
 
Story about module management with angular.js
Story about module management with angular.jsStory about module management with angular.js
Story about module management with angular.jsDavid Amend
 
JSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendJSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendVlad Fedosov
 
Isomorphic JavaScript: #DevBeat Master Class
Isomorphic JavaScript: #DevBeat Master ClassIsomorphic JavaScript: #DevBeat Master Class
Isomorphic JavaScript: #DevBeat Master ClassSpike Brehm
 
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JSFestUA
 
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan KrausHTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan KrausWomen in Technology Poland
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalabilityTwinbit
 
Single Page Applications – Know The Ecosystem system
Single Page Applications – Know The Ecosystem systemSingle Page Applications – Know The Ecosystem system
Single Page Applications – Know The Ecosystem systemSynerzip
 
(Js) Export your own WebGL Viewer
(Js) Export your own WebGL Viewer(Js) Export your own WebGL Viewer
(Js) Export your own WebGL ViewerJooinK
 
Deep dive into Android async operations
Deep dive into Android async operationsDeep dive into Android async operations
Deep dive into Android async operationsMateusz Grzechociński
 
Griffon for the Enterprise
Griffon for the EnterpriseGriffon for the Enterprise
Griffon for the EnterpriseJames Williams
 
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...Alessandro Molina
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]GDSC UofT Mississauga
 
Client vs Server Templating: Speed up initial load for SPA with Angular as an...
Client vs Server Templating: Speed up initial load for SPA with Angular as an...Client vs Server Templating: Speed up initial load for SPA with Angular as an...
Client vs Server Templating: Speed up initial load for SPA with Angular as an...David Amend
 

Ähnlich wie Mantri Presentation One (20)

A Story about AngularJS modularization development
A Story about AngularJS modularization developmentA Story about AngularJS modularization development
A Story about AngularJS modularization development
 
Asynchronous Module Definition (AMD)
Asynchronous Module Definition (AMD)Asynchronous Module Definition (AMD)
Asynchronous Module Definition (AMD)
 
Java2day 2013 : Modern workflows for javascript integration
Java2day 2013 : Modern workflows for javascript integrationJava2day 2013 : Modern workflows for javascript integration
Java2day 2013 : Modern workflows for javascript integration
 
Story about module management with angular.js
Story about module management with angular.jsStory about module management with angular.js
Story about module management with angular.js
 
JSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendJSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontend
 
Isomorphic JavaScript: #DevBeat Master Class
Isomorphic JavaScript: #DevBeat Master ClassIsomorphic JavaScript: #DevBeat Master Class
Isomorphic JavaScript: #DevBeat Master Class
 
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
 
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan KrausHTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus
 
Grails 101
Grails 101Grails 101
Grails 101
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalability
 
Micro frontend
Micro frontendMicro frontend
Micro frontend
 
Hello android
Hello androidHello android
Hello android
 
Node.js Course 2 of 2 - Advanced techniques
Node.js Course 2 of 2 - Advanced techniquesNode.js Course 2 of 2 - Advanced techniques
Node.js Course 2 of 2 - Advanced techniques
 
Single Page Applications – Know The Ecosystem system
Single Page Applications – Know The Ecosystem systemSingle Page Applications – Know The Ecosystem system
Single Page Applications – Know The Ecosystem system
 
(Js) Export your own WebGL Viewer
(Js) Export your own WebGL Viewer(Js) Export your own WebGL Viewer
(Js) Export your own WebGL Viewer
 
Deep dive into Android async operations
Deep dive into Android async operationsDeep dive into Android async operations
Deep dive into Android async operations
 
Griffon for the Enterprise
Griffon for the EnterpriseGriffon for the Enterprise
Griffon for the Enterprise
 
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
 
Client vs Server Templating: Speed up initial load for SPA with Angular as an...
Client vs Server Templating: Speed up initial load for SPA with Angular as an...Client vs Server Templating: Speed up initial load for SPA with Angular as an...
Client vs Server Templating: Speed up initial load for SPA with Angular as an...
 

Kürzlich hochgeladen

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Kürzlich hochgeladen (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
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
  • 5. Mantri Development Cycle #mantrijs mantrijs.com
  • 6. Page Load Breakout Mantri Runtime Starts Parsing mantriConf Synchronous XHR .json document.write Vendor ('<script>...'); Libs Synchronous XHR deps.js document.write ('<script>...'); Your Application Mantri Runtime Finishes Parsing #mantrijs mantrijs.com
  • 7. Mantri 50k feet View $ mantri deps Resolves Deps ✓ Concats app to one file ✓ Strips require statements ✓ Compiles app ✓ Optionally wraps app ✓ Minifies third-party ✓ Concatenates all ✓ $ mantri build #mantrijs mantrijs.com
  • 9. The Natural Way #mantrijs mantrijs.com
  • 10. Mantri Declarations goog.provide('app'); goog.require('app.model.User'); goog.require('app.view.main'); var user = new app.model.User(); goog.provide('app.model.User'); goog.provide('app.view.main'); goog.require('app.helpers'); goog.require('app.view.front); goog.require('app.view.about); app.model.User = function() { goog.require('app.view.login); // ... #mantrijs mantrijs.com
  • 11. Dependency Tree #mantrijs mantrijs.com
  • 12. Mantri Uses Namespaces goog.provide('app.views.frontpage'); // equals to var app = app || {}; app.views = app.views || {}; app.views.frontpage = app.views.frontpage || {}; // and... window.app === app; #mantrijs mantrijs.com
  • 13. The HTML Document <script src="js/libs/mantri.web.js"></script> <script data-require="app" ... <script data-config="/mantriConf.json" ... <script data-deps="/deps.js" ... #mantrijs mantrijs.com
  • 14. Required Files mantriConf.json deps.js ● Declare third-party libs ● Auto generated ● Dependency Config ● Command line ● Build Config ● Each time a declaration changes #mantrijs mantrijs.com
  • 15. Building Your Application $ mantri build ✓ Grunt Task #mantrijs mantrijs.com
  • 17. Application Wrapping "outputWrapper": "(function(){<%=output%>})();" ● IIFEs are cool ● "Hides" all previously global variables ● Explicit exposing #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