es2015 ready angular web stack par douglas duteil à best of web 2015

55
ES2015 ready Angular web stack ? Douglas Duteil @douglasduteil

Upload: sfeir

Post on 06-Aug-2015

392 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

ES2015 ready Angular web stack ?

Douglas Duteil @douglasduteil

Page 2: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Angular 1.x

Douglas Duteil @douglasduteil

….…. Dec 18, 2014

Page 3: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Angular 1.x

Douglas Duteil @douglasduteil

Since Feb 15, 2015

Page 4: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

ES2015 ready Angular web stack ?

Douglas Duteil @douglasduteil

Page 5: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Me, Myself and I

Douglas Duteil@douglasduteil

Front End Dev at SFΞIRMembre de Angular UICofounder of OneDoes

Page 6: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Once upon a time…

Page 8: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Fail often

Page 9: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

The winning stack

Page 10: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

ES2015 ?

Page 11: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

ECMAScript 2015

● ECMAScript the spec of JavaScript

● Last version : ES5 => ES2009

● New one : ES6 => ES2015

Page 12: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

ES2015 aka ES6● In Browser Modularity System (import/export)

● Enhanced browser api (Object, Array, Promise, Loader...)

● Syntaxic sugar (spreading, destructuring, fat arrows...)

Page 13: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

ES6 is not ES5...

Page 14: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Learn it !

Page 15: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Target attitude

Page 16: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Critical path first

● Load the first page fast ! ○ Inline all the critical stuff !

● Async loading for the rest

● The rest can be anything ! ○ I said anything○ From any source....

Page 17: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Critical path first

Page Critical Resources

SystemJS

Bootstrapping

Page 18: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

What’s SystemJS

● Spec-compliant universal module loader

● Builded on top of the Loader API (ES7)

● Loads: ○ ES6 modules, AMD, CommonJS, global scripts○ And more through plugins (CSS, JSON, etc…)

Page 19: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Bootstrapping

<script

src="https://github.jspm.io/systemjs/[email protected]/dist/system.js">

</script>

<script>

// import 'app.js' from the current URL

System.import('app');

</script>

Page 20: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

...System.config({

"paths": {

"*": "*.js",

"github:*": "jspm_packages/github/*.js"

}

});

System.config({

"map": {

"angular": "github:angular/[email protected]",

"angular-mocks": "github:angular/[email protected]"

}

}); NOPE

Page 21: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

JSPM

GANG

Page 22: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

JSPM

JSPM Stargate

Page 23: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

6 PACK MANAGA

JESUS SUPA

Page 24: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

What’s JSPM

● Package manager for the SystemJS universal module loader

● Can use npm and github endpoints

● Auto create/update a config file for SystemJS from your package.json

Page 25: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Simple plz

# Create / validate project configuration file

jspm init

# Install and config your dependencies

jspm install angular angular-mocks

Page 26: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Simple plz$ tree -L 4 jspm_packagesjspm_packages├── github│ └── angular│ ├── [email protected]│ │ ├── angular.js│ │ └── ...│ ├── [email protected]│ ├── [email protected]│ │ ├── angular-mocks.js│ │ └── ...│ └── [email protected]├── es6-module-loader.js├── system.js├── traceur.js└── ...

Page 27: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Simple plz$ tree -L 4 jspm_packagesjspm_packages├── github│ └── angular│ ├── [email protected]│ │ ├── angular.js│ │ └── ...│ ├── [email protected]│ ├── [email protected]│ │ ├── angular-mocks.js│ │ └── ...│ └── [email protected]├── es6-module-loader.js├── system.js├── traceur.js└── ...

Page 28: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

The win ?

Page Critical Resources

SystemJS

Bootstrapping

System.config

JSPM

Vendors Sources

Page 29: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

ngColloc

Page 30: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Conflicts ?

● Module system

● Dependency injection

● Utilities

Page 31: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Module system

// on b.js

angular.module('b', [

'a'

]);

// on a.js

angular.module('a', []);

● ES5

Page 32: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Module system

// on b.js

import angular from 'angular';

import aModule from './a';

export default angular.module('b', [

aModule.name

]);

// on a.js

import angular from 'angular';

export default angular.module('a', []);

● ES6

Page 33: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Dependency injection// on a.js

angular.module('a', [])

.factory('aFacto', aFacto)

;

/**

* @ngInject

*/

function aFacto(){

// ...

}

● ES5

Page 34: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Dependency injection// on b.js

angular.module('b', ['a'])

.controller('BbCtrl', BbCtrl)

;

/**

* @ngInject

*/

function BbCtrl(aFacto){

// ...

}

● ES5

Page 35: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Dependency injection// on a.js

export function aFacto(){

// ...

}

● ES6

Page 36: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Dependency injection// on b.js

import angular from 'angular';

import {aFacto} from './a';

export default angular.module('b', [])

.controller('BbCtrl', BbCtrl);

/**

* @ngInject

*/

function BbCtrl(){

// aFacto bla bla bla...

}

● ES6

Page 37: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Utilities

var opts = angular.extend({}, defaults, options);

// to ES6

let opts = Object.assign({}, defaults, options);

// or ES7

let opts = {...defaults, ...options}

Page 38: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Quality matters

Page 39: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Quality matters

● Well known minimal ES5 quality tests :

○ JSHINT / ESLint○ Karma unit tests○ Karma coverage

Page 41: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015
Page 42: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

peerDependencyIstanbul

Karma preprocessor

Gulp

Page 43: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

peerDependencyIsparta

Karma-babel- preprocessor

Gulp-babel

Page 44: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Isparta !

Page 46: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Isparta !

● Transform ES6 to ES5 (with babel)

● Extract its abstract syntax tree (AST)

● Run the coverage over the AST

● Post process the result with a sourcemap

Page 47: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Isparta !

Page 48: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Conclusion

Page 49: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Ghetto Coding

Page 51: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Thanks

Page 52: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Merry

Page 53: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

X mascript

Merry

Page 54: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

X mascript

Merry

Page 55: Es2015 ready angular web stack par Douglas Duteil à Best Of Web 2015

Q & A

Douglas Duteil @douglasduteil