+ All Categories
Home > Technology > Mantri Presentation One

Mantri Presentation One

Date post: 18-Oct-2014
Category:
View: 770 times
Download: 6 times
Share this document with a friend
Description:
Mantri Javascript Dependency System Presentation One
27
Transcript
Page 1: Mantri Presentation One
Page 2: Mantri Presentation One

What is Mantri?✓ Manages Web Application's Dependencies

✓ Leaves no footprint on production

✓ Offers a complete workflow

✓ IE6+

#mantrijsmantrijs.com

Page 3: Mantri Presentation One

What Dependencies?● Multiple Javascript Files

● Each file can depend on other files

● Order of loading

● Order of evaluation

● Order of concatenating and building

#mantrijsmantrijs.com

Page 4: Mantri Presentation One

Why Manage?● Automatic dependency resolution

● Enables large scale applications

● Collaboration between large teams

● Code scalability

● Better readability

#mantrijsmantrijs.com

Page 6: Mantri Presentation One

Page Load Breakout

#mantrijsmantrijs.com

mantriConf.json

Vendor Libs

deps.js

Your Application

Mantri Runtime Finishes Parsing

Synchronous XHR

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

Mantri RuntimeStarts Parsing

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

Synchronous XHR

Page 7: Mantri Presentation One

Mantri 50k feet View

$ mantri deps

$ mantri build

Resolves Deps ✓Concats app to one file ✓

Strips require statements ✓Compiles app ✓

Optionally wraps app ✓Minifies third-party ✓

Concatenates all ✓

#mantrijsmantrijs.com

Page 8: Mantri Presentation One

Web Development with Mantri

Page 9: Mantri Presentation One

The Natural Way

#mantrijsmantrijs.com

Page 10: Mantri Presentation One

Mantri Declarations

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

goog.require('app.helpers');

app.model.User = function() { // ...

goog.provide('app');

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

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

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

goog.require('app.view.front);goog.require('app.view.about);goog.require('app.view.login);

#mantrijsmantrijs.com

Page 11: Mantri Presentation One

Dependency Tree

#mantrijsmantrijs.com

Page 12: Mantri Presentation One

Mantri Uses Namespacesgoog.provide('app.views.frontpage');

// equals tovar app = app || {};app.views = app.views || {};app.views.frontpage = app.views.frontpage || {};

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

#mantrijsmantrijs.com

Page 13: Mantri Presentation One

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" ...

#mantrijsmantrijs.com

Page 14: Mantri Presentation One

Required FilesmantriConf.json● Declare third-party libs● Dependency Config● Build Config

deps.js● Auto generated● Command line● Each time a declaration

changes

#mantrijsmantrijs.com

Page 15: Mantri Presentation One

Building Your Application$ mantri build

✓ Grunt Task

#mantrijsmantrijs.com

Page 16: Mantri Presentation One

Workflow Concepts

Page 17: Mantri Presentation One

Application Wrapping"outputWrapper": "(function(){<%=output%>})();"

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

#mantrijsmantrijs.com

Page 18: Mantri Presentation One

Module DefinitionsCommonJS● Used in node.js● Supported in Browser● Uses exports and module.

exports keywords

AMD Asynchronous Module Definition

● Extended browser support● Uses function factories● Encapsulates each file in an

anon function

[[ harmony:modules ]] ES6

● Spec is not out yet● Doesn't support existing

definitions (yet?)● Not a module loader

#mantrijsmantrijs.com

Page 19: Mantri Presentation One

Universal Module Definitions

(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;}));

UMD module definitions can work anywhere, be it in the client, on the server or anywhere else.

...or how you can expose your library as a CommonJS or AMD module.

https://github.com/umdjs/umd/

#mantrijsmantrijs.com

Page 20: Mantri Presentation One

● Debugging from console

● Dead easy stubbing and mocking for testing

● Increases visibility and maintainability

● Scales smoothly

● Modern build flows decouple development from

production

Using Namespaces

mantrijs.com#mantrijs

mantrijs.com

Page 21: Mantri Presentation One

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

#mantrijsmantrijs.com

Page 22: Mantri Presentation One

● 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

Why not Namespaces?

mantrijs.com#mantrijs

mantrijs.com

Page 23: Mantri Presentation One

Namespaces vs Modules

goog.provide('app.views.main'');

goog.require('app.views.frontpage');

/* win */

#mantrijsmantrijs.com

Tokens● requires build● large scale ready● calculates once per build

Filenames● no build requirement● can't move files or folders

easily● calculates on each page

load

define('viewMain, ['app/views/frontpage'],

function (viewFrontpage) { /* .. */ });

Page 24: Mantri Presentation One

Recap, Mantri Features

Page 25: Mantri Presentation One

● Synchronous, app loads before DomContentLoaded

● No footprint on production

● Simple provide and require statements

● Available on NPM

Mantri Specifications

#mantrijsmantrijs.com

Page 26: Mantri Presentation One

Mantri Specifications● Wraps around Google Closure Tools

● Uses Grunt Task Manager

● Abstracts the complexity away

● Low entry barrier that scales seamlessly

#mantrijsmantrijs.com

Page 27: Mantri Presentation One

Thank You!

http://mantrijs.com

#mantrijs@thanpolashttp://thanpol.as


Recommended