A Story about AngularJS modularization development
1,872 views
57 slides
Jan 30, 2015
Slide 1 of 57
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
About This Presentation
The more your AngularJS App is growing the more important is modularization. It starts with the naming convention, file structure, AMD, goes through the build process, loading and packaging strategies and ends in the browser.
We are going to give proposed solutions in practice as a ground for discu...
The more your AngularJS App is growing the more important is modularization. It starts with the naming convention, file structure, AMD, goes through the build process, loading and packaging strategies and ends in the browser.
We are going to give proposed solutions in practice as a ground for discussion.
Further, you are welcome to present your ideas in slides or code, which demonstrate how to manage modularization in Angular.js projects.
Speaker Bio:
Johannes Weber has spent more than 10 years in front- and backend development. He works for Mayflower GmbH where he focuses on the migration of SPA and MPA.
David Amend ist seit Jahren im Banken-Umfeld mit Schwerpunkt auf der Frontend-Entwicklung mithilfe von Java und JavaScript in Projekten tätig.
Size: 1.91 MB
Language: en
Added: Jan 30, 2015
Slides: 57 pages
Slide Content
A Story about AngularJS
modularization development
Munich Meetup #4
What’s about loading more these 5 scripts?
...how could I handle this?
You could use AMD!
-scoped thirdparty
-correct order of “mc” + “angular.module”
-framework independant
-async file loading of all dependencies
define([“lodash”, “angular”, “mycomponents”], function(_, angular, mc) {
mc.setModel(friends: [{name : “Peter”, age : 35}]);
return angular.module('myApp', ['mycomponents'])
.controller('MyCtrl1', [‘myService’, function (myService) {
//...
}])
});
AMD: what’s that?
“mycomponents” is duplicated! Why?
define([“mycomponents”], function(mc) {
angular.module('myApp', ['mycomponents'])
.controller('MyCtrl1', [‘myService’, function (myService) {
mc.setModel(friends: [{name : “Peter”, age : 35}]);
//...
}]) });
3.
angular
→ used in any file !
load order must be handled?
→ anything loaded before angular.bootstrap
→ no code outside of angular.module
$script([
'vendorLibs.min.js',
'myapp.min.js'
], function() {
angular.bootstrap(document, ['myApp']);
});
How to deal with vendors?
angular + lodash
-polluting global namespace?
lodash → not used anywhere
define([“mycomponents”], function(mc) {
angular.module('myApp', ['mycomponents'])
.controller('MyCtrl1', [‘myService’, function (myService) {
var _ = myNamespace.vendorLibs.lodash;
//...
}]) });
How to deal with vendors?
polluting → namespacing
How to deal with vendors?
Use existing modules: angular-lodash
https://github.com/rockabox/ng-lodash
var app = angular.module('yourAwesomeApp', ['ngLodash']);
Are you using A of AMD, only for DEV ?
Loading 100 single files in the browser ?
Do you distinguish between DEV and PROD?
Do you distinguish between
dev and prod with AMD ?
app.js
JS Dependency Levels
app.js
JS Dependency Levels
Development Production
build, minified, concatinated
vendorLibs.min.js
JS Dependency Levels
Production Production
Splitting your source into junks would be nicer!
app.js
JS Dependency Levels
appTemplates.min.js
myapp.min.js
What are Modules in AngularJS 2.0
import {Inject} from 'di/annotations';
import {Grinder} from './grinder';
import {Pump} from './pump';
import {Heater} from './heater';
@Inject(Grinder, Pump, Heater)
export class CoffeeMaker {
constructor(grinder, pump, heater) {
}
brew() {
console.log('Brewing a coffee...');
}}
Angular 2.0
→ combining angulars DI with ES6 loaders
→ combining ES6 loader with angular
???
→ which is preferred long time strategy ?
The end
Outlook
Outlook: AngularJS 2.0
-removal of angular.module
-Loading through ES6 modules
-Dependency Injection, Inversion of Control,
annotations
But: how to know about magic dependencies of
'vendorLibs.min.js'
→ bower.json
Using Bower for YOUR modules !
/someRepo
-mymodule/bower.json
-mysubmodule/bower.json
-vendor-libs/bower.json
-global-css/bower.json
/anotherRepo
-anothermodule/bower.json
TypeScript to support traceability of usages
module myapp.body {
import MyserviceType = myapp.header.myService; → compiled + removed at build time
angular.module('myApp')
.controller('MyCtrl1', [‘myService’, function (myService : MyServiceType) {
var result = myService.fetchData('123');
//...
}]) }) };
declare module myapp.header {
interface responseData {
name : string,
age : number
}