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

Commit a28000a

Browse files
committed
incorporate more comments from thso
1 parent e35e741 commit a28000a

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

public/docs/_examples/dependency-injection/dart/lib/car/car_creations.dart

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// #docplaster
12
// Examples with car and engine variations
23
import 'car.dart';
34

@@ -18,6 +19,8 @@ class Engine2 implements Engine {
1819

1920
Engine2(this.cylinders);
2021
}
22+
23+
// Later, where the car is created...
2124
//#enddocregion car-ctor-instantiation-with-param
2225

2326
Car superCar() {
@@ -39,6 +42,8 @@ class MockEngine extends Engine {
3942
class MockTires extends Tires {
4043
String make = 'YokoGoodStone';
4144
}
45+
46+
// Later, where the car is created for testing...
4247
//#enddocregion car-ctor-instantiation-with-mocks
4348
Car testCar() {
4449
//#docregion car-ctor-instantiation-with-mocks

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ include ../_util-fns
160160
:marked
161161
We supply two arguments to the `Provider` constructor.
162162
+includeShared('{ts}', 'providers-provide-4-2')
163+
:marked
164+
The second is a named parameter, such as `useClass`,
165+
that we can think of as a *recipe* for creating the dependency value.
166+
There are many ways to create dependency values... and many ways to write a recipe.
163167
+includeShared('{ts}', 'providers-alternative-1')
164168
+makeExample('dependency-injection/dart/lib/providers_component.dart','providers-4')
165169
.callout.is-helpful
@@ -212,9 +216,7 @@ p <b>[PENDING: How about a better name than ProviderComponent8?]</b>
212216
+includeShared('{ts}', 'tokens-non-class-deps-1')
213217
p <b>[PENDING: What's the Dart equivalent of "object hash"? How can we shorten/improve this code?]</b>
214218
+makeExample('dependency-injection/dart/lib/app_config.dart','config','lib/app_config.dart (excerpt)')(format='.')
215-
+includeShared('{ts}', 'tokens-non-class-deps-2')
216-
p <b>[PENDING: That's not right. That text is from the TypeScript version. How should the Dart code/text be different?]</b>
217-
p <b>[PENDING: TypeScript has a whole section here on "Interfaces aren't valid tokens". But they are in Dart!]</b>
219+
p <b>[PENDING: add explanatory/transition text here]</b>
218220
.callout.is-helpful
219221
header Dart difference: Interfaces are valid tokens
220222
:marked
@@ -226,7 +228,7 @@ p <b>[PENDING: TypeScript has a whole section here on "Interfaces aren't valid t
226228
(usually, that's the name of an abstract class)
227229
as the first argument.
228230
+includeShared('{ts}', 'tokens-string-1')
229-
p <b>[PENDING: Where did CONFIG_HASH come from? (lib/app_config.dart) Why does the code use that instead of CONFIG? (only matters if we keep the code, I suppose)]</b>
231+
p <b>[PENDING: Why is that "fortunate"? String tokens seem UNfortunate... Also, where did CONFIG_HASH come from? (lib/app_config.dart) Why does the code use that instead of CONFIG? (only matters if we keep the code, I suppose)]</b>
230232
+makeExample('dependency-injection/dart/lib/providers_component.dart','providers-9a')(format=".")
231233
+includeShared('{ts}', 'tokens-string-2')
232234
p <b>[PENDING: I don't like showing ProviderComponent9a. Also... can we make this code easier to read?]</b>

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

+12-15
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ include ../_util-fns
6161
if we can't swap in low-pressure tires during the test?
6262

6363
We have no control over the car's hidden dependencies.
64-
When we can't control the dependencies, a class become difficult to test.
64+
When we can't control the dependencies, a class becomes difficult to test.
6565

6666
How can we make `Car` more robust, flexible, and testable?
6767

@@ -196,17 +196,11 @@ include ../_util-fns
196196
It governs all the child components of this area.
197197
Our stripped down version has only one child, `HeroListComponent`,
198198
which displays a list of heroes.
199-
200-
.l-sub-section
201-
:marked
202-
Do we really need so many files? Of course not!
203-
We're going *beyond* the strictly necessary
204-
in order to illustrate patterns that work well in real applications.
205199
// #enddocregion di-2
206200
// #docregion di-3
207201
:marked
208202
Right now `HeroListComponent` gets heroes from `HEROES`, an in-memory collection
209-
defined in another file and imported by this component.
203+
defined in another file.
210204
That may suffice in the early stages of development, but it's far from ideal.
211205
As soon as we try to test this component or want to get our heroes data from a remote server,
212206
we'll have to change the implementation of `heroes` and
@@ -531,7 +525,8 @@ code-example(format, language="html").
531525
// #docregion providers-2
532526
- var lang = current.path[1]
533527
- var implements = lang == 'dart' ? 'implements' : 'looks and behaves like a '
534-
#{decoration}
528+
- var objectlike = lang == 'dart' ? '' : 'an object that behaves like '
529+
- var loggerlike = lang == 'dart' ? '' : 'We could provide a logger-like object. '
535530
:marked
536531
The `providers` array appears to hold a service class.
537532
In reality it holds an instance of the [Provider](/docs/ts/latest/api/core/Provider-class.html) class that can create that service.
@@ -540,8 +535,8 @@ code-example(format, language="html").
540535
The `Logger` class itself is an obvious and natural provider &mdash; it has the right shape and it's designed to be created.
541536
But it's not the only way.
542537

543-
We can configure the injector with alternative providers that can deliver an object that behaves like a `Logger`.
544-
We could provide a substitute class. We could provide a logger-like object.
538+
We can configure the injector with alternative providers that can deliver #{objectlike} a `Logger`.
539+
We could provide a substitute class. #{loggerlike}
545540
We could give it a provider that calls a logger factory function.
546541
Any of these approaches might be a good choice under the right circumstances.
547542

@@ -582,11 +577,13 @@ code-example(format, language="html").
582577
:marked
583578
The first is the [token](#token) that serves as the key for both locating a dependency value
584579
and registering the provider.
580+
// #enddocregion providers-provide-4-2
585581
582+
// Dart is different here (uses an optional parameter)
583+
:marked
586584
The second is a provider definition object,
587585
which we can think of as a *recipe* for creating the dependency value.
588586
There are many ways to create dependency values... and many ways to write a recipe.
589-
// #enddocregion providers-provide-4-2
590587
// #docregion providers-alternative-1
591588
:marked
592589
<a id="class-provider"></a>
@@ -762,15 +759,15 @@ code-example(format, language="html").
762759
These configuration objects aren't always instances of a class. They tend to be object hashes like this one:
763760
// #enddocregion tokens-non-class-deps-1
764761
+makeExample('dependency-injection/ts/app/app.config.ts','config','app/app-config.ts (excerpt)')(format='.')
765-
// #docregion tokens-non-class-deps-2
762+
763+
// TypeScript only?
766764
:marked
767765
We'd like to make this `config` object available for injection.
768766
We know we can register an object with a [value provider](#value-provider).
769767
But what do we use for the token?
770768
We don't have a class to serve as a token. There is no `Config` class.
771-
// #enddocregion tokens-non-class-deps-2
772769

773-
// begin Typescript only
770+
// Typescript only
774771
<a id="interface"></a>
775772
:marked
776773
### Interfaces aren't valid tokens

0 commit comments

Comments
 (0)