SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
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

Contenu connexe

En vedette (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
 

Similaire à 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
 

Similaire à 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...
 

Dernier

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Dernier (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

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