Skip to content

Commit 5d44436

Browse files
mheveryjbdeboer
authored andcommitted
chore: Replace Module.[type|value|factory]() with Module.bind()
1 parent 8af0552 commit 5d44436

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+395
-401
lines changed

bin/parser_generator_for_spec.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import 'package:angular/core/parser/parser.dart';
66
import 'package:angular/tools/parser_getter_setter/generator.dart';
77

88
main(arguments) {
9-
Module module = new Module()..type(Parser, implementedBy: DynamicParser);
10-
module.type(ParserBackend, implementedBy: DartGetterSetterGen);
9+
Module module = new Module()..bind(Parser, toImplementation: DynamicParser);
10+
module.bind(ParserBackend, toImplementation: DartGetterSetterGen);
1111
Injector injector = new DynamicInjector(modules: [module],
1212
allowImplicitInjection: true);
1313

example/web/animation.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ class AnimationDemo {
2020
class AnimationDemoModule extends Module {
2121
AnimationDemoModule() {
2222
install(new AnimationModule());
23-
type(RepeatDemo);
24-
type(VisibilityDemo);
25-
type(StressDemo);
26-
type(CssDemo);
27-
type(AnimationDemo);
23+
bind(RepeatDemo);
24+
bind(VisibilityDemo);
25+
bind(StressDemo);
26+
bind(CssDemo);
27+
bind(AnimationDemo);
2828
}
2929
}
3030
main() {

example/web/bouncing_balls.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ class BallPosition {
124124

125125
class MyModule extends Module {
126126
MyModule() {
127-
type(BounceController);
128-
type(BallPosition);
127+
bind(BounceController);
128+
bind(BallPosition);
129129
}
130130
}
131131

example/web/hello_world.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ class HelloWorld {
1010

1111
main() {
1212
applicationFactory()
13-
.addModule(new Module()..type(HelloWorld))
13+
.addModule(new Module()..bind(HelloWorld))
1414
.run();
1515
}

example/web/todo.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,28 +95,28 @@ class Todo {
9595
main() {
9696
print(window.location.search);
9797
var module = new Module()
98-
..type(Todo)
99-
..type(PlaybackHttpBackendConfig);
98+
..bind(Todo)
99+
..bind(PlaybackHttpBackendConfig);
100100

101101
// If these is a query in the URL, use the server-backed
102102
// TodoController. Otherwise, use the stored-data controller.
103103
var query = window.location.search;
104104
if (query.contains('?')) {
105-
module.type(Server, implementedBy: HttpServer);
105+
module.bind(Server, toImplementation: HttpServer);
106106
} else {
107-
module.type(Server, implementedBy: NoOpServer);
107+
module.bind(Server, toImplementation: NoOpServer);
108108
}
109109

110110
if (query == '?record') {
111111
print('Using recording HttpBackend');
112112
var wrapper = new HttpBackendWrapper(new HttpBackend());
113-
module.value(HttpBackendWrapper, new HttpBackendWrapper(new HttpBackend()));
114-
module.type(HttpBackend, implementedBy: RecordingHttpBackend);
113+
module.bind(HttpBackendWrapper, toValue: new HttpBackendWrapper(new HttpBackend()));
114+
module.bind(HttpBackend, toImplementation: RecordingHttpBackend);
115115
}
116116

117117
if (query == '?playback') {
118118
print('Using playback HttpBackend');
119-
module.type(HttpBackend, implementedBy: PlaybackHttpBackend);
119+
module.bind(HttpBackend, toImplementation: PlaybackHttpBackend);
120120
}
121121

122122
applicationFactory().addModule(module).run();

lib/animate/module.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ final Logger _logger = new Logger('ng.animate');
155155
*/
156156
class AnimationModule extends Module {
157157
AnimationModule() {
158-
type(AnimationFrame);
159-
type(AnimationLoop);
160-
type(CssAnimationMap);
161-
type(AnimationOptimizer);
162-
value(NgAnimate, null);
163-
type(NgAnimateChildren);
164-
type(Animate, implementedBy: CssAnimate);
158+
bind(AnimationFrame);
159+
bind(AnimationLoop);
160+
bind(CssAnimationMap);
161+
bind(AnimationOptimizer);
162+
bind(NgAnimate, toValue: null);
163+
bind(NgAnimateChildren);
164+
bind(Animate, toImplementation: CssAnimate);
165165
}
166166
}

lib/application.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* class MyModule extends Module {
1212
* MyModule() {
13-
* type(HelloWorldController);
13+
* bind(HelloWorldController);
1414
* }
1515
* }
1616
*
@@ -101,8 +101,8 @@ class AngularModule extends Module {
101101
install(new PerfModule());
102102
install(new RoutingModule());
103103

104-
type(MetadataExtractor);
105-
value(Expando, elementExpando);
104+
bind(MetadataExtractor);
105+
bind(Expando, toValue: elementExpando);
106106
}
107107
}
108108

@@ -146,9 +146,9 @@ abstract class Application {
146146

147147
Application(): element = _find('[ng-app]', dom.window.document.documentElement) {
148148
modules.add(ngModule);
149-
ngModule..value(VmTurnZone, zone)
150-
..value(Application, this)
151-
..factory(dom.Node, (i) => i.get(Application).element);
149+
ngModule..bind(VmTurnZone, toValue: zone)
150+
..bind(Application, toValue: this)
151+
..bind(dom.Node, toFactory: (i) => i.get(Application).element);
152152
}
153153

154154
/**

lib/application_factory.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ import 'dart:mirrors' show MirrorsUsed;
6060
class _DynamicApplication extends Application {
6161
_DynamicApplication() {
6262
ngModule
63-
..type(MetadataExtractor, implementedBy: DynamicMetadataExtractor)
64-
..type(FieldGetterFactory, implementedBy: DynamicFieldGetterFactory)
65-
..type(ClosureMap, implementedBy: DynamicClosureMap);
63+
..bind(MetadataExtractor, toImplementation: DynamicMetadataExtractor)
64+
..bind(FieldGetterFactory, toImplementation: DynamicFieldGetterFactory)
65+
..bind(ClosureMap, toImplementation: DynamicClosureMap);
6666
}
6767

6868
Injector createInjector() => new DynamicInjector(modules: modules);

lib/application_factory_static.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* class MyModule extends Module {
1515
* MyModule() {
16-
* type(HelloWorldController);
16+
* bind(HelloWorldController);
1717
* }
1818
* }
1919
*
@@ -55,10 +55,9 @@ class _StaticApplication extends Application {
5555
Map<String, FieldSetter> fieldSetters,
5656
Map<String, Symbol> symbols) {
5757
ngModule
58-
..value(MetadataExtractor, new StaticMetadataExtractor(metadata))
59-
..value(FieldGetterFactory, new StaticFieldGetterFactory(fieldGetters))
60-
..value(ClosureMap, new StaticClosureMap(fieldGetters, fieldSetters,
61-
symbols));
58+
..bind(MetadataExtractor, toValue: new StaticMetadataExtractor(metadata))
59+
..bind(FieldGetterFactory, toValue: new StaticFieldGetterFactory(fieldGetters))
60+
..bind(ClosureMap, toValue: new StaticClosureMap(fieldGetters, fieldSetters, symbols));
6261
}
6362

6463
Injector createInjector() =>
@@ -76,7 +75,7 @@ class _StaticApplication extends Application {
7675
*
7776
* main() {
7877
* applicationFactory()
79-
* .addModule(new Module()..type(HelloWorld))
78+
* .addModule(new Module()..bind(HelloWorld))
8079
* .run();
8180
* }
8281
*
@@ -88,7 +87,7 @@ class _StaticApplication extends Application {
8887
* generated_static_expressions.getters,
8988
* generated_static_expressions.setters,
9089
* generated_static_expressions.symbols)
91-
* .addModule(new Module()..type(HelloWorldController))
90+
* .addModule(new Module()..bind(HelloWorldController))
9291
* .run();
9392
*
9493
*/
@@ -98,6 +97,5 @@ Application staticApplicationFactory(
9897
Map<String, FieldGetter> fieldGetters,
9998
Map<String, FieldSetter> fieldSetters,
10099
Map<String, Symbol> symbols) {
101-
return new _StaticApplication(typeFactories, metadata, fieldGetters, fieldSetters,
102-
symbols);
100+
return new _StaticApplication(typeFactories, metadata, fieldGetters, fieldSetters, symbols);
103101
}

lib/core/annotation_src.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ abstract class Directive {
123123
* module: Foo.moduleFactory)
124124
* class Foo {
125125
* static moduleFactory() => new Module()
126-
* ..type(SomeTypeA, visibility: Directive.LOCAL_VISIBILITY);
126+
* ..bind(SomeTypeA, visibility: Directive.LOCAL_VISIBILITY);
127127
* }
128128
*
129129
* When specifying types, factories or values in the module, notice that
@@ -563,7 +563,7 @@ abstract class DetachAware {
563563
*
564564
* // Registration
565565
* var module = ...;
566-
* module.type(MyFilter);
566+
* module.bind(MyFilter);
567567
*
568568
*
569569
* <!-- Usage -->

lib/core/module_internal.dart

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,26 @@ part "zone.dart";
3131

3232
class CoreModule extends Module {
3333
CoreModule() {
34-
type(ScopeDigestTTL);
35-
36-
type(MetadataExtractor);
37-
type(Cache);
38-
type(ExceptionHandler);
39-
type(FormatterMap);
40-
type(Interpolate);
41-
type(RootScope);
42-
factory(Scope, (injector) => injector.get(RootScope));
43-
factory(ClosureMap, (_) => throw "Must provide dynamic/static ClosureMap.");
44-
type(ScopeStats);
45-
type(ScopeStatsEmitter);
46-
factory(ScopeStatsConfig, (i) => new ScopeStatsConfig());
47-
value(Object, {}); // RootScope context
48-
type(VmTurnZone);
49-
50-
type(Parser, implementedBy: DynamicParser);
51-
type(ParserBackend, implementedBy: DynamicParserBackend);
52-
type(DynamicParser);
53-
type(DynamicParserBackend);
54-
type(Lexer);
34+
bind(ScopeDigestTTL);
35+
36+
bind(MetadataExtractor);
37+
bind(Cache);
38+
bind(ExceptionHandler);
39+
bind(FormatterMap);
40+
bind(Interpolate);
41+
bind(RootScope);
42+
bind(Scope, toFactory: (injector) => injector.get(RootScope));
43+
bind(ClosureMap, toFactory: (_) => throw "Must provide dynamic/static ClosureMap.");
44+
bind(ScopeStats);
45+
bind(ScopeStatsEmitter);
46+
bind(ScopeStatsConfig, toFactory: (i) => new ScopeStatsConfig());
47+
bind(Object, toValue: {}); // RootScope context
48+
bind(VmTurnZone);
49+
50+
bind(Parser, toImplementation: DynamicParser);
51+
bind(ParserBackend, toImplementation: DynamicParserBackend);
52+
bind(DynamicParser);
53+
bind(DynamicParserBackend);
54+
bind(Lexer);
5555
}
5656
}

lib/core_dom/common.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DirectiveRef {
3737
*/
3838
Injector forceNewDirectivesAndFilters(Injector injector, List<Module> modules) {
3939
modules.add(new Module()
40-
..factory(Scope, (i) {
40+
..bind(Scope, toFactory: (i) {
4141
var scope = i.parent.get(Scope);
4242
return scope.createChild(new PrototypeMap(scope.context));
4343
}));

lib/core_dom/element_binder.dart

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ class TemplateElementBinder extends ElementBinder {
2727
_registerViewFactory(node, parentInjector, nodeModule) {
2828
assert(templateViewFactory != null);
2929
nodeModule
30-
..factory(ViewPort, (_) =>
30+
..bind(ViewPort, toFactory: (_) =>
3131
new ViewPort(node, parentInjector.get(Animate)))
32-
..value(ViewFactory, templateViewFactory)
33-
..factory(BoundViewFactory, (Injector injector) =>
32+
..bind(ViewFactory, toValue: templateViewFactory)
33+
..bind(BoundViewFactory, toFactory: (Injector injector) =>
3434
templateViewFactory.bind(injector));
3535
}
3636
}
@@ -239,13 +239,13 @@ class ElementBinder {
239239
_createDirectiveFactories(DirectiveRef ref, nodeModule, node, nodesAttrsDirectives, nodeAttrs,
240240
visibility) {
241241
if (ref.type == TextMustache) {
242-
nodeModule.factory(TextMustache, (Injector injector) {
242+
nodeModule.bind(TextMustache, toFactory: (Injector injector) {
243243
return new TextMustache(node, ref.value, injector.get(Interpolate),
244244
injector.get(Scope), injector.get(FormatterMap));
245245
});
246246
} else if (ref.type == AttrMustache) {
247247
if (nodesAttrsDirectives.isEmpty) {
248-
nodeModule.factory(AttrMustache, (Injector injector) {
248+
nodeModule.bind(AttrMustache, toFactory: (Injector injector) {
249249
var scope = injector.get(Scope);
250250
var interpolate = injector.get(Interpolate);
251251
for (var ref in nodesAttrsDirectives) {
@@ -265,17 +265,17 @@ class ElementBinder {
265265
} else {
266266
factory = _componentFactory;
267267
}
268-
nodeModule.factory(ref.type, factory.call(node, ref), visibility: visibility);
268+
nodeModule.bind(ref.type, toFactory: factory.call(node, ref), visibility: visibility);
269269
} else {
270-
nodeModule.type(ref.type, visibility: visibility);
270+
nodeModule.bind(ref.type, visibility: visibility);
271271
}
272272
}
273273

274274
// Overridden in TemplateElementBinder
275275
_registerViewFactory(node, parentInjector, nodeModule) {
276-
nodeModule..factory(ViewPort, null)
277-
..factory(ViewFactory, null)
278-
..factory(BoundViewFactory, null);
276+
nodeModule..bind(ViewPort, toValue: null)
277+
..bind(ViewFactory, toValue: null)
278+
..bind(BoundViewFactory, toValue: null);
279279
}
280280

281281
Injector bind(View view, Injector parentInjector, dom.Node node) {
@@ -293,19 +293,19 @@ class ElementBinder {
293293

294294
var nodesAttrsDirectives = [];
295295
var nodeModule = new Module()
296-
..type(NgElement)
297-
..value(View, view)
298-
..value(dom.Element, node)
299-
..value(dom.Node, node)
300-
..value(NodeAttrs, nodeAttrs)
301-
..factory(ElementProbe, (_) => probe);
296+
..bind(NgElement)
297+
..bind(View, toValue: view)
298+
..bind(dom.Element, toValue: node)
299+
..bind(dom.Node, toValue: node)
300+
..bind(NodeAttrs, toValue: nodeAttrs)
301+
..bind(ElementProbe, toFactory: (_) => probe);
302302

303303
directiveRefs.forEach((DirectiveRef ref) {
304304
Directive annotation = ref.annotation;
305305
var visibility = ref.annotation.visibility;
306306
if (ref.annotation is Controller) {
307307
scope = scope.createChild(new PrototypeMap(scope.context));
308-
nodeModule.value(Scope, scope);
308+
nodeModule.bind(Scope, toValue: scope);
309309
}
310310

311311
_createDirectiveFactories(ref, nodeModule, node, nodesAttrsDirectives, nodeAttrs,

0 commit comments

Comments
 (0)