Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 6e8f602

Browse files
committed
post-review updates
1 parent f9dac13 commit 6e8f602

File tree

4 files changed

+35
-37
lines changed

4 files changed

+35
-37
lines changed

public/docs/_examples/dependency-injection/dart/lib/app_component.dart

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
// #docplaster
2-
// #docregion
3-
// #docregion imports
41
import 'package:angular2/core.dart';
52

63
import 'app_config.dart';
74
import 'car/car_component.dart';
85
import 'heroes/heroes_component.dart';
96
import 'logger_service.dart';
107
import 'user_service.dart';
11-
//PENDING: check whether we intend to hide injector_component.dart & providers_component.dart; if so, change docregion name?
12-
// #enddocregion imports
138
import 'injector_component.dart';
149
import 'test_component.dart';
1510
import 'providers_component.dart';
@@ -62,6 +57,6 @@ class AppComponent {
6257
return _userService.user;
6358
}
6459

65-
String get userInfo => 'Current user, ${user.name}, is'
66-
'${isAuthorized ? "" : " not"} authorized. ';
60+
String get userInfo => 'Current user, ${user.name}, is' +
61+
(isAuthorized ? '' : ' not') + ' authorized. ';
6762
}

public/docs/_examples/dependency-injection/dart/lib/logger_service.dart

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import 'package:angular2/core.dart';
44
@Injectable()
55
class Logger {
66
List<String> _logs = [];
7-
87
List<String> get logs => _logs;
98

109
void log(String message) {

public/docs/dart/latest/guide/dependency-injection.jade

+19-17
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ block config-obj-maps
9595

9696
block what-should-we-use-as-token
9797
:marked
98-
But what should we use as the token?
99-
We could use the **[Map][]** interface.
98+
But what should we use as the token?
99+
While we _could_ use **[Map][]**, we _should not_ because (like
100+
`String`) `Map` is too general. Our app might depend on several maps, each
101+
for a different purpose.
100102

101103
[Map]: https://api.dartlang.org/stable/dart-core/Map-class.html
102104

@@ -107,32 +109,32 @@ block what-should-we-use-as-token
107109
Dart doesn't have this limitation;
108110
every class implicitly defines an interface,
109111
so interface names are just class names.
110-
111-
:marked
112-
The problem with using `Map` as a token, is not that it is an abstract
113-
class, but rather that it is very general purpose (like `String`) and so
114-
our application may depend on several maps each used for a
115-
different purpose.
112+
`Map` is a *valid* token even though it's the name of an abstract class;
113+
it's just *unsuitable* as a token because it's too general.
116114

117115
block dart-map-alternative
118116
:marked
119117
As an alternative to using a configuration `Map`, we can define
120-
a custom class type:
118+
a custom configuration class:
121119

122120
+makeExample('dependency-injection/ts/app/app.config.ts','config-alt','app/app-config.ts (alternative config)')(format='.')
123121

124122
:marked
125-
One of the key benefits of defining a configuration object class, is
126-
strong static checking relative to configuration property names and their types.
127-
The Dart [cascade operator][cascade-op] provides a convenient means of initializing
128-
the configuration object. Use of the cascaded object initialization idiom
123+
Defining a configuration class has a few benefits. One key benefit
124+
is strong static checking: we'll be warned early if we misspell a property
125+
name or assign it a value of the wrong type.
126+
The Dart [cascade notation][cascade] (`..`) provides a convenient means of initializing
127+
a configuration object.
128+
129+
Use of the cascaded initialization idiom
129130
prevents us from defining our configuration object instance as `const`.
130-
As a consequencem we cannot declare a [value provider](#value-provider),
131-
but a [factory provider](#factory-provider) does the trick &mdash; as
132-
we illustrate by providing and injecting the configuration object in our
131+
As a consequence, we cannot declare a [value provider](#value-provider),
132+
but a [factory provider](#factory-provider) does the trick.
133+
134+
We illustrate this below by providing and injecting the configuration object in our
133135
top-level `AppComponent`:
134136

135-
[cascade-op]: https://www.dartlang.org/docs/dart-up-and-running/ch02.html#cascade
137+
[cascade]: https://www.dartlang.org/docs/dart-up-and-running/ch02.html#cascade
136138

137139
+makeExcerpt('lib/app_component.dart','providers')
138140
+makeExcerpt('lib/app_component.dart','ctor')

public/docs/ts/latest/guide/dependency-injection.jade

+14-12
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ p Run the #[+liveExampleLink2()].
3434

3535
Our `Car` needs an engine and tires. Instead of asking for them,
3636
the `Car` constructor instantiates its own copies from
37-
the very specific classes, `Engine` and `Tires`.
37+
the very specific classes `Engine` and `Tires`.
3838

3939
What if the `Engine` class evolves and its constructor requires a parameter?
4040
Our `Car` is broken and stays broken until we rewrite it along the lines of
@@ -422,9 +422,9 @@ block injectable-not-always-needed-in-ts
422422

423423
We *can* add it if we really want to. It isn't necessary because the
424424
`HeroesComponent` is already marked with `@Component`, and this
425-
!{_decorator} class (like `@Directive` and `@Pipe` which we will study later
426-
on) is a subtype of <a href="#{injMetaUrl}">InjectableMetadata</a>. It is in
427-
fact <a href="#{injMetaUrl}">InjectableMetadata</a> #{_decorator}s that
425+
!{_decorator} class (like `@Directive` and `@Pipe`, which we'll learn about later)
426+
is a subtype of <a href="#{injMetaUrl}">InjectableMetadata</a>. It is in
427+
fact `InjectableMetadata` #{_decorator}s that
428428
identify a class as a target for instantiation by an injector.
429429

430430
block ts-any-decorator-will-do
@@ -701,7 +701,7 @@ block dart-diff-const-metadata-ctor
701701
+makeTabs(
702702
`dependency-injection/ts/app/heroes/heroes.component.ts,
703703
dependency-injection/ts/app/heroes/heroes.component.1.ts`,
704-
null,
704+
',full',
705705
`app/heroes/heroes.component (v3),
706706
app/heroes/heroes.component (v2)`,
707707
stylePattern)
@@ -779,7 +779,8 @@ block what-should-we-use-as-token
779779
:marked
780780
### OpaqueToken
781781

782-
The solution is to define and use an !{opaquetoken}.
782+
One solution to choosing a provider token for non-class dependencies is
783+
to define and use an !{opaquetoken}.
783784
The definition looks like this:
784785

785786
+makeExample('dependency-injection/ts/app/app.config.ts','token')(format='.')
@@ -798,8 +799,8 @@ block what-should-we-use-as-token
798799
- var configType = _docsFor == 'dart' ? '<code>Map</code>' : '<code>AppConfig</code>'
799800
.l-sub-section
800801
:marked
801-
Although it plays no role in dependency injection,
802-
the !{configType} interface supports typing of the configuration object within the class.
802+
Although the !{configType} interface plays no role in dependency injection,
803+
it supports typing of the configuration object within the class.
803804

804805
block dart-map-alternative
805806
:marked
@@ -813,16 +814,17 @@ block dart-map-alternative
813814

814815
Our `HeroService` *requires* a `Logger`, but what if it could get by without
815816
a logger?
816-
As is illustrated next, we can indicate that to the dependency injection
817-
framework by marking the constructor's argument as optional.
817+
We can tell Angular that the dependency is optional by annotating the
818+
constructor argument with `@Optional()`:
818819

819820
+ifDocsFor('ts')
820821
+makeExample('dependency-injection/ts/app/providers.component.ts','import-optional', '')
821822
+makeExample('dependency-injection/ts/app/providers.component.ts','provider-10-ctor', '')(format='.')
822823

823824
:marked
824-
Be prepared for a null logger. If we don't register one somewhere up the line,
825-
the injector will inject `null`.
825+
When using `@Optional()`, our code must be prepared for a null value. If we
826+
don't register a logger somewhere up the line, the injector will set the
827+
value of `logger` to null.
826828

827829
.l-main-section
828830
:marked

0 commit comments

Comments
 (0)