Skip to content

Commit 3894595

Browse files
committed
refactor: Remove IQueryList
BREAKING CHANGE: Closes angular#3577
1 parent b783738 commit 3894595

File tree

4 files changed

+134
-90
lines changed

4 files changed

+134
-90
lines changed

modules/angular2/core.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';
1616
export {Compiler} from 'angular2/src/core/compiler/compiler';
1717

1818
export {AppViewManager} from 'angular2/src/core/compiler/view_manager';
19-
export {IQueryList} from 'angular2/src/core/compiler/interface_query';
2019
export {QueryList} from 'angular2/src/core/compiler/query_list';
2120
export {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader';
2221
export {LifeCycle} from 'angular2/src/core/life_cycle/life_cycle';

modules/angular2/src/core/compiler/interface_query.ts

Lines changed: 0 additions & 78 deletions
This file was deleted.

modules/angular2/src/core/compiler/query_list.dart

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,78 @@
11
library angular2.src.core.compiler.query_list;
22

33
import 'dart:collection';
4-
import './interface_query.dart';
54

65
/**
7-
* Injectable Objects that contains a live list of child directives in the light Dom of a directive.
6+
* An iterable and observable live list of components in the DOM.
7+
*
8+
* A QueryList contains a live list of child directives in the DOM of a directive.
89
* The directives are kept in depth-first pre-order traversal of the DOM.
910
*
10-
* In the future this class will implement an Observable interface.
11-
* For now it uses a plain list of observable callbacks.
11+
* The `QueryList` is iterable, therefore it can be used in both javascript code with `for..of` loop
12+
* as well as in template with `*ng-for="of"` directive.
13+
*
14+
* QueryList is updated as part of the change-detection cycle of a directive. Since change detection
15+
* happens after construction of a directive, QueryList will always be empty when observed in the
16+
* constructor.
17+
*
18+
*
19+
* NOTE: In the future this class will implement an `Observable` interface. For now it uses a plain
20+
* list of observable callbacks.
21+
*
22+
* # Example:
23+
*
24+
* Assume that `<tabs>` component would like to get a list its children which are `<pane>`
25+
* components as shown in this example:
26+
*
27+
* ```html
28+
* <tabs>
29+
* <pane title="Overview">...</pane>
30+
* <pane *ng-for="#o of objects" [title]="o.title">{{o.text}}</pane>
31+
* </tabs>
32+
* ```
33+
*
34+
* In the above example the list of `<tabs>` elements needs to get a list of `<pane>` elements so
35+
* that it could render tabs with the correct titles and in the correct order.
36+
*
37+
* A possible solution would be for a `<pane>` to inject `<tabs>` component and then register itself
38+
* with `<tabs>` component's on `hydrate` and deregister on `dehydrate` event. While a reasonable
39+
* approach, this would only work partialy since `*ng-for` could rearrange the list of `<pane>`
40+
* components which would not be reported to `<tabs>` component and thus the list of `<pane>`
41+
* components would be out of sync with respect to the list of `<pane>` elements.
42+
*
43+
* A preferred solution is to inject a `QueryList` which is a live list of directives in the
44+
* component`s light DOM.
45+
*
46+
* ```javascript
47+
* @Component(
48+
* selector: 'tabs'
49+
* )
50+
* @View(
51+
* template: `
52+
* <ul>
53+
* <li *ng-for="#pane of panes">{{pane.title}}</li>
54+
* </ul>
55+
* <content></content>
56+
* `
57+
* )
58+
* class Tabs {
59+
* QueryList<Pane> panes;
60+
*
61+
* constructor(@Query(Pane) QueryList<Pane> this.panes) { }
62+
* }
63+
*
64+
* @Component(
65+
* selector: 'pane',
66+
* properties: ['title']
67+
* )
68+
* @View(...)
69+
* class Pane {
70+
* String title;
71+
* }
72+
* ```
1273
*/
1374
class QueryList<T> extends Object
14-
with IterableMixin<T>
15-
implements IQueryList<T> {
75+
with IterableMixin<T> {
1676
List<T> _results = [];
1777
List _callbacks = [];
1878
bool _dirty = false;

modules/angular2/src/core/compiler/query_list.ts

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,77 @@
11
import {List, ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
2-
import {IQueryList} from './interface_query';
32

43
/**
5-
* Injectable Objects that contains a live list of child directives in the light Dom of a directive.
4+
* An iterable and observable live list of components in the DOM.
5+
*
6+
* A QueryList contains a live list of child directives in the DOM of a directive.
67
* The directives are kept in depth-first pre-order traversal of the DOM.
78
*
8-
* In the future this class will implement an Observable interface.
9-
* For now it uses a plain list of observable callbacks.
9+
* The `QueryList` is iterable, therefore it can be used in both javascript code with `for..of` loop
10+
* as well as in template with `*ng-for="of"` directive.
11+
*
12+
* QueryList is updated as part of the change-detection cycle of a directive. Since change detection
13+
* happens after construction of a directive, QueryList will always be empty when observed in the
14+
* constructor.
15+
*
16+
*
17+
* NOTE: In the future this class will implement an `Observable` interface. For now it uses a plain
18+
* list of observable callbacks.
19+
*
20+
* # Example:
21+
*
22+
* Assume that `<tabs>` component would like to get a list its children which are `<pane>`
23+
* components as shown in this example:
24+
*
25+
* ```html
26+
* <tabs>
27+
* <pane title="Overview">...</pane>
28+
* <pane *ng-for="#o of objects" [title]="o.title">{{o.text}}</pane>
29+
* </tabs>
30+
* ```
31+
*
32+
* In the above example the list of `<tabs>` elements needs to get a list of `<pane>` elements so
33+
* that it could render tabs with the correct titles and in the correct order.
34+
*
35+
* A possible solution would be for a `<pane>` to inject `<tabs>` component and then register itself
36+
* with `<tabs>` component's on `hydrate` and deregister on `dehydrate` event. While a reasonable
37+
* approach, this would only work partialy since `*ng-for` could rearrange the list of `<pane>`
38+
* components which would not be reported to `<tabs>` component and thus the list of `<pane>`
39+
* components would be out of sync with respect to the list of `<pane>` elements.
40+
*
41+
* A preferred solution is to inject a `QueryList` which is a live list of directives in the
42+
* component`s light DOM.
43+
*
44+
* ```javascript
45+
* @Component({
46+
* selector: 'tabs'
47+
* })
48+
* @View({
49+
* template: `
50+
* <ul>
51+
* <li *ng-for="#pane of panes">{{pane.title}}</li>
52+
* </ul>
53+
* <content></content>
54+
* `
55+
* })
56+
* class Tabs {
57+
* panes: QueryList<Pane>
58+
*
59+
* constructor(@Query(Pane) panes:QueryList<Pane>) {
60+
* this.panes = panes;
61+
* }
62+
* }
63+
*
64+
* @Component({
65+
* selector: 'pane',
66+
* properties: ['title']
67+
* })
68+
* @View(...)
69+
* class Pane {
70+
* title:string;
71+
* }
72+
* ```
1073
*/
11-
export class QueryList<T> implements IQueryList<T> {
74+
export class QueryList<T> {
1275
protected _results: List < T >= [];
1376
protected _callbacks: List < () => void >= [];
1477
protected _dirty: boolean = false;

0 commit comments

Comments
 (0)