Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 5a14408

Browse files
vicbmhevery
authored andcommitted
style: code cleanup
Closes #671
1 parent aaae1d6 commit 5a14408

File tree

9 files changed

+125
-120
lines changed

9 files changed

+125
-120
lines changed

lib/animate/animation_optimizer.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ class AnimationOptimizer {
104104
bool shouldAnimate(dom.Node node) {
105105
bool alwaysAnimate = _alwaysAnimate[node];
106106
if (alwaysAnimate != null) {
107-
print("alwaysAnimate: $alwaysAnimate");
108107
return alwaysAnimate;
109108
}
110109

lib/bootstrap.dart

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,21 @@ Injector _defaultInjectorFactory(List<Module> modules) =>
4343
*
4444
* # Parameters:
4545
*
46-
* - [module] Option application module to add to the [Injector].
47-
* - [modules] Optional list of [Module]s to add to the [Injector] (if more than one is needed).
46+
* - [module] Optional application module to add to the [Injector].
47+
* - [modules] Optional list of [Module]s to add to the [Injector] (when more
48+
* than one is needed).
4849
* - [element] Optional root element of the application. If non specified, the
49-
* the root element is looked up using the [selector]. If selector can not
50-
* identify a root, the root [HTML] element is used for bootstraping.
51-
* - [selector] Optional CSS selector used to locate the root element for the application.
52-
* - [injectorFactor] Optional factory responsible for creating the injector.
50+
* the root element is looked up using the [selector]. If the selector can
51+
* not identify a root, the root [HTML] element is used.
52+
* - [selector] Optional CSS selector used to locate the root element for the
53+
* application.
54+
* - [injectorFactory] Optional factory responsible for creating the injector.
5355
*
5456
*
5557
*
5658
* # A typical way to boostrap an Angular application:
5759
*
58-
* Module myAppModule = new Module();
60+
* var myAppModule = new Module();
5961
* myAppModule.type(MyType);
6062
* ....
6163
* Injector injector = ngBootstrap(module: myAppModule);
@@ -73,9 +75,9 @@ Injector ngBootstrap({
7375
if (modules != null) ngModules.addAll(modules);
7476
if (element == null) {
7577
element = dom.querySelector(selector);
76-
var document = dom.window.document;
7778
if (element == null) {
78-
element = document.childNodes.firstWhere((e) => e is dom.Element);
79+
element = dom.window.document.childNodes
80+
.firstWhere((e) => e is dom.Element);
7981
}
8082
}
8183

@@ -89,8 +91,9 @@ Injector ngBootstrap({
8991
return zone.run(() {
9092
var rootElements = [element];
9193
Injector injector = injectorFactory(ngModules);
92-
injector.get(Compiler)(rootElements, injector.get(DirectiveMap))
93-
(injector, rootElements);
94+
var compiler = injector.get(Compiler);
95+
var blockFactory = compiler(rootElements, injector.get(DirectiveMap));
96+
blockFactory(injector, rootElements);
9497
return injector;
9598
});
9699
}

lib/core/registry.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ abstract class AnnotationMap<K> {
55

66
AnnotationMap(Injector injector, MetadataExtractor extractMetadata) {
77
injector.types.forEach((type) {
8-
var meta = extractMetadata(type)
8+
extractMetadata(type)
99
.where((annotation) => annotation is K)
1010
.forEach((annotation) {
1111
_map[annotation] = type;
@@ -19,10 +19,12 @@ abstract class AnnotationMap<K> {
1919
return value;
2020
}
2121

22-
forEach(fn(K, Type)) => _map.forEach(fn);
22+
void forEach(fn(K, Type)) {
23+
_map.forEach(fn);
24+
}
2325

2426
List<K> annotationsFor(Type type) {
25-
var res = <K>[];
27+
final res = <K>[];
2628
forEach((ann, annType) {
2729
if (annType == type) res.add(ann);
2830
});
@@ -35,7 +37,7 @@ abstract class AnnotationsMap<K> {
3537

3638
AnnotationsMap(Injector injector, MetadataExtractor extractMetadata) {
3739
injector.types.forEach((type) {
38-
var meta = extractMetadata(type)
40+
extractMetadata(type)
3941
.where((annotation) => annotation is K)
4042
.forEach((annotation) {
4143
map.putIfAbsent(annotation, () => []).add(type);
@@ -49,7 +51,7 @@ abstract class AnnotationsMap<K> {
4951
return value;
5052
}
5153

52-
forEach(fn(K, Type)) {
54+
void forEach(fn(K, Type)) {
5355
map.forEach((annotation, types) {
5456
types.forEach((type) {
5557
fn(annotation, type);
@@ -72,7 +74,8 @@ class MetadataExtractor {
7274
Iterable call(Type type) {
7375
if (reflectType(type) is TypedefMirror) return [];
7476
var metadata = reflectClass(type).metadata;
75-
if (metadata == null) return [];
76-
return metadata.map((InstanceMirror im) => im.reflectee);
77+
return metadata == null
78+
? []
79+
: metadata.map((InstanceMirror im) => im.reflectee);
7780
}
7881
}

lib/core_dom/block_factory.dart

Lines changed: 74 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,36 @@ part of angular.core.dom;
77
* BoundBlockFactory can only be used from within a specific Directive such
88
* as [NgRepeat], but it can not be stored in a cache.
99
*
10-
* The BoundBlockFactory needs [Scope] to be created.
10+
* The BoundBlockFactory needs a [Scope] to be created.
1111
*/
12-
class BoundBlockFactory {
13-
BlockFactory blockFactory;
14-
15-
Injector injector;
12+
class BoundBlockFactory implements Function {
13+
final BlockFactory blockFactory;
14+
final Injector injector;
1615

1716
BoundBlockFactory(this.blockFactory, this.injector);
1817

19-
Block call(Scope scope) {
20-
return blockFactory(injector.createChild([new Module()..value(Scope, scope)]));
21-
}
18+
Block call(Scope scope) =>
19+
blockFactory(injector.createChild([new Module()..value(Scope, scope)]));
2220
}
2321

2422
/**
2523
* BlockFactory is used to create new [Block]s. BlockFactory is created by the
2624
* [Compiler] as a result of compiling a template.
2725
*/
28-
class BlockFactory {
26+
class BlockFactory implements Function {
2927
final List directivePositions;
3028
final List<dom.Node> templateElements;
3129
final Profiler _perf;
3230
final Expando _expando;
3331

34-
BlockFactory(this.templateElements, this.directivePositions, this._perf, this._expando);
32+
BlockFactory(this.templateElements, this.directivePositions, this._perf,
33+
this._expando);
3534

3635
BoundBlockFactory bind(Injector injector) =>
37-
new BoundBlockFactory(this, injector);
36+
new BoundBlockFactory(this, injector);
3837

3938
Block call(Injector injector, [List<dom.Node> elements]) {
40-
if (elements == null) {
41-
elements = cloneElements(templateElements);
42-
}
39+
if (elements == null) elements = cloneElements(templateElements);
4340
var timerId;
4441
try {
4542
assert((timerId = _perf.startTimer('ng.block')) != false);
@@ -51,7 +48,8 @@ class BlockFactory {
5148
}
5249
}
5350

54-
_link(Block block, List<dom.Node> nodeList, List directivePositions, Injector parentInjector) {
51+
_link(Block block, List<dom.Node> nodeList, List directivePositions,
52+
Injector parentInjector) {
5553
var preRenderedIndexOffset = 0;
5654
var directiveDefsByName = {};
5755

@@ -93,8 +91,7 @@ class BlockFactory {
9391
}
9492

9593
Injector _instantiateDirectives(Block block, Injector parentInjector,
96-
dom.Node node, List<DirectiveRef> directiveRefs,
97-
Parser parser) {
94+
dom.Node node, List<DirectiveRef> directiveRefs, Parser parser) {
9895
var timerId;
9996
assert((timerId = _perf.startTimer('ng.block.link.setUp', _html(node))) != false);
10097
Injector nodeInjector;
@@ -105,17 +102,20 @@ class BlockFactory {
105102
ElementProbe probe;
106103

107104
try {
108-
if (directiveRefs == null || directiveRefs.length == 0) return parentInjector;
109-
var nodeModule = new Module();
105+
if (directiveRefs == null || directiveRefs.length == 0) {
106+
return parentInjector;
107+
}
110108
var blockHoleFactory = (_) => null;
111109
var blockFactory = (_) => null;
112110
var boundBlockFactory = (_) => null;
113111
var nodesAttrsDirectives = null;
114112

115-
nodeModule.value(Block, block);
116-
nodeModule.value(dom.Element, node);
117-
nodeModule.value(dom.Node, node);
118-
nodeModule.value(NodeAttrs, nodeAttrs);
113+
var nodeModule = new Module()
114+
..value(Block, block)
115+
..value(dom.Element, node)
116+
..value(dom.Node, node)
117+
..value(NodeAttrs, nodeAttrs);
118+
119119
directiveRefs.forEach((DirectiveRef ref) {
120120
NgAnnotation annotation = ref.annotation;
121121
var visibility = _elementOnly;
@@ -163,20 +163,23 @@ class BlockFactory {
163163
injector.get(dom.NodeTreeSanitizer), _expando);
164164
if (fctrs == null) fctrs = new Map<Type, _ComponentFactory>();
165165
fctrs[ref.type] = componentFactory;
166-
return componentFactory.call(injector, compiler, scope, blockCache, http, templateCache, directives);
166+
return componentFactory.call(injector, compiler, scope, blockCache,
167+
http, templateCache, directives);
167168
}, visibility: visibility);
168169
} else {
169170
nodeModule.type(ref.type, visibility: visibility);
170171
}
171172
for (var publishType in ref.annotation.publishTypes) {
172-
nodeModule.factory(publishType, (Injector injector) => injector.get(ref.type), visibility: visibility);
173+
nodeModule.factory(publishType, (Injector injector) =>
174+
injector.get(ref.type), visibility: visibility);
173175
}
174176
if (annotation.children == NgAnnotation.TRANSCLUDE_CHILDREN) {
175177
// Currently, transclude is only supported for NgDirective.
176178
assert(annotation is NgDirective);
177179
blockHoleFactory = (_) => new BlockHole([node]);
178180
blockFactory = (_) => ref.blockFactory;
179-
boundBlockFactory = (Injector injector) => ref.blockFactory.bind(injector);
181+
boundBlockFactory = (Injector injector) =>
182+
ref.blockFactory.bind(injector);
180183
}
181184
});
182185
nodeModule
@@ -198,7 +201,9 @@ class BlockFactory {
198201
var controller = nodeInjector.get(ref.type);
199202
probe.directives.add(controller);
200203
assert((linkMapTimer = _perf.startTimer('ng.block.link.map', ref.type)) != false);
201-
var shadowScope = (fctrs != null && fctrs.containsKey(ref.type)) ? fctrs[ref.type].shadowScope : null;
204+
var shadowScope = (fctrs != null && fctrs.containsKey(ref.type))
205+
? fctrs[ref.type].shadowScope
206+
: null;
202207
if (ref.annotation is NgController) {
203208
scope.context[(ref.annotation as NgController).publishAs] = controller;
204209
} else if (ref.annotation is NgComponent) {
@@ -252,21 +257,17 @@ class BlockFactory {
252257
}
253258

254259
// DI visibility callback allowing node-local visibility.
255-
256260
static final Function _elementOnly = (Injector requesting, Injector defining) {
257-
if (requesting.name == _SHADOW) {
258-
requesting = requesting.parent;
259-
}
261+
if (requesting.name == _SHADOW) requesting = requesting.parent;
260262
return identical(requesting, defining);
261263
};
262264

263265
// DI visibility callback allowing visibility from direct child into parent.
264-
265-
static final Function _elementDirectChildren = (Injector requesting, Injector defining) {
266-
if (requesting.name == _SHADOW) {
267-
requesting = requesting.parent;
268-
}
269-
return _elementOnly(requesting, defining) || identical(requesting.parent, defining);
266+
static final Function _elementDirectChildren = (Injector requesting,
267+
Injector defining) {
268+
if (requesting.name == _SHADOW) requesting = requesting.parent;
269+
return _elementOnly(requesting, defining) ||
270+
identical(requesting.parent, defining);
270271
};
271272
}
272273

@@ -278,16 +279,11 @@ class BlockFactory {
278279
@NgInjectableService()
279280
class BlockCache {
280281
// _blockFactoryCache is unbounded
281-
Cache<String, BlockFactory> _blockFactoryCache =
282-
new LruCache<String, BlockFactory>(capacity: 0);
283-
284-
Http $http;
285-
286-
TemplateCache $templateCache;
287-
288-
Compiler compiler;
289-
290-
dom.NodeTreeSanitizer treeSanitizer;
282+
final _blockFactoryCache = new LruCache<String, BlockFactory>(capacity: 0);
283+
final Http $http;
284+
final TemplateCache $templateCache;
285+
final Compiler compiler;
286+
final dom.NodeTreeSanitizer treeSanitizer;
291287

292288
BlockCache(this.$http, this.$templateCache, this.compiler, this.treeSanitizer);
293289

@@ -313,7 +309,7 @@ class BlockCache {
313309
* the shadowDom, fetching template, importing styles, setting up attribute
314310
* mappings, publishing the controller, and compiling and caching the template.
315311
*/
316-
class _ComponentFactory {
312+
class _ComponentFactory implements Function {
317313

318314
final dom.Element element;
319315
final Type type;
@@ -330,7 +326,9 @@ class _ComponentFactory {
330326
_ComponentFactory(this.element, this.type, this.component, this.treeSanitizer,
331327
this._expando);
332328

333-
dynamic call(Injector injector, Compiler compiler, Scope scope, BlockCache $blockCache, Http $http, TemplateCache $templateCache, DirectiveMap directives) {
329+
dynamic call(Injector injector, Compiler compiler, Scope scope,
330+
BlockCache $blockCache, Http $http, TemplateCache $templateCache,
331+
DirectiveMap directives) {
334332
this.compiler = compiler;
335333
shadowDom = element.createShadowRoot();
336334
shadowDom.applyAuthorStyles = component.applyAuthorStyles;
@@ -346,30 +344,34 @@ class _ComponentFactory {
346344
var cssUrls = component.cssUrls;
347345
if (cssUrls.isNotEmpty) {
348346
cssUrls.forEach((css) => cssFutures.add(
349-
$http.getString(css, cache: $templateCache).catchError((e) => '/*\n$e\n*/\n')
350-
) );
347+
$http.getString(css, cache: $templateCache).catchError((e) =>
348+
'/*\n$e\n*/\n')
349+
));
351350
} else {
352351
cssFutures.add( new async.Future.value(null) );
353352
}
354353
var blockFuture;
355354
if (component.template != null) {
356-
blockFuture = new async.Future.value($blockCache.fromHtml(component.template, directives));
355+
blockFuture = new async.Future.value($blockCache.fromHtml(
356+
component.template, directives));
357357
} else if (component.templateUrl != null) {
358358
blockFuture = $blockCache.fromUrl(component.templateUrl, directives);
359359
}
360-
TemplateLoader templateLoader = new TemplateLoader( async.Future.wait(cssFutures).then((Iterable<String> cssList) {
361-
if (cssList != null) {
362-
var filteredCssList = cssList.where((css) => css != null );
363-
shadowDom.setInnerHtml('<style>${filteredCssList.join('')}</style>', treeSanitizer: treeSanitizer);
364-
}
365-
if (blockFuture != null) {
366-
return blockFuture.then((BlockFactory blockFactory) {
367-
if (!shadowScope.isAttached) return shadowDom;
368-
return attachBlockToShadowDom(blockFactory);
369-
});
370-
}
371-
return shadowDom;
372-
}));
360+
TemplateLoader templateLoader = new TemplateLoader(
361+
async.Future.wait(cssFutures).then((Iterable<String> cssList) {
362+
if (cssList != null) {
363+
var filteredCssList = cssList.where((css) => css != null );
364+
shadowDom.setInnerHtml('<style>${filteredCssList.join('')}</style>',
365+
treeSanitizer: treeSanitizer);
366+
}
367+
if (blockFuture != null) {
368+
return blockFuture.then((BlockFactory blockFactory) {
369+
if (!shadowScope.isAttached) return shadowDom;
370+
return attachBlockToShadowDom(blockFactory);
371+
});
372+
}
373+
return shadowDom;
374+
}));
373375
controller = createShadowInjector(injector, templateLoader).get(type);
374376
if (controller is NgShadowRootAware) {
375377
templateLoader.template.then((_) {
@@ -423,21 +425,21 @@ String _html(obj) {
423425
if (obj is String) {
424426
return obj;
425427
} else if (obj is List) {
426-
return (obj as List).fold('', (v, e) => v + _html(e));
428+
return (obj as List).map((e) => _html(e)).join();
427429
} else if (obj is dom.Element) {
428430
var text = (obj as dom.Element).outerHtml;
429431
return text.substring(0, text.indexOf('>') + 1);
430-
} else {
431-
return obj.nodeName;
432432
}
433+
return obj.nodeName;
433434
}
434435

435436
/**
436-
* [ElementProbe] is attached to each [Element] in the DOM. Its sole purpose is to
437-
* allow access to the [Injector], [Scope], and Directives for debugging and automated
438-
* test purposes. The information here is not used by Angular in any way.
437+
* [ElementProbe] is attached to each [Element] in the DOM. Its sole purpose is
438+
* to allow access to the [Injector], [Scope], and Directives for debugging and
439+
* automated test purposes. The information here is not used by Angular in any
440+
* way.
439441
*
440-
* SEE: [ngInjector], [ngScope], [ngDirectives]
442+
* see: [ngInjector], [ngScope], [ngDirectives]
441443
*/
442444
class ElementProbe {
443445
final ElementProbe parent;

0 commit comments

Comments
 (0)