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

Commit

Permalink
feat(Core): Add @visibleForTemplate, and document it in the CHANGELOG.
Browse files Browse the repository at this point in the history
Closes #930.

PiperOrigin-RevId: 212358660
  • Loading branch information
matanlurey authored and leonsenft committed Sep 11, 2018
1 parent d89866f commit c91efa5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
41 changes: 41 additions & 0 deletions angular/CHANGELOG.md
Expand Up @@ -38,6 +38,46 @@
from the annotated component as type arguments to its children. See its
documentation for details.

* [#930][]: Added `@visibleForTemplate` to `package:angular/meta.dart`. This
is an _optional_ annotation that may be used to annotate elements that
should _only_ be used from within generated code (i.e. a `.template.dart`).
It is a compile-time _hint_, which may be treated as a failing build, to use
annotated elements outside of the component or template.

This annotation is intended to give component authors more control in
specifying the public API of their component(s), especially coupled with the
fact that AngularDart requires all members to be public to be reachable from
generated code. For example, `c` and `ngAfterChanges` are only accessible
from `CalculatorComponent` (or its template) in the following:

```dart
import 'package:angular/angular.dart';
import 'package:angular/meta.dart';
@Component(
selector: 'calculator-comp',
template: '{{a}} + {{b}} = {{c}}',
)
class CalculatorComponent implements AfterChanges {
@Input()
num a = 0;
@Input()
num b = 0;
@visibleForTemplate
num c = 0;
@override
@visibleForTemplate
void ngAfterChanges() {
c = a + b;
}
}
```

**NOTE**: This feature is only _enforced_ in SDK: `>=2.1.0-dev.3.1`.

### Bug fixes

* [#1538][]: A compile-time error is reported if the `@deferred` template
Expand Down Expand Up @@ -117,6 +157,7 @@

[#434]: https://github.com/dart-lang/angular/issues/434
[#880]: https://github.com/dart-lang/angular/issues/880
[#930]: https://github.com/dart-lang/angular/issues/930
[#1500]: https://github.com/dart-lang/angular/issues/1500
[#1502]: https://github.com/dart-lang/angular/issues/1502
[#1538]: https://github.com/dart-lang/angular/issues/1538
Expand Down
1 change: 1 addition & 0 deletions angular/lib/meta.dart
Expand Up @@ -8,6 +8,7 @@ library angular.meta;
import 'dart:html';

import 'package:meta/meta.dart';
export 'src/meta.dart' show visibleForTemplate;

/// Wraps a typed [callback] with a single parameter of type [A].
///
Expand Down
7 changes: 0 additions & 7 deletions angular/lib/src/meta.dart
@@ -1,13 +1,6 @@
// **DO NOT CHANGE**. The analyzer looks for this _specific name_.
library angular.meta;

// Work in progress.
//
// - https://github.com/dart-lang/angular/issues/930
// - https://github.com/dart-lang/sdk/issues/33353
//
// Once this is enabled we will export it from `angular.dart`.

/// Used to annotate a class, field, or method that is public for template use.
///
/// An annotated element may be referenced in the _same_ Dart library, or in
Expand Down

0 comments on commit c91efa5

Please sign in to comment.