Skip to content
This repository was archived by the owner on Sep 16, 2022. It is now read-only.

Commit c91efa5

Browse files
matanlureyleonsenft
authored andcommitted
feat(Core): Add @visibleForTemplate, and document it in the CHANGELOG.
Closes #930. PiperOrigin-RevId: 212358660
1 parent d89866f commit c91efa5

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

angular/CHANGELOG.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,46 @@
3838
from the annotated component as type arguments to its children. See its
3939
documentation for details.
4040
41+
* [#930][]: Added `@visibleForTemplate` to `package:angular/meta.dart`. This
42+
is an _optional_ annotation that may be used to annotate elements that
43+
should _only_ be used from within generated code (i.e. a `.template.dart`).
44+
It is a compile-time _hint_, which may be treated as a failing build, to use
45+
annotated elements outside of the component or template.
46+
47+
This annotation is intended to give component authors more control in
48+
specifying the public API of their component(s), especially coupled with the
49+
fact that AngularDart requires all members to be public to be reachable from
50+
generated code. For example, `c` and `ngAfterChanges` are only accessible
51+
from `CalculatorComponent` (or its template) in the following:
52+
53+
```dart
54+
import 'package:angular/angular.dart';
55+
import 'package:angular/meta.dart';
56+
57+
@Component(
58+
selector: 'calculator-comp',
59+
template: '{{a}} + {{b}} = {{c}}',
60+
)
61+
class CalculatorComponent implements AfterChanges {
62+
@Input()
63+
num a = 0;
64+
65+
@Input()
66+
num b = 0;
67+
68+
@visibleForTemplate
69+
num c = 0;
70+
71+
@override
72+
@visibleForTemplate
73+
void ngAfterChanges() {
74+
c = a + b;
75+
}
76+
}
77+
```
78+
79+
**NOTE**: This feature is only _enforced_ in SDK: `>=2.1.0-dev.3.1`.
80+
4181
### Bug fixes
4282
4383
* [#1538][]: A compile-time error is reported if the `@deferred` template
@@ -117,6 +157,7 @@
117157
118158
[#434]: https://github.com/dart-lang/angular/issues/434
119159
[#880]: https://github.com/dart-lang/angular/issues/880
160+
[#930]: https://github.com/dart-lang/angular/issues/930
120161
[#1500]: https://github.com/dart-lang/angular/issues/1500
121162
[#1502]: https://github.com/dart-lang/angular/issues/1502
122163
[#1538]: https://github.com/dart-lang/angular/issues/1538

angular/lib/meta.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ library angular.meta;
88
import 'dart:html';
99

1010
import 'package:meta/meta.dart';
11+
export 'src/meta.dart' show visibleForTemplate;
1112

1213
/// Wraps a typed [callback] with a single parameter of type [A].
1314
///

angular/lib/src/meta.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
// **DO NOT CHANGE**. The analyzer looks for this _specific name_.
22
library angular.meta;
33

4-
// Work in progress.
5-
//
6-
// - https://github.com/dart-lang/angular/issues/930
7-
// - https://github.com/dart-lang/sdk/issues/33353
8-
//
9-
// Once this is enabled we will export it from `angular.dart`.
10-
114
/// Used to annotate a class, field, or method that is public for template use.
125
///
136
/// An annotated element may be referenced in the _same_ Dart library, or in

0 commit comments

Comments
 (0)