Skip to content

Commit de31aca

Browse files
naomiblackmhevery
authored andcommitted
docs(di): Edits to DI.
Closes angular#1420
1 parent 97220dd commit de31aca

File tree

13 files changed

+113
-107
lines changed

13 files changed

+113
-107
lines changed

modules/angular2/di.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @module
33
* @public
44
* @description
5-
* This is a description
5+
* The `di` module provides dependency injection container services.
66
*/
77

88
export {Inject, InjectPromise, InjectLazy, Injectable, Optional, DependencyAnnotation} from './src/di/annotations';

modules/angular2/di_annotations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
* @module
33
* @public
44
* @description
5-
* This is a description
5+
* Annotations which controll how the dependencies are resolved by the [Injector].
66
*/
77

modules/angular2/di_errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
* @module
33
* @public
44
* @description
5-
* This is a description
5+
* Errors thrown by the [Injector].
66
*/
77

modules/angular2/directives.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @module
33
* @public
44
* @description
5-
* Describe the directives module here
5+
* Common directives shipped with Angualr.
66
*/
77

88
export * from './src/directives/class';

modules/angular2/src/core/compiler/compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class CompilerCache {
4141
}
4242

4343
/**
44-
* @exportedAs angular2/template
44+
* @exportedAs angular2/view
4545
*/
4646
@Injectable()
4747
export class Compiler {

modules/angular2/src/core/compiler/view_container.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as vhModule from './view_hydrator';
1111
import {Renderer} from 'angular2/src/render/api';
1212

1313
/**
14-
* @exportedAs angular2/template
14+
* @exportedAs angular2/view
1515
*/
1616
export class ViewContainer {
1717
viewFactory: vfModule.ViewFactory;

modules/angular2/src/di/annotations.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {CONST} from "angular2/src/facade/lang";
22

33
/**
4-
* A parameter annotation that creates a synchronous eager dependency.
4+
* A parameter annotation that specifies a dependency.
55
*
66
* ```
77
* class AComponent {
@@ -20,7 +20,7 @@ export class Inject {
2020
}
2121

2222
/**
23-
* A parameter annotation that creates an asynchronous eager dependency.
23+
* A parameter annotation that specifies a [Promise] of a dependency.
2424
*
2525
* ```
2626
* class AComponent {
@@ -62,7 +62,9 @@ export class InjectLazy {
6262
}
6363

6464
/**
65-
* A parameter annotation that marks a dependency as optional. (Injects `null` if not found.)
65+
* A parameter annotation that marks a dependency as optional. [Injector] provides `null` if the dependency is not
66+
* found.
67+
*
6668
* ```
6769
* class AComponent {
6870
* constructor(@Optional() aService:MyService) {
@@ -82,8 +84,7 @@ export class Optional {
8284
/**
8385
* `DependencyAnnotation` is used by the framework to extend DI.
8486
*
85-
* Only annotations implementing `DependencyAnnotation` will be added
86-
* to the list of dependency properties.
87+
* Only annotations implementing `DependencyAnnotation` are added to the list of dependency properties.
8788
*
8889
* For example:
8990
*
@@ -118,8 +119,8 @@ export class DependencyAnnotation {
118119
}
119120

120121
/**
121-
* A marker annotation that marks a class as available to `Injector`s for creation. Used by tooling for generating
122-
* constructor stubs.
122+
* A marker annotation that marks a class as available to `Injector` for creation. Used by tooling for
123+
* generating constructor stubs.
123124
*
124125
* ```
125126
* class NeedsService {

modules/angular2/src/di/binding.js

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ var _EMPTY_LIST = []; // TODO: make const when supported
5050
export class Binding {
5151

5252
/**
53-
* Token used when retriving this binding. Usually the [Type].
53+
* Token used when retrieving this binding. Usually the [Type].
5454
*/
5555
token;
5656

5757
/**
58-
* Bind an interface to an implementation / subclass.
58+
* Binds an interface to an implementation / subclass.
5959
*
6060
* ## Example
6161
*
62-
* Becuse `toAlias` and `toClass` are often confused the example contains both use cases for easy comparison.
62+
* Becuse `toAlias` and `toClass` are often confused, the example contains both use cases for easy comparison.
6363
*
6464
* ```javascript
6565
*
@@ -86,7 +86,7 @@ export class Binding {
8686
toClass:Type;
8787

8888
/**
89-
* Bind a key to a value.
89+
* Binds a key to a value.
9090
*
9191
* ## Example
9292
*
@@ -101,10 +101,10 @@ export class Binding {
101101
toValue;
102102

103103
/**
104-
* Bind a key to an alias of an existing key.
104+
* Binds a key to the alias for an existing key.
105105
*
106-
* An alias means that we will return the same instance as if the alias token was used. (This is in contrast to
107-
* `toClass` where a separet instance of `toClass` will be returned.)
106+
* An alias means that [Injector] returns the same instance as if the alias token was used. This is in contrast to
107+
* `toClass` where a separate instance of `toClass` is returned.
108108
*
109109
* ## Example
110110
*
@@ -127,15 +127,15 @@ export class Binding {
127127
*
128128
* expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
129129
* expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
130-
130+
*
131131
* expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
132132
* expect(injectorClass.get(Vehicle) instanceof Car).toBe(true);
133133
* ```
134134
*/
135135
toAlias;
136136

137137
/**
138-
* Bind a key to a function which computes the value.
138+
* Binds a key to a function which computes the value.
139139
*
140140
* ## Example
141141
*
@@ -153,7 +153,7 @@ export class Binding {
153153
toFactory:Function;
154154

155155
/**
156-
* Bind a key to a function which computes the value asynchronously.
156+
* Binds a key to a function which computes the value asynchronously.
157157
*
158158
* ## Example
159159
*
@@ -170,15 +170,17 @@ export class Binding {
170170
* injector.asyncGet(String).then((v) => expect(v).toBe('Value: 3'));
171171
* ```
172172
*
173-
* The interesting thing to note is that event thougt `Numeber` has an async factory, the `String` factory
174-
* function takes the resolved value. This shows that the [Injector] delays executing of the `String` factory
175-
* until after the `Number` is resolved. This can only be done if the `token` is retrive
173+
* The interesting thing to note is that event though `Number` has an async factory, the `String` factory
174+
* function takes the resolved value. This shows that the [Injector] delays executing the `String` factory
175+
* until after the `Number` is resolved. This can only be done if the `token` is retrieved using the
176+
* [Injector.asyncGet] API.
177+
*
176178
*/
177179
toAsyncFactory:Function;
178180

179181
/**
180-
* Used in conjunction with `toFactory` or `toAsyncFactory` and specifies the `token`s which should be injected
181-
* into the factory function.
182+
* Used in conjunction with `toFactory` or `toAsyncFactory` and specifies a set of dependencies (as `token`s) which
183+
* should be injected into the factory function.
182184
*
183185
* ## Example
184186
*
@@ -216,7 +218,9 @@ export class Binding {
216218
}
217219

218220
/**
219-
*
221+
* Converts the [Binding] into [ResolvedBinding].
222+
*
223+
* [Injector] internaly only uses [ResolvedBindings], [Binding] contains convenience sugar.
220224
*/
221225
resolve(): ResolvedBinding {
222226
var factoryFn:Function;
@@ -250,29 +254,31 @@ export class Binding {
250254
}
251255

252256
/**
253-
* An internal resolved representaion of a [Binding] used by [Injector].
254-
*
255-
* A [Binding] is resolved when it has a factory fonction. Binding to a class, alias, or value, are just convenience
256-
* methods, as [Injector] only operates on calling factory functions.
257+
* An internal resolved representation of a [Binding] used by the [Injector].
258+
*
259+
* A [Binding] is resolved when it has a factory function. Binding to a class, alias, or value, are just convenience
260+
* methods, as [Injector] only operates on calling factory functions.
261+
*
262+
* @exportedAs angular2/di
257263
*/
258264
export class ResolvedBinding {
259265
/**
260266
* A key, usually a [Type].
261267
*/
262268
key:Key;
263-
269+
264270
/**
265-
* Factory function which can return an instance of [key].
271+
* Factory function which can return an instance of represented by a [key].
266272
*/
267273
factory:Function;
268-
274+
269275
/**
270276
* Arguments (dependencies) to the [factory] function.
271277
*/
272278
dependencies:List<Dependency>;
273-
279+
274280
/**
275-
* Specifies if the [factory] function returns an [Promise]
281+
* Specifies whether the [factory] function returns a [Promise].
276282
*/
277283
providedAsPromise:boolean;
278284

@@ -285,7 +291,9 @@ export class ResolvedBinding {
285291
}
286292

287293
/**
288-
* Provides fluent API for imperative construction of [Binding] objects. (JavaScript only.)
294+
* Provides an API for imperatively constructing [Binding]s.
295+
*
296+
* This is only relevant for JavaScript.
289297
*
290298
* @exportedAs angular2/di
291299
*/
@@ -294,7 +302,8 @@ export function bind(token):BindingBuilder {
294302
}
295303

296304
/**
297-
* Helper class for [bind] function.
305+
* Helper class for the [bind] function.
306+
*
298307
* @exportedAs angular2/di
299308
*/
300309
export class BindingBuilder {
@@ -305,11 +314,11 @@ export class BindingBuilder {
305314
}
306315

307316
/**
308-
* Bind an interface to an implementation / subclass.
317+
* Binds an interface to an implementation / subclass.
309318
*
310319
* ## Example
311320
*
312-
* Becuse `toAlias` and `toClass` are often confused the example contains both use cases for easy comparison.
321+
* Because `toAlias` and `toClass` are often confused, the example contains both use cases for easy comparison.
313322
*
314323
* ```javascript
315324
*
@@ -338,7 +347,7 @@ export class BindingBuilder {
338347
}
339348

340349
/**
341-
* Bind a key to a value.
350+
* Binds a key to a value.
342351
*
343352
* ## Example
344353
*
@@ -355,14 +364,14 @@ export class BindingBuilder {
355364
}
356365

357366
/**
358-
* Bind a key to an alias of an existing key.
367+
* Binds a key to the alias for an existing key.
359368
*
360369
* An alias means that we will return the same instance as if the alias token was used. (This is in contrast to
361370
* `toClass` where a separet instance of `toClass` will be returned.)
362371
*
363372
* ## Example
364373
*
365-
* Becuse `toAlias` and `toClass` are often confused the example contains both use cases for easy comparison.
374+
* Becuse `toAlias` and `toClass` are often confused, the example contains both use cases for easy comparison.
366375
*
367376
* ```javascript
368377
*
@@ -381,7 +390,7 @@ export class BindingBuilder {
381390
*
382391
* expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
383392
* expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
384-
393+
*
385394
* expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
386395
* expect(injectorClass.get(Vehicle) instanceof Car).toBe(true);
387396
* ```
@@ -391,7 +400,7 @@ export class BindingBuilder {
391400
}
392401

393402
/**
394-
* Bind a key to a function which computes the value.
403+
* Binds a key to a function which computes the value.
395404
*
396405
* ## Example
397406
*
@@ -413,7 +422,7 @@ export class BindingBuilder {
413422
}
414423

415424
/**
416-
* Bind a key to a function which computes the value asynchronously.
425+
* Binds a key to a function which computes the value asynchronously.
417426
*
418427
* ## Example
419428
*
@@ -429,9 +438,10 @@ export class BindingBuilder {
429438
* injector.asyncGet(String).then((v) => expect(v).toBe('Value: 3'));
430439
* ```
431440
*
432-
* The interesting thing to note is that event thougt `Numeber` has an async factory, the `String` factory
441+
* The interesting thing to note is that event though `Number` has an async factory, the `String` factory
433442
* function takes the resolved value. This shows that the [Injector] delays executing of the `String` factory
434-
* until after the `Number` is resolved. This can only be done if the `token` is retrive
443+
* until after the `Number` is resolved. This can only be done if the `token` is retrieved using the
444+
* [Injector.asyncGet] API.
435445
*/
436446
toAsyncFactory(factoryFunction:Function, dependencies:List = null):Binding {
437447
return new Binding(this.token, {

0 commit comments

Comments
 (0)