Skip to content

Commit e819e97

Browse files
committed
docs: expose more API to public, document QueryList
1 parent f149ae7 commit e819e97

File tree

11 files changed

+160
-14
lines changed

11 files changed

+160
-14
lines changed

modules/angular2/src/core/annotations/di.js

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ import {CONST} from 'angular2/src/facade/lang';
22
import {DependencyAnnotation} from 'angular2/di';
33

44
/**
5-
* The directive can inject an emitter function that would emit events onto the
6-
* directive host element.
5+
* Specifies that a function for emitting events should be injected.
6+
*
7+
* NOTE: This is changing pre 1.0.
8+
*
9+
* The directive can inject an emitter function that would emit events onto the directive host element.
10+
*
11+
* @exportedAs angular2/annotations
712
*/
813
export class EventEmitter extends DependencyAnnotation {
914
eventName: string;
15+
1016
@CONST()
1117
constructor(eventName) {
1218
super();
@@ -19,8 +25,13 @@ export class EventEmitter extends DependencyAnnotation {
1925
}
2026

2127
/**
22-
* The directive can inject a property setter that would allow setting this property on the
23-
* host element
28+
* Specifies that a function for setting host properties should be injected.
29+
*
30+
* NOTE: This is changing pre 1.0.
31+
*
32+
* The directive can inject a property setter that would allow setting this property on the host element.
33+
*
34+
* @exportedAs angular2/annotations
2435
*/
2536
export class PropertySetter extends DependencyAnnotation {
2637
propName: string;
@@ -36,7 +47,32 @@ export class PropertySetter extends DependencyAnnotation {
3647
}
3748

3849
/**
39-
* The directive can inject the value of an attribute of the host element
50+
* Specifies that a constant attribute value should be injected.
51+
*
52+
* The directive can inject constant string literals of host element attributes.
53+
*
54+
* ## Example
55+
*
56+
* suppose we have an `<input>` element and would like to know its `type`.
57+
*
58+
* ```html
59+
* <input type="text">
60+
* ```
61+
*
62+
* A decorator could inject string literal `text` like so:
63+
*
64+
* ```javascript
65+
* @Decorator({
66+
* selector: `input'
67+
* })
68+
* class InputDecorator {
69+
* constructor(@Attribute('type') type) {
70+
* // type would be `text` in this example
71+
* }
72+
* }
73+
* ```
74+
*
75+
* @exportedAs angular2/annotations
4076
*/
4177
export class Attribute extends DependencyAnnotation {
4278
attributeName: string;
@@ -56,7 +92,11 @@ export class Attribute extends DependencyAnnotation {
5692
}
5793

5894
/**
59-
* The directive can inject an query that would reflect a list of ancestor directives
95+
* Specifies that a [QueryList] should be injected.
96+
*
97+
* See: [QueryList] for usage.
98+
*
99+
* @exportedAs angular2/annotations
60100
*/
61101
export class Query extends DependencyAnnotation {
62102
directive;

modules/angular2/src/core/compiler/query_list.dart renamed to modules/angular2/src/core/compiler/base_query_list.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import 'dart:collection';
1010
* In the future this class will implement an Observable interface.
1111
* For now it uses a plain list of observable callbacks.
1212
*/
13-
class QueryList extends Object with IterableMixin<Directive> {
13+
class BaseQueryList extends Object with IterableMixin<Directive> {
1414
List<Directive> _results;
1515
List _callbacks;
1616
bool _dirty;
1717

18-
QueryList(): _results = [], _callbacks = [], _dirty = false;
18+
BaseQueryList(): _results = [], _callbacks = [], _dirty = false;
1919

2020
Iterator<Directive> get iterator => _results.iterator;
2121

modules/angular2/src/core/compiler/query_list.es6 renamed to modules/angular2/src/core/compiler/base_query_list.es6

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import {Directive} from 'angular2/src/core/annotations/annotations';
77
*
88
* In the future this class will implement an Observable interface.
99
* For now it uses a plain list of observable callbacks.
10+
*
11+
* @exportedAs angular2/view
1012
*/
11-
export class QueryList {
13+
export class BaseQueryList {
1214
_results: List<Directive>;
1315
_callbacks;
1416
_dirty;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ export class CompilerCache {
4040
}
4141
}
4242

43-
43+
/**
44+
* @exportedAs angular2/template
45+
*/
4446
@Injectable()
4547
export class Compiler {
4648
_reader: DirectiveMetadataReader;

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import {Renderer} from 'angular2/src/render/api';
1010
import {ElementRef} from './element_injector';
1111
import {AppView} from './view';
1212

13-
13+
/**
14+
* @exportedAs angular2/view
15+
*/
1416
export class ComponentRef {
1517
location:ElementRef;
1618
instance:any;
@@ -34,6 +36,8 @@ export class ComponentRef {
3436
/**
3537
* Service for dynamically loading a Component into an arbitrary position in the internal Angular
3638
* application tree.
39+
*
40+
* @exportedAs angular2/view
3741
*/
3842
@Injectable()
3943
export class DynamicComponentLoader {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ var _undefined = new Object();
1919

2020
var _staticKeys;
2121

22+
/**
23+
* @exportedAs angular2/view
24+
*/
2225
export class ElementRef {
2326
elementInjector:ElementInjector;
2427

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import {BaseQueryList} from './base_query_list';
2+
3+
/**
4+
* An iterable live list of components in the Light DOM.
5+
*
6+
* Injectable Objects that contains a live list of child directives in the light DOM of a directive.
7+
* The directives are kept in depth-first pre-order traversal of the DOM.
8+
*
9+
* The `QueryList` is iterable, therefore it can be used in both javascript code with `for..of` loop as well as in
10+
* template with `*for="of"` viewport.
11+
*
12+
* NOTE: In the future this class will implement an `Observable` interface. For now it uses a plain list of observable
13+
* callbacks.
14+
*
15+
* # Example:
16+
*
17+
* Assume that `<tabs>` component would like to get a list its children which are `<pane>` components as shown in this
18+
* example:
19+
*
20+
* ```html
21+
* <tabs>
22+
* <pane title="Overview">...</pane>
23+
* <pane *for="o in objects" [title]="o.title">{{o.text}}</pane>
24+
* </tabs>
25+
* ```
26+
*
27+
* In the above example the list of `<tabs>` elements needs to get a list of `<pane>` elements so that it could render
28+
* tabs with the correct titles and in the correct order.
29+
*
30+
* A possible solution would be for a `<pane>` to inject `<tabs>` component and then register itself with `<tabs>`
31+
* component's on `hydrate` and deregister on `dehydrate` event. While a reasonable approach, this would only work
32+
* partialy since `*for` could rearange the list of `<pane>` components which would not be reported to `<tabs>`
33+
* component and thus the list of `<pane>` componets would be out of sync with respect to the list of `<pane>` elements.
34+
*
35+
* A prefferd solution is to inject a `QueryList` which is a live list of directives in the component`s light DOM.
36+
*
37+
* ```javascript
38+
* @Component({
39+
* selector: 'tabs'
40+
* })
41+
* @View({
42+
* template: `
43+
* <ul>
44+
* <li *for="pane of panes">{{pane.title}}</li>
45+
* </ul>
46+
* <content></content>
47+
* `
48+
* })
49+
* class Tabs {
50+
* panes: QueryList<Pane>
51+
*
52+
* constructor(@Query(Pane) panes:QueryList<Pane>) {
53+
* this.panes = panes;
54+
* }
55+
* }
56+
*
57+
* @Component({
58+
* selector: 'pane',
59+
* properties: ['title']
60+
* })
61+
* @View(...)
62+
* class Pane {
63+
* title:string;
64+
* }
65+
* ```
66+
*
67+
* @exportedAs angular2/view
68+
*/
69+
export class QueryList extends BaseQueryList {
70+
71+
/**
72+
*/
73+
onChange(callback) {
74+
return super.onChange(callback);
75+
}
76+
77+
/**
78+
*/
79+
removeCallback(callback) {
80+
return super.removeCallback(callback);
81+
}
82+
83+
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import * as renderApi from 'angular2/src/render/api';
1313
/**
1414
* Const of making objects: http://jsperf.com/instantiate-size-of-object
1515
*
16-
* @exportedAs angular2/template
1716
*/
1817
@IMPLEMENTS(ChangeDispatcher)
1918
// TODO(tbosch): this is not supported in dart2js (no '.' is allowed)
@@ -288,7 +287,6 @@ export class AppView {
288287

289288
/**
290289
*
291-
* @exportedAs angular2/template
292290
*/
293291
export class AppProtoView {
294292
elementBinders:List<ElementBinder>;

modules/angular2/src/test_lib/test_bed.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_meta
1818
import {queryView, viewRootNodes, el} from './utils';
1919
import {instantiateType, getTypeOf} from './lang_utils';
2020

21-
21+
/**
22+
* @exportedAs angular2/test
23+
*/
2224
export class TestBed {
2325
_injector: Injector;
2426

modules/angular2/src/test_lib/test_injector.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export function createTestInjector(bindings: List) {
142142
* @param {Array} tokens
143143
* @param {Function} fn
144144
* @return {FunctionWithParamTokens}
145+
* @exportedAs angular2/test
145146
*/
146147
export function inject(tokens: List, fn: Function) {
147148
return new FunctionWithParamTokens(tokens, fn);

0 commit comments

Comments
 (0)