diff --git a/ngast/lib/src/expression/micro/scanner.dart b/ngast/lib/src/expression/micro/scanner.dart index 93460a7f5f..34121b2706 100644 --- a/ngast/lib/src/expression/micro/scanner.dart +++ b/ngast/lib/src/expression/micro/scanner.dart @@ -55,8 +55,6 @@ class NgMicroScanner { return _scanLetAssignment(); case _NgMicroScannerState.scanLetIdentifier: return _scanLetIdentifier(); - default: - throw _unexpected(); } } diff --git a/ngast/lib/src/lexer.dart b/ngast/lib/src/lexer.dart index 150578bdf2..a33340b7b5 100644 --- a/ngast/lib/src/lexer.dart +++ b/ngast/lib/src/lexer.dart @@ -7,7 +7,7 @@ import 'token/tokens.dart'; /// Separates an Angular template into a series of lexical tokens. /// /// ## Example use -/// ```dart +/// ``` /// const NgLexer().tokenize('
Hello World!
'); /// ``` class NgLexer { diff --git a/ngast/lib/src/visitors/whitespace.dart b/ngast/lib/src/visitors/whitespace.dart index daa034b65b..75bd34c178 100644 --- a/ngast/lib/src/visitors/whitespace.dart +++ b/ngast/lib/src/visitors/whitespace.dart @@ -4,7 +4,7 @@ import 'recursive.dart'; /// Applies whitespace reduction to implement (`preserveWhitespace: false`). /// /// Use [visitAllRoot] to process root nodes: -/// ```dart +/// ``` /// var nodes = parse(template, sourceUrl: url); /// nodes = const MinimizeWhitespaceVisitor().visitAllRoot(nodes); /// ``` diff --git a/ngast/test/random_generator_test/random_tester.dart b/ngast/test/random_generator_test/random_tester.dart index 79577b91b7..09259de3ca 100644 --- a/ngast/test/random_generator_test/random_tester.dart +++ b/ngast/test/random_generator_test/random_tester.dart @@ -80,8 +80,6 @@ NgSimpleTokenType generateRandomSimple(State state) { case State.text: var i = rng.nextInt(textMap.length); return textMap[i]; - default: - return NgSimpleTokenType.unexpectedChar; } } @@ -144,8 +142,6 @@ String generateHtmlString() { sb.write('lorem ipsum'); } break; - default: - sb.write(''); } } return sb.toString(); diff --git a/ngcompiler/lib/v1/src/angular_compiler/analyzer/common.dart b/ngcompiler/lib/v1/src/angular_compiler/analyzer/common.dart index ba416f0b67..38958ef220 100644 --- a/ngcompiler/lib/v1/src/angular_compiler/analyzer/common.dart +++ b/ngcompiler/lib/v1/src/angular_compiler/analyzer/common.dart @@ -44,8 +44,8 @@ String? getTypeName(DartType type) { /// /// For example for the following code: /// ``` -/// const foo = const []; -/// const bar = const ['A string']; +/// const foo = []; +/// const bar = ['A string']; /// ``` /// /// ... both `foo` and `bar` should return the [DartType] for `String`. diff --git a/ngcompiler/lib/v1/src/angular_compiler/analyzer/di/dependencies.dart b/ngcompiler/lib/v1/src/angular_compiler/analyzer/di/dependencies.dart index 0feca37db9..e1b0b801ca 100644 --- a/ngcompiler/lib/v1/src/angular_compiler/analyzer/di/dependencies.dart +++ b/ngcompiler/lib/v1/src/angular_compiler/analyzer/di/dependencies.dart @@ -15,7 +15,7 @@ import 'tokens.dart'; /// Support for reading and parsing a class or function's "dependencies". /// /// For example, the following class and its constructor: -/// ```dart +/// ``` /// class FooService { /// FooService(BarService barService, [@Optional() @Inject(someToken) baz]); /// } diff --git a/ngcompiler/lib/v1/src/angular_compiler/analyzer/di/injector.dart b/ngcompiler/lib/v1/src/angular_compiler/analyzer/di/injector.dart index 09bc07272a..ea68d9a7eb 100644 --- a/ngcompiler/lib/v1/src/angular_compiler/analyzer/di/injector.dart +++ b/ngcompiler/lib/v1/src/angular_compiler/analyzer/di/injector.dart @@ -435,7 +435,7 @@ abstract class InjectorVisitor { /// Implement providing a new instance of [type], calling [constructor]. /// /// Any [dependencies] are expected to invoke local methods as appropriate: - /// ```dart + /// ``` /// refer('inject').call([refer('Dep1')]) /// ``` void visitProvideClass( @@ -461,7 +461,7 @@ abstract class InjectorVisitor { /// Implement providing [token] by calling [function]. /// /// Any [dependencies] are expected to invoke local methods as appropriate: - /// ```dart + /// ``` /// refer('inject').call([refer('Dep1')]) /// ``` void visitProvideFactory( diff --git a/ngcompiler/lib/v1/src/compiler/ir/model.dart b/ngcompiler/lib/v1/src/compiler/ir/model.dart index ee3a002c70..5d0ea65c25 100644 --- a/ngcompiler/lib/v1/src/compiler/ir/model.dart +++ b/ngcompiler/lib/v1/src/compiler/ir/model.dart @@ -324,10 +324,10 @@ class HtmlBinding implements BindingTarget { } class ClassBinding implements BindingTarget { - /// Name of the class binding, i.e. foo in [class.foo]='bar'. + /// Name of the class binding, i.e. foo in `[class.foo]='bar'`. /// - /// If name is null, then we treat this as a [className]='"foo"' or - /// [attr.class]='foo'. + /// If name is null, then we treat this as a `[className]='"foo"'` or + /// `[attr.class]='foo'`. final String? name; @override diff --git a/ngcompiler/lib/v1/src/compiler/output/dart_emitter.dart b/ngcompiler/lib/v1/src/compiler/output/dart_emitter.dart index ab08bb89fe..246fdc0c81 100644 --- a/ngcompiler/lib/v1/src/compiler/output/dart_emitter.dart +++ b/ngcompiler/lib/v1/src/compiler/output/dart_emitter.dart @@ -409,8 +409,6 @@ class _DartEmitterVisitor extends AbstractEmitterVisitor return '.addAll'; case o.BuiltinMethod.subscribeObservable: return 'listen'; - default: - throw StateError('Unknown builtin method: $method'); } } @@ -621,8 +619,6 @@ class _DartEmitterVisitor extends AbstractEmitterVisitor case o.BuiltinTypeName.voidName: typeStr = 'void'; break; - default: - throw StateError('Unsupported builtin type ${type.name}'); } if (type.modifiers.contains(o.TypeModifier.nullableModifier)) { final suffix = emitNullSafeSyntax ? '?' : '/*?*/'; diff --git a/ngcompiler/lib/v1/src/compiler/template_parser/ast_template_parser.dart b/ngcompiler/lib/v1/src/compiler/template_parser/ast_template_parser.dart index b09c2156c8..f851276224 100644 --- a/ngcompiler/lib/v1/src/compiler/template_parser/ast_template_parser.dart +++ b/ngcompiler/lib/v1/src/compiler/template_parser/ast_template_parser.dart @@ -1190,8 +1190,7 @@ String _getEventName(ast.EventAst event) => /// Visitor which filters elements that are not supported in angular templates. class _ElementFilter extends ast.RecursiveTemplateAstVisitor { - static const _securityUrl = - 'https://webdev.dartlang.org/angular/guide/security'; + static const _securityUrl = 'https://angulardart.xyz/guide/security'; @override ast.ElementAst? visitElement(ast.ElementAst astNode, [_]) { diff --git a/ngcompiler/lib/v1/src/compiler/view_compiler/expression_converter.dart b/ngcompiler/lib/v1/src/compiler/view_compiler/expression_converter.dart index b6bc3e133f..f2629c8a9e 100644 --- a/ngcompiler/lib/v1/src/compiler/view_compiler/expression_converter.dart +++ b/ngcompiler/lib/v1/src/compiler/view_compiler/expression_converter.dart @@ -151,7 +151,9 @@ class _AstToExpressionVisitor if (_metadata.template!.preserveWhitespace! || value.contains('\u00A0') || value.contains(ngSpace) || - !value.contains('\n')) return replaceNgSpace(value); + !value.contains('\n')) { + return replaceNgSpace(value); + } return replaceNgSpace(value.replaceAll('\n', '').trimLeft()); } @@ -161,7 +163,9 @@ class _AstToExpressionVisitor if (_metadata.template!.preserveWhitespace! || value.contains('\u00A0') || value.contains(ngSpace) || - !value.contains('\n')) return replaceNgSpace(value); + !value.contains('\n')) { + return replaceNgSpace(value); + } return replaceNgSpace(value.replaceAll('\n', '').trimRight()); } diff --git a/ngcompiler/lib/v1/src/compiler/view_compiler/ir/provider_source.dart b/ngcompiler/lib/v1/src/compiler/view_compiler/ir/provider_source.dart index ffabaa0ad9..3837341a4f 100644 --- a/ngcompiler/lib/v1/src/compiler/view_compiler/ir/provider_source.dart +++ b/ngcompiler/lib/v1/src/compiler/view_compiler/ir/provider_source.dart @@ -26,9 +26,9 @@ abstract class ProviderSource { /// Whether a dynamic `injectorGet(...)` is required to resolve this provider. /// /// For example: - /// ```dart - /// // DependencyService is dynamically required to resolve MyService. - /// _MyService = MyService(injectorGet(DependencyService)); + /// ``` + /// // DependencyService is dynamically required to resolve MyService. + /// _MyService = MyService(injectorGet(DependencyService)); /// ``` bool get hasDynamicDependencies => false; } diff --git a/ngcompiler/lib/v1/src/compiler/view_compiler/update_statement_visitor.dart b/ngcompiler/lib/v1/src/compiler/view_compiler/update_statement_visitor.dart index 34449c413d..506ae6ca10 100644 --- a/ngcompiler/lib/v1/src/compiler/view_compiler/update_statement_visitor.dart +++ b/ngcompiler/lib/v1/src/compiler/view_compiler/update_statement_visitor.dart @@ -269,9 +269,6 @@ o.Expression _sanitizedValue( case TemplateSecurityContext.resourceUrl: method = SafeHtmlAdapters.sanitizeResourceUrl; break; - default: - throw ArgumentError('internal error, unexpected ' - 'TemplateSecurityContext $securityContext.'); } return o.importExpr(method).callFn([renderValue]); } diff --git a/ngcompiler/lib/v1/src/compiler/view_compiler/view_builder.dart b/ngcompiler/lib/v1/src/compiler/view_compiler/view_builder.dart index d81debb1c7..2fb7d6debf 100644 --- a/ngcompiler/lib/v1/src/compiler/view_compiler/view_builder.dart +++ b/ngcompiler/lib/v1/src/compiler/view_compiler/view_builder.dart @@ -601,8 +601,6 @@ o.Constructor? _createViewConstructor(CompileView view) { // Host views have no constructor parameters, thus don't require an // explicit constructor. return null; - default: - throw StateError('Unsupported $ViewType: ${view.viewType}'); } } @@ -687,8 +685,6 @@ o.Expression _createParentClassExpr(CompileView view) { return o.importExpr(Views.embeddedView, typeParams: typeArgs); case ViewType.host: return o.importExpr(Views.hostView, typeParams: typeArgs); - default: - throw StateError('Unsupported $ViewType: ${view.viewType}'); } } @@ -907,8 +903,6 @@ o.Statement? _generateInitStatement(CompileView view) { // Host views should have exactly one root node. view.rootNodesOrViewContainers.single, ]).toStmt(); - default: - throw StateError('Unsupported $ViewType: ${view.viewType}'); } } diff --git a/ngdart/lib/angular.dart b/ngdart/lib/angular.dart index b8eecb2b2c..f3efca4e73 100644 --- a/ngdart/lib/angular.dart +++ b/ngdart/lib/angular.dart @@ -11,9 +11,9 @@ /// * [AngularDart guide][] /// * [AngularDart cheat sheet][cheatsheet] /// -/// [AngularDart]: https://webdev.dartlang.org/angular -/// [AngularDart guide]: https://webdev.dartlang.org/angular/guide -/// [cheatsheet]: https://webdev.dartlang.org/angular/cheatsheet +/// [AngularDart]: https://angulardart.xyz +/// [AngularDart guide]: https://angulardart.xyz/guide +/// [cheatsheet]: https://angulardart.xyz/cheatsheet library angular; diff --git a/ngdart/lib/experimental.dart b/ngdart/lib/experimental.dart index a1fd1b996a..dbe385a6ad 100644 --- a/ngdart/lib/experimental.dart +++ b/ngdart/lib/experimental.dart @@ -23,8 +23,8 @@ export 'src/meta.dart' show changeDetectionLink; /// Create a root application [Injector]. /// /// Requires [userInjector] to provide app-level services or overrides: -/// ```dart -/// main() { +/// ``` +/// void main() { /// var injector = rootInjector((parent) { /// return Injector.map({ /* ... */ }, parent); /// }); diff --git a/ngdart/lib/src/bootstrap/run.dart b/ngdart/lib/src/bootstrap/run.dart index b5379cfc50..8c4c93445f 100644 --- a/ngdart/lib/src/bootstrap/run.dart +++ b/ngdart/lib/src/bootstrap/run.dart @@ -98,9 +98,10 @@ Injector _identityInjector(Injector parent) => parent; /// Starts a new AngularDart application with [componentFactory] as the root. /// -/// ```dart +/// ``` /// // Assume this file is "main.dart". /// import 'package:ngdart/angular.dart'; +/// /// import 'main.template.dart' as ng; /// /// @Component( @@ -123,8 +124,10 @@ Injector _identityInjector(Injector parent) => parent; /// Optionally may supply a [createInjector] function in order to provide /// services to the root of the application: /// +/// ``` /// // Assume this file is "main.dart". /// import 'package:ngdart/angular.dart'; +/// /// import 'main.template.dart' as ng; /// /// @Component( @@ -143,14 +146,12 @@ Injector _identityInjector(Injector parent) => parent; /// } /// } /// +/// @GenerateInjector([ClassProvider(HelloService)]) +/// final InjectorFactory helloInjector = ng.helloInjector$Injector; +/// /// void main() { /// runApp(ng.HelloWorldNgFactory, createInjector: helloInjector); /// } -/// -/// @GenerateInjector(const [ -/// const ClassProvider(HelloService), -/// ]) -/// final InjectorFactory helloInjector = ng.helloInjector$Injector; /// ``` /// /// See [InjectorFactory] for more examples. diff --git a/ngdart/lib/src/common/directives/ng_class.dart b/ngdart/lib/src/common/directives/ng_class.dart index 19ba422a90..33a655bacf 100644 --- a/ngdart/lib/src/common/directives/ng_class.dart +++ b/ngdart/lib/src/common/directives/ng_class.dart @@ -13,14 +13,14 @@ import 'package:ngdart/src/utilities.dart'; /// /// - [String] - all the CSS classes listed in a string (space delimited) are /// added -/// - [List] - all the CSS classes (List elements) are added -/// - [Object] - each key corresponds to a CSS class name while values are +/// - [List] - all the CSS classes (List elements) are added +/// - [Map] - each key corresponds to a CSS class name while values are /// interpreted as expressions evaluating to [bool]. If a given expression -/// evaluates to [true] a corresponding CSS class is added - otherwise it is +/// evaluates to `true` a corresponding CSS class is added - otherwise it is /// removed. /// /// While the [NgClass] directive can interpret expressions evaluating to -/// [String], [Array] or [Object], the [Object]-based version is the most often +/// [String], [List] or [Map], the [Map]-based version is the most often /// used and has an advantage of keeping all the CSS class names in a template. /// /// ### Examples @@ -31,7 +31,7 @@ import 'package:ngdart/src/utilities.dart'; /// ``` /// /// -/// ```dart +/// ``` /// Map currentClasses = {}; /// void setCurrentClasses() { /// currentClasses = { @@ -46,8 +46,8 @@ import 'package:ngdart/src/utilities.dart'; /// For details, see the [`ngClass` discussion in the Template Syntax][guide] /// page. /// -/// [ex]: https://angulardart.dev/examples/template-syntax#ngClass -/// [guide]: https://webdev.dartlang.org/angular/guide/template-syntax.html#ngClass +/// [ex]: https://angulardart.xyz/examples/template-syntax#ngClass +/// [guide]: https://angulardart.xyz/guide/template-syntax.html#ngClass @Directive( selector: '[ngClass]', ) diff --git a/ngdart/lib/src/common/directives/ng_for.dart b/ngdart/lib/src/common/directives/ng_for.dart index 8bfaab3ac7..a41abeb0d2 100644 --- a/ngdart/lib/src/common/directives/ng_for.dart +++ b/ngdart/lib/src/common/directives/ng_for.dart @@ -81,7 +81,7 @@ import '../../core/linker.dart'; /// For details, see the [`ngFor` discussion in the Template Syntax][guide] /// page. /// -/// [guide]: https://webdev.dartlang.org/angular/guide/template-syntax.html#ngFor +/// [guide]: https://angulardart.xyz/guide/template-syntax.html#ngFor @Directive( selector: '[ngFor][ngForOf]', ) diff --git a/ngdart/lib/src/common/directives/ng_for_identity.dart b/ngdart/lib/src/common/directives/ng_for_identity.dart index fb0c7fc38d..b716a11d40 100644 --- a/ngdart/lib/src/common/directives/ng_for_identity.dart +++ b/ngdart/lib/src/common/directives/ng_for_identity.dart @@ -1,4 +1,5 @@ import 'package:meta/meta.dart'; +import 'package:ngdart/src/common/directives/ng_for.dart'; import 'package:ngdart/src/core/linker/template_ref.dart'; import 'package:ngdart/src/core/linker/view_container_ref.dart'; import 'package:ngdart/src/meta.dart'; diff --git a/ngdart/lib/src/common/directives/ng_if.dart b/ngdart/lib/src/common/directives/ng_if.dart index 092b9c740d..7f97e67ba6 100644 --- a/ngdart/lib/src/common/directives/ng_if.dart +++ b/ngdart/lib/src/common/directives/ng_if.dart @@ -26,7 +26,7 @@ import 'package:ngdart/src/runtime/check_binding.dart'; /// /// ``` /// -/// [guide]: https://webdev.dartlang.org/angular/guide/template-syntax.html#ngIf +/// [guide]: https://angulardart.xyz/guide/template-syntax.html#ngIf @Directive( selector: '[ngIf]', ) diff --git a/ngdart/lib/src/common/directives/ng_style.dart b/ngdart/lib/src/common/directives/ng_style.dart index 193ec5bf10..740c97aa00 100644 --- a/ngdart/lib/src/common/directives/ng_style.dart +++ b/ngdart/lib/src/common/directives/ng_style.dart @@ -8,7 +8,7 @@ import '../../core/change_detection/differs/default_keyvalue_differ.dart'; /// The `NgStyle` directive changes an element's style based on the bound style /// expression: /// -///
+///
/// /// _styleExp_ must evaluate to a `Map`. Element style properties /// are set based on the map entries: each _key_:_value_ pair identifies a @@ -31,7 +31,7 @@ import '../../core/change_detection/differs/default_keyvalue_differ.dart'; /// ``` /// /// -/// ```dart +/// ``` /// Map currentStyles = {}; /// void setCurrentStyles() { /// currentStyles = { @@ -45,15 +45,8 @@ import '../../core/change_detection/differs/default_keyvalue_differ.dart'; /// In this example, user changes to the `` elements result in updates /// to the corresponding style properties of the first paragraph. /// -/// A [Map] literal can be used as a style expression: -/// -///
-/// -/// A better practice, however, is to bind to a component field or method, as -/// in the binding to `setStyle()` above. -/// -/// [guide]: https://webdev.dartlang.org/angular/guide/template-syntax.html#ngStyle -/// [ex]: https://angulardart.dev/examples/template-syntax#ngStyle +/// [guide]: https://angulardart.xyz/guide/template-syntax.html#ngStyle +/// [ex]: https://angulardart.xyz/examples/template-syntax#ngStyle @Directive( selector: '[ngStyle]', ) diff --git a/ngdart/lib/src/common/directives/ng_switch.dart b/ngdart/lib/src/common/directives/ng_switch.dart index 7c1f2d6454..23980b0be1 100644 --- a/ngdart/lib/src/common/directives/ng_switch.dart +++ b/ngdart/lib/src/common/directives/ng_switch.dart @@ -69,8 +69,8 @@ class SwitchView { /// Try the [live example][ex]. /// For details, see the [Structural Directives section on `ngSwitch`][guide]. /// -/// [ex]: https://angulardart.dev/examples/template-syntax#ngSwitch -/// [guide]: https://webdev.dartlang.org/angular/guide/structural-directives.html#ngSwitch +/// [ex]: https://angulardart.xyz/examples/template-syntax#ngSwitch +/// [guide]: https://angulardart.xyz/guide/structural-directives.html#ngSwitch /// @Directive( selector: '[ngSwitch]', diff --git a/ngdart/lib/src/common/directives/ng_template_outlet.dart b/ngdart/lib/src/common/directives/ng_template_outlet.dart index 6cb61c81a0..38c1092446 100644 --- a/ngdart/lib/src/common/directives/ng_template_outlet.dart +++ b/ngdart/lib/src/common/directives/ng_template_outlet.dart @@ -5,7 +5,7 @@ import 'package:ngdart/src/meta.dart'; /// /// ### Examples /// -/// ```dart +/// ``` /// @Component( /// selector: 'example', /// template: ''' @@ -28,7 +28,7 @@ import 'package:ngdart/src/meta.dart'; /// [ngTemplateOutletContext]="iconContext"> /// /// ''', -/// directives: const [NgTemplateOutlet], +/// directives: [NgTemplateOutlet], /// ) /// class ExampleComponent { /// final textContext = 'Hello world!'; diff --git a/ngdart/lib/src/common/pipes/async_pipe.dart b/ngdart/lib/src/common/pipes/async_pipe.dart index 248be633cf..16dfd422ec 100644 --- a/ngdart/lib/src/common/pipes/async_pipe.dart +++ b/ngdart/lib/src/common/pipes/async_pipe.dart @@ -39,19 +39,21 @@ final _observableStrategy = _ObservableStrategy(); /// ### Example /// /// -/// ```dart +/// ``` /// @Component( -/// selector: 'async-greeter', -/// template: ''' -///
-///

Wait for it ... {{ $pipe.async(greeting) }}

-/// -///
''') +/// selector: 'async-greeter', +/// template: ''' +///
+///

Wait for it ... {{ $pipe.async(greeting) }}

+/// +///
+/// ''', +/// ) /// class AsyncGreeterPipe { -/// static const _delay = const Duration(seconds: 2); +/// static const _delay = Duration(seconds: 2); /// -/// Future greeting; -/// bool done; +/// late Future greeting; +/// late bool done; /// /// AsyncGreeterPipe() { /// tryAgain(); @@ -64,17 +66,17 @@ final _observableStrategy = _ObservableStrategy(); /// /// void tryAgain() { /// done = false; -/// greeting = new Future.delayed(_delay, greet); +/// greeting = Future.delayed(_delay, greet); /// } /// } /// /// @Component( -/// selector: 'async-time', -/// template: "

Time: {{ $pipe.date($pipe.async(time), 'mediumTime') }}

") // +/// selector: 'async-time', +/// template: "

Time: {{ $pipe.date($pipe.async(time), 'mediumTime') }}

", +/// ) /// class AsyncTimePipe { -/// static const _delay = const Duration(seconds: 1); -/// final Stream time = -/// new Stream.periodic(_delay, (_) => new DateTime.now()); +/// static const _delay = Duration(seconds: 1); +/// final Stream time = Stream.periodic(_delay, (_) =>DateTime.now()); /// } /// ``` /// @@ -82,7 +84,7 @@ final _observableStrategy = _ObservableStrategy(); class AsyncPipe implements OnDestroy { Object? _latestValue; Object? _subscription; - dynamic /* Stream | Future | EventEmitter */ _obj; + dynamic /* Stream | Future */ _obj; dynamic _strategy; final ChangeDetectorRef _ref; @@ -95,7 +97,7 @@ class AsyncPipe implements OnDestroy { } } - dynamic transform(dynamic /* Stream | Future | EventEmitter */ obj) { + dynamic transform(dynamic /* Stream | Future */ obj) { if (_obj == null) { if (obj != null) { _subscribe(obj); @@ -107,14 +109,14 @@ class AsyncPipe implements OnDestroy { return _latestValue; } - void _subscribe(dynamic /* Stream | Future | EventEmitter */ obj) { + void _subscribe(dynamic /* Stream | Future */ obj) { _obj = obj; _strategy = _selectStrategy(obj); _subscription = _strategy.createSubscription( obj, (Object? value) => _updateLatestValue(obj, value)); } - dynamic _selectStrategy(dynamic /* Stream | Future | EventEmitter */ obj) { + dynamic _selectStrategy(dynamic /* Stream | Future */ obj) { if (obj is Future) { return _promiseStrategy; } else if (obj is Stream) { diff --git a/ngdart/lib/src/common/pipes/replace_pipe.dart b/ngdart/lib/src/common/pipes/replace_pipe.dart index d589a9356d..7042fe3c86 100644 --- a/ngdart/lib/src/common/pipes/replace_pipe.dart +++ b/ngdart/lib/src/common/pipes/replace_pipe.dart @@ -18,7 +18,7 @@ import 'invalid_pipe_argument_exception.dart' show InvalidPipeArgumentException; /// All behavior is based on the expected behavior of the JavaScript API /// String.prototype.replace() function. /// -/// Where the input expression is a [String] or [Number] (to be treated as a +/// Where the input expression is a [String] or [num] (to be treated as a /// string), /// the `pattern` is a [String] or [RegExp], /// the 'replacement' is a [String] or [Function]. diff --git a/ngdart/lib/src/core/application_tokens.dart b/ngdart/lib/src/core/application_tokens.dart index b8e73e564c..5c5fff598f 100644 --- a/ngdart/lib/src/core/application_tokens.dart +++ b/ngdart/lib/src/core/application_tokens.dart @@ -5,12 +5,18 @@ import 'package:ngdart/src/meta.dart'; /// The identifier is used internally to apply CSS scoping behavior. /// /// To avoid a randomly generated value, a custom value can be provided: -/// ```dart -/// bootstrapStatic( -/// YourAppComponent, -/// const [ -/// const Provider(appId, useValue: 'my-unique-id'), -/// ], -/// ) +/// ``` +/// import 'package:ngdart/angular.dart'; +/// +/// import 'main.template.dart' as ng; +/// +/// @GenerateInjector([ +/// ValueProvider.forToken(appId, 'my-unique-id') +/// ]) +/// final InjectorFactory appInjector = appInjector$Injector; +/// +/// void main() { +/// runApp(ng.AppComponentNgFactory, createInjector: appInjector); +/// } /// ``` const appId = OpaqueToken('appId'); diff --git a/ngdart/lib/src/core/change_detection/change_detector_ref.dart b/ngdart/lib/src/core/change_detection/change_detector_ref.dart index 7c5b584d0c..9be29af700 100644 --- a/ngdart/lib/src/core/change_detection/change_detector_ref.dart +++ b/ngdart/lib/src/core/change_detection/change_detector_ref.dart @@ -31,12 +31,12 @@ abstract class ChangeDetectorRef { /// changeDetection: ChangeDetectionStrategy.onPush, /// ) /// class OnPushExample implements OnDestroy { - /// Timer timer; + /// late Timer timer; /// /// var ticks = 0; /// /// OnPushExample(ChangeDetectorRef changeDetector) { - /// timer = Timer.periodic(Duration(seconds: 1), () { + /// timer = Timer.periodic(const Duration(seconds: 1), () { /// ticks++; /// changeDetector.markForCheck(); /// }); diff --git a/ngdart/lib/src/core/change_detection/differs/default_iterable_differ.dart b/ngdart/lib/src/core/change_detection/differs/default_iterable_differ.dart index ab9e3c0a0a..9db8b0b305 100644 --- a/ngdart/lib/src/core/change_detection/differs/default_iterable_differ.dart +++ b/ngdart/lib/src/core/change_detection/differs/default_iterable_differ.dart @@ -12,7 +12,7 @@ import 'package:ngdart/src/utilities.dart'; /// you may specify a [TrackByFn]`: /// ``` /// class MyComp { -/// Object trackByEmployeeId(int index, dynamic item) { +/// Object? trackByEmployeeId(int index, dynamic item) { /// return item is Employee ? item.id : item; /// } /// } @@ -260,8 +260,6 @@ class DefaultIterableDiffer { /// previousKey to currentKey, and clear all of the queues (additions, moves, /// removals). Set the previousIndexes of moved and added items to their /// currentIndexes. Reset the list of additions, moves and removals - /// - /// @internal void _reset() { if (isDirty) { CollectionChangeRecord? record; @@ -293,8 +291,6 @@ class DefaultIterableDiffer { /// then it is a new item. /// - `item` is the current item in the collection /// - `index` is the position of the item in the collection - /// - /// @internal CollectionChangeRecord _mismatch(CollectionChangeRecord? record, dynamic item, dynamic itemTrackBy, int index) { // The previous record after which we will append the current one. @@ -361,8 +357,6 @@ class DefaultIterableDiffer { /// switching position. This is incorrect, since a better way to think of it /// is as insert of 'b' rather then switch 'a' with 'b' and then add 'a' /// at the end. - /// - /// @internal CollectionChangeRecord _verifyReinsertion(CollectionChangeRecord record, dynamic item, dynamic itemTrackBy, int index) { var reinsertRecord = _unlinkedRecords?.get(itemTrackBy); @@ -379,8 +373,6 @@ class DefaultIterableDiffer { /// collection. /// /// - `record` The first excess [CollectionChangeRecord]. - /// - /// @internal void _truncate(CollectionChangeRecord? record) { // Anything after that needs to be removed; while (record != null) { diff --git a/ngdart/lib/src/core/change_detection/host.dart b/ngdart/lib/src/core/change_detection/host.dart index ede4cea23d..bbc976167e 100644 --- a/ngdart/lib/src/core/change_detection/host.dart +++ b/ngdart/lib/src/core/change_detection/host.dart @@ -20,7 +20,7 @@ abstract class ChangeDetectionHost { /// **INTERNAL ONLY**: Whether a crash was detected during the last `tick()`. static bool get checkForCrashes => _current?._lastGuardedView != null; - /// **INTERNAL ONLY**: Register a crash during [view.detectCrash]. + /// **INTERNAL ONLY**: Register a crash during [View.detectCrash]. static void handleCrash(View view, Object error, StackTrace trace) { final current = _current!; current @@ -94,7 +94,7 @@ abstract class ChangeDetectionHost { } } - /// Runs [AppView.detectChanges] on all top-level components/views. + /// Runs [DeprecatedDetectChanges.detectChanges] on all top-level components/views. void _runTick() { final detectors = _changeDetectors; final length = detectors.length; @@ -111,7 +111,7 @@ abstract class ChangeDetectionHost { } } - /// Runs [AppView.detectChanges] for all top-level components/views. + /// Runs [DeprecatedDetectChanges.detectChanges] for all top-level components/views. /// /// Unlike [_runTick], this enters a guarded mode that checks a view tree for /// exceptions, trying to find the leaf-most node that throws during change @@ -138,8 +138,6 @@ abstract class ChangeDetectionHost { return _checkForChangeDetectionError(); } - static const _isSoundNullSafety = [] is! List; - /// Checks for any uncaught exception that occurred during change detection. @dart2js.noInline bool _checkForChangeDetectionError() { @@ -152,9 +150,7 @@ abstract class ChangeDetectionHost { // the value being null part of the explicit contract. By changing this // to `_lastCaughtException!` and running our test cases multiple tests // start failing! - _isSoundNullSafety - ? _lastCaughtException ?? Error() - : _lastCaughtException as Object, + _lastCaughtException!, _lastCaughtTrace, ); _resetViewErrors(); @@ -168,7 +164,7 @@ abstract class ChangeDetectionHost { _lastGuardedView = _lastCaughtException = _lastCaughtTrace = null; } - /// Disables the [view] as an error, and forwards to [reportException]. + /// Disables the [view] as an error, and forwards to [handleUncaughtException]. @dart2js.noInline void reportViewException( View view, diff --git a/ngdart/lib/src/core/linker/component_factory.dart b/ngdart/lib/src/core/linker/component_factory.dart index df43db9f59..609636e96e 100644 --- a/ngdart/lib/src/core/linker/component_factory.dart +++ b/ngdart/lib/src/core/linker/component_factory.dart @@ -103,7 +103,7 @@ class ComponentRef { /// Backing implementation behind a `class` [T] annotated with `@Component`. /// /// For example, if this lives in `example.dart`: -/// ```dart +/// ``` /// @Component( /// selector: 'example', /// template: '...', @@ -113,10 +113,10 @@ class ComponentRef { /// /// ... then `ExampleNgFactory` is generated in `example.template.dart`, and /// can be accessed by importing this generated file. For example: -/// ```dart +/// ``` /// import 'example.template.dart' as ng; /// -/// getComponentFactory() { +/// void getComponentFactory() { /// final ComponentFactory comp = ng.ExampleNgFactory; /// // Can now use 'comp' as a ComponentFactory. /// } diff --git a/ngdart/lib/src/core/linker/component_loader.dart b/ngdart/lib/src/core/linker/component_loader.dart index e755de71fd..1ee5a6eab0 100644 --- a/ngdart/lib/src/core/linker/component_loader.dart +++ b/ngdart/lib/src/core/linker/component_loader.dart @@ -21,7 +21,7 @@ class ComponentLoader { /// /// May optionally define a parent [injector]; defaults to an empty injector. /// - /// ```dart + /// ``` /// // An `ExampleComponent`s generated code, including a `ComponentFactory`. /// import 'example.template.dart' as ng; /// @@ -66,10 +66,10 @@ class ComponentLoader { /// in the DOM, similar to how `*ngIf` and `*ngFor` operate. /// /// The following API would load a new component next to `currentAd`: - /// ```dart + /// ``` /// @Component( /// selector: 'ad-view', - /// template: r''' + /// template: ''' /// This component is sponsored by: /// /// ''', diff --git a/ngdart/lib/src/di/injector.dart b/ngdart/lib/src/di/injector.dart index 1c019d2116..13b3f2a4d1 100644 --- a/ngdart/lib/src/di/injector.dart +++ b/ngdart/lib/src/di/injector.dart @@ -17,7 +17,7 @@ Never throwsNotFound(HierarchicalInjector injector, Object token) { /// Defines a function that creates an injector around a [parent] injector. /// /// An [InjectorFactory] can be as simple as a closure or function: -/// ```dart +/// ``` /// class Example {} /// /// /// Returns an [Injector] that provides an `Example` service. diff --git a/ngdart/lib/src/meta.dart b/ngdart/lib/src/meta.dart index aa67dfb539..e4c4076638 100644 --- a/ngdart/lib/src/meta.dart +++ b/ngdart/lib/src/meta.dart @@ -26,7 +26,7 @@ export 'meta/visibility.dart'; /// will be referenced in the template HTML of an AngularDart component. For /// example: /// -/// ```dart +/// ``` /// // my_component.dart /// import 'package:ngdart/angular.dart'; /// @@ -50,7 +50,7 @@ export 'meta/visibility.dart'; /// and is not intended to be part of the public API of the component. Another /// library attempting to access `fullName` would trigger a diagnostic: /// -/// ```dart +/// ``` /// // other_lib.dart /// import 'my_component.dart'; /// diff --git a/ngdart/lib/src/meta/di_arguments.dart b/ngdart/lib/src/meta/di_arguments.dart index 22a190a100..740e5a699d 100644 --- a/ngdart/lib/src/meta/di_arguments.dart +++ b/ngdart/lib/src/meta/di_arguments.dart @@ -1,26 +1,32 @@ import 'package:meta/meta_meta.dart'; +import '../di/injector.dart'; + /// A parameter metadata that specifies a dependency. /// /// ## Example /// -/// ```dart -/// class Engine {} +/// ``` +/// class Engine { +/// const Engine(); +/// } +/// +/// const engine = Engine(); /// -/// @Injectable() /// class Car { +/// Car(@Inject(Engine) this.engine); +/// /// final Engine engine; -/// Car(@Inject("MyEngine") this.engine); /// } /// -/// var engine = new Engine(); +/// @GenerateInjector([ +/// ValueProvider(Engine, engine), +/// ClassProvider(Car), +/// ]) +/// final InjectorFactory injector = ng.injector$Injector; /// -/// var injector = Injector.resolveAndCreate([ -/// new Provider("MyEngine", useValue: engine), -/// Car -/// ]); -/// -/// expect(injector.get(Car).engine, same(engine)); +/// Car car = injector(root).get(Car); +/// expect(car.engine, same(engine)); /// ``` /// /// When `@Inject()` is not present, [Injector] will use the type annotation of @@ -28,16 +34,21 @@ import 'package:meta/meta_meta.dart'; /// /// ## Example /// -/// ```dart +/// ``` /// class Engine {} /// -/// @Injectable() /// class Car { -/// Car(Engine engine) {} //same as Car(@Inject(Engine) Engine engine) +/// Car(Engine engine) {} // same as Car(@Inject(Engine) Engine engine) /// } /// -/// var injector = Injector.resolveAndCreate([Engine, Car]); -/// expect(injector.get(Car).engine, new isInstanceOf()); +/// @GenerateInjector([ +/// ClassProvider(Engine), +/// ClassProvider(Car), +/// ]) +/// final InjectorFactory injector = ng.injector$Injector; +/// +/// Car car = injector(root).get(Car); +/// expect(car.engine, isA()); /// ``` @Target({TargetKind.parameter}) class Inject { @@ -69,7 +80,7 @@ class Inject { /// /// ### Example /// -/// ```dart +/// ``` /// // Use the default constructor to create a new instance of MyService. /// @Injectable() /// class MyService {} @@ -96,9 +107,9 @@ class Inject { /// /// ### Example /// -/// ```dart +/// ``` /// // Could be put anywhere DI providers are allowed. -/// const Provide(MyService, useFactory: createMyService); +/// FactoryProvider(MyService, createMyService); /// /// // A `Provide` may now use `createMyService` via `useFactory`. /// @Injectable() @@ -113,6 +124,7 @@ class Inject { TargetKind.function, TargetKind.method, }) +@Deprecated('It does nothing but throw on invalid uses.') class Injectable { const Injectable(); } @@ -123,17 +135,19 @@ class Injectable { /// /// ## Example /// -/// ```dart +/// ``` /// class Engine {} /// -/// @Injectable() /// class Car { -/// final Engine engine; +/// final Engine? engine; /// Car(@Optional() this.engine); /// } /// -/// var injector = Injector.resolveAndCreate([Car]); -/// expect(injector.get(Car).engine, isNull); +/// @GenerateInjector([ClassProvider(Car)]) +/// final InjectorFactory injector = ng.injector$Injector; +/// +/// Car car = injector(root).get(Car); +/// expect(car.engine, isNull); /// ``` @Target({TargetKind.parameter}) class Optional { @@ -144,23 +158,34 @@ class Optional { /// /// ## Example /// -/// ```dart +/// ``` /// class Dependency {} /// -/// @Injectable() /// class NeedsDependency { /// final Dependency dependency; /// NeedsDependency(@Self() this.dependency); /// } /// -/// var inj = Injector.resolveAndCreate([Dependency, NeedsDependency]); -/// var nd = inj.get(NeedsDependency); +/// @GenerateInjector([ +/// ClassProvider(Dependency), +/// ClassProvider(NeedsDependency), +/// ]) +/// final InjectorFactory injector = ng.injector$Injector; +/// +/// NeedsDependency needsDependency = injector(root).get(NeedsDependency); +/// expect(needsDependency.dependency, isA()); +/// +/// @GenerateInjector([ +/// ClassProvider(Dependency), +/// ]) +/// final InjectorFactory parent = ng.parent$Injector; /// -/// expect(nd.dependency, new isInstanceOf()); +/// @GenerateInjector([ +/// ClassProvider(NeedsDependency), +/// ]) +/// final InjectorFactory child = ng.child$Injector; /// -/// inj = Injector.resolveAndCreate([Dependency]); -/// var child = inj.resolveAndCreateChild([NeedsDependency]); -/// expect(() => child.get(NeedsDependency), throws); +/// expect(() => child(parent(root)).get(NeedsDependency), throwsA(anything)); /// ``` @Target({TargetKind.parameter}) class Self { @@ -172,22 +197,34 @@ class Self { /// /// ## Example /// -/// ```dart +/// ``` /// class Dependency {} /// -/// @Injectable() /// class NeedsDependency { /// final Dependency dependency; /// NeedsDependency(@SkipSelf() this.dependency); /// } /// -/// var parent = Injector.resolveAndCreate([Dependency]); -/// var child = parent.resolveAndCreateChild([NeedsDependency]); -/// expect(child.get(NeedsDependency).dependency, new -/// isInstanceOf()); +/// @GenerateInjector([ +/// ClassProvider(Dependency), +/// ]) +/// final InjectorFactory parent = ng.parent$Injector; +/// +/// @GenerateInjector([ +/// ClassProvider(NeedsDependency), +/// ]) +/// final InjectorFactory child = ng.child$Injector; +/// +/// NeedsDependency needsDependency = child(parent(root)).get(NeedsDependency) +/// expect(needsDependency.dependency, isA()); /// -/// var inj = Injector.resolveAndCreate([Dependency, NeedsDependency]); -/// expect(() => inj.get(NeedsDependency), throws); +/// @GenerateInjector([ +/// ClassProvider(Dependency), +/// ClassProvider(NeedsDependency), +/// ]) +/// final InjectorFactory injector = ng.injector$Injector; +/// +/// expect(() => injector(root).get(NeedsDependency), throwsA(anything)); /// ``` @Target({TargetKind.parameter}) class SkipSelf { @@ -209,43 +246,46 @@ class SkipSelf { /// `HostService` is defined at `ParentCmp`, and `OtherService` is defined at /// `App`. /// -///```dart +///``` /// class OtherService {} /// class HostService {} /// /// @Directive( -/// selector: 'child-directive' +/// selector: 'child-directive', /// ) /// class ChildDirective { /// ChildDirective( -/// @Optional() @Host() OtherService os, -/// @Optional() @Host() HostService hs) { -/// print("os is null", os); -/// print("hs is NOT null", hs); +/// @Optional() @Host() OtherService? os, +/// @Optional() @Host() HostService? hs, +/// ) { +/// print('os is null: $os'); +/// print('hs is NOT null: $hs'); /// } /// } /// /// @Component( /// selector: 'parent-cmp', -/// providers: const [HostService], +/// directives: [ChildDirective], +/// providers: [HostService], /// template: ''' /// Dir: /// ''', -/// directives: const [ChildDirective] /// ) /// class ParentCmp {} /// /// @Component( /// selector: 'app', -/// providers: const [OtherService], +/// directives: [ParentCmp] +/// providers: [OtherService], /// template: ''' /// Parent: /// ''', -/// directives: const [ParentCmp] /// ) /// class App {} /// -/// bootstrap(App); +/// void main() { +/// runApp(ng.AppNgFactory); +/// } ///``` @Target({TargetKind.parameter}) class Host { diff --git a/ngdart/lib/src/meta/di_generate_injector.dart b/ngdart/lib/src/meta/di_generate_injector.dart index a643d87590..c974a9117b 100644 --- a/ngdart/lib/src/meta/di_generate_injector.dart +++ b/ngdart/lib/src/meta/di_generate_injector.dart @@ -1,20 +1,19 @@ import 'package:meta/meta_meta.dart'; +import '../di/injector.dart'; import 'di_modules.dart'; /// Annotates a method to generate an [Injector] factory at compile-time. /// /// Using `@GenerateInjector` is conceptually similar to using `@Component` or -/// `@Directive` with a `providers: const [ ... ]` argument, but like a +/// `@Directive` with a `providers: [ ... ]` argument, but like a /// component or directive that injector is generated ahead of time, during /// compilation: /// /// ``` /// import 'my_file.template.dart' as ng; /// -/// @GenerateInjector(const [ -/// const Provider(A, useClass: APrime), -/// ]) +/// @GenerateInjector([ClassProvider(A, APrime)]) /// // The generated factory is your method's name, suffixed with `$Injector`. /// final InjectorFactory example = example$Injector; /// ``` diff --git a/ngdart/lib/src/meta/di_modules.dart b/ngdart/lib/src/meta/di_modules.dart index b6216a0058..15c680f45c 100644 --- a/ngdart/lib/src/meta/di_modules.dart +++ b/ngdart/lib/src/meta/di_modules.dart @@ -12,7 +12,7 @@ import 'package:ngdart/src/meta.dart'; /// Previously, AngularDart loosely expressed "modules" as a recursive list of /// both providers and other lists of providers. For example, the following /// pattern may be re-written to use `Module`: -/// ```dart +/// ``` /// // Before. /// const carModule = [ /// ClassProvider(Car, useClass: AmericanCar), diff --git a/ngdart/lib/src/meta/di_providers.dart b/ngdart/lib/src/meta/di_providers.dart index dcec794dc4..43d5f2b432 100644 --- a/ngdart/lib/src/meta/di_providers.dart +++ b/ngdart/lib/src/meta/di_providers.dart @@ -65,7 +65,7 @@ class Provider { /// Class whose constructor should be invoked when [token] is injected. /// /// When omitted and [token] is a [Type], this value is implicitly [token]: - /// ```dart + /// ``` /// // The same thing. /// const Provider(Foo); /// const Provider(Foo, useClass: Foo); @@ -75,7 +75,7 @@ class Provider { /// Constant value to use when [token] is injected. /// /// It is recommended to use [useValue] with an [OpaqueToken] as [token]: - /// ```dart + /// ``` /// const animationDelay = OpaqueToken('animationDelay'); /// /// const Provider(animationDelay, useValue: Duration(seconds: 1)); @@ -159,12 +159,12 @@ Object buildAtRuntime(Provider provider, RuntimeInjectorBuilder builder) { /// If [T] is provided (i.e. not [dynamic]), it must be the same as [token]. /// /// A class that provides itself: -/// ```dart +/// ``` /// const ClassProvider(Service); /// ``` /// /// A class that provides itself with a different implementation: -/// ```dart +/// ``` /// const ClassProvider(Service, useClass: CachedService); /// ``` @optionalTypeArgs @@ -244,7 +244,7 @@ class FactoryProvider extends Provider { /// Describes at compile-time using a constant value to represent a token. /// /// It is recommended to use [useValue] with an [OpaqueToken] as [token]: -/// ```dart +/// ``` /// const animationDelay = OpaqueToken('animationDelay'); /// /// const ValueProvider.forToken(animationDelay, Duration(seconds: 1)); diff --git a/ngdart/lib/src/meta/di_tokens.dart b/ngdart/lib/src/meta/di_tokens.dart index e990e69883..49aa688d4c 100644 --- a/ngdart/lib/src/meta/di_tokens.dart +++ b/ngdart/lib/src/meta/di_tokens.dart @@ -9,8 +9,8 @@ import 'package:ngdart/src/utilities.dart'; /// /// @Component( /// selector: 'dashboard', -/// providers: const [ -/// const ValueProvider.forToken(loginUrl, 'https://someurl.com'), +/// providers: [ +/// ValueProvider.forToken(loginUrl, 'https://someurl.com'), /// ], /// ) /// class DashboardComponent {} @@ -32,8 +32,8 @@ import 'package:ngdart/src/utilities.dart'; /// /// @Component( /// selector: 'dashboard', -/// providers: const [ -/// const ValueProvider.forToken(loginUrl, 'https://someurl.com'), +/// providers: [ +/// ValueProvider.forToken(loginUrl, 'https://someurl.com'), /// ], /// ) /// class DashboardComponent {} @@ -64,9 +64,9 @@ class OpaqueToken { /// /// @Component( /// selector: 'presidents-list', -/// providers: const [ -/// const ValueProvider.forToken(usPresidents, 'George Washington'), -/// const ValueProvider.forToken(usPresidents, 'Abraham Lincoln'), +/// providers: [ +/// ValueProvider.forToken(usPresidents, 'George Washington'), +/// ValueProvider.forToken(usPresidents, 'Abraham Lincoln'), /// ], /// ) /// class PresidentsListComponent { @@ -94,9 +94,9 @@ class OpaqueToken { /// /// @Component( /// selector: 'presidents-list', -/// providers: const [ -/// const ValueProvider.forToken(usPresidents, 'George Washington'), -/// const ValueProvider.forToken(usPresidents, 'Abraham Lincoln'), +/// providers: [ +/// ValueProvider.forToken(usPresidents, 'George Washington'), +/// ValueProvider.forToken(usPresidents, 'Abraham Lincoln'), /// ], /// ) /// class PresidentsListComponent { diff --git a/ngdart/lib/src/meta/directives.dart b/ngdart/lib/src/meta/directives.dart index de350e6552..b96e9d7341 100644 --- a/ngdart/lib/src/meta/directives.dart +++ b/ngdart/lib/src/meta/directives.dart @@ -9,7 +9,7 @@ import 'visibility.dart'; /// attach behavior to elements in the DOM. /// /// -/// ```dart +/// ``` /// import 'dart:html'; /// /// import 'package:ngdart/angular.dart'; @@ -32,8 +32,8 @@ import 'visibility.dart'; /// /// See also: /// -/// * [Attribute Directives](https://webdev.dartlang.org/angular/guide/attribute-directives) -/// * [Lifecycle Hooks](https://webdev.dartlang.org/angular/guide/lifecycle-hooks) +/// * [Attribute Directives](https://angulardart.xyz/guide/attribute-directives) +/// * [Lifecycle Hooks](https://angulardart.xyz/guide/lifecycle-hooks) /// @Target({TargetKind.classType}) class Directive { @@ -75,14 +75,15 @@ class Directive { /// ### Example /// Here is an example of a class that can be injected: /// - /// ```dart + /// ``` /// class Greeter { /// String greet(String name) => 'Hello ${name}!'; /// } /// /// @Directive( /// selector: 'greet', - /// providers: const [ Greeter]) + /// providers: [Greeter], + /// ) /// class HelloWorld { /// final Greeter greeter; /// @@ -96,16 +97,18 @@ class Directive { /// /// ### Example /// - /// ```dart + /// ``` /// @Directive( /// selector: 'child-dir', - /// exportAs: 'child') + /// exportAs: 'child', + /// ) /// class ChildDir {} /// /// @Component( /// selector: 'main', /// template: ``, - /// directives: const [ChildDir]) + /// directives: [ChildDir], + /// ) /// class MainComponent {} /// ``` final String? exportAs; @@ -146,7 +149,7 @@ class Directive { /// the callbacks are called by the change detection at defined points in time /// during the life of the component. /// -/// [LCH]: https://webdev.dartlang.org/angular/guide/lifecycle-hooks +/// [LCH]: https://angulardart.xyz/guide/lifecycle-hooks @Target({TargetKind.classType}) class Component extends Directive { /// Defines the used change detection strategy. @@ -164,31 +167,29 @@ class Component extends Directive { /// ## Simple Example /// /// Here is an example of a class that can be injected: + /// ``` + /// class Greeter { + /// greet(String name) => 'Hello ${name}!'; + /// } /// - /// class Greeter { - /// greet(String name) => 'Hello ${name}!'; - /// } - /// - /// @Directive( - /// selector: 'needs-greeter' - /// ) - /// class NeedsGreeter { - /// final Greeter greeter; - /// - /// NeedsGreeter(this.greeter); - /// } + /// @Directive( + /// selector: 'needs-greeter' + /// ) + /// class NeedsGreeter { + /// final Greeter greeter; /// - /// @Component( - /// selector: 'greet', - /// viewProviders: [ - /// Greeter - /// ], - /// template: '', - /// directives: [NeedsGreeter] - /// ) - /// class HelloWorld { - /// } + /// NeedsGreeter(this.greeter); + /// } /// + /// @Component( + /// selector: 'greet', + /// viewProviders: [Greeter], + /// template: '', + /// directives: [NeedsGreeter] + /// ) + /// class HelloWorld { + /// } + /// ``` final List viewProviders; /// A list of identifiers that may be referenced in the template. @@ -196,16 +197,16 @@ class Component extends Directive { /// ## Small Example /// /// Suppose you want to use an enum value in your template: + /// ``` + /// enum MyEnum { foo, bar, baz } /// - /// enum MyEnum { foo, bar, baz } - /// - /// @Component( - /// selector: 'example', - /// exports: const [MyEnum], - /// template: '

{{MyEnum.bar}}

', - /// ) - /// class Example {} - /// + /// @Component( + /// selector: 'example', + /// exports: [MyEnum], + /// template: '

{{MyEnum.bar}}

', + /// ) + /// class Example {} + /// ``` final List exports; final String? templateUrl; @@ -282,7 +283,7 @@ class Pipe { /// /// A [Directive] could read the string literal `'text'` like so: /// -/// ```dart +/// ``` /// @Directive(selector: 'input') /// class InputAttrDirective { /// InputAttrDirective(@Attribute('type') String type) { @@ -324,7 +325,7 @@ abstract class _Query { /// /// ### Example /// -/// ```dart +/// ``` /// @Component( /// selector: 'root-comp', /// directives: [TabPanelComponent, TabComponent], @@ -434,7 +435,7 @@ abstract class _ViewQuery extends _Query { /// /// With a [Type] selector: /// -/// ```dart +/// ``` /// @Component( /// selector: 'child-cmp', /// template: '

child

' @@ -454,12 +455,12 @@ abstract class _ViewQuery extends _Query { /// ) /// class SomeCmp implements AfterViewInit { /// @ViewChildren(ChildCmp) -/// List children; +/// List? children; /// /// @override /// void ngAfterViewInit() { /// // children are set -/// for (var child in children) { +/// for (var child in children!) { /// child.doSomething(); /// } /// } @@ -468,7 +469,7 @@ abstract class _ViewQuery extends _Query { /// /// With a [String] selector: /// -/// ```dart +/// ``` /// @Component( /// selector: 'child-cmp', /// template: '

child

', @@ -488,12 +489,12 @@ abstract class _ViewQuery extends _Query { /// ) /// class SomeCmp implements AfterViewInit { /// @ViewChildren('child1, child2, child3') -/// List children; +/// List? children; /// /// @override /// void ngAfterViewInit() { /// // Initial children are set -/// for (var child in children) { +/// for (var child in children!) { /// child.doSomething(); /// } /// } @@ -502,7 +503,7 @@ abstract class _ViewQuery extends _Query { /// /// Using a _setter_ for update notifications: /// -/// ```dart +/// ``` /// @Component( /// selector: 'child-cmp', /// template: '

child

', @@ -545,7 +546,7 @@ abstract class _ViewQuery extends _Query { /// /// Reading an HTML element using `read`: /// -/// ```dart +/// ``` /// @Component( /// selector: 'child-cmp', /// template: '

child

', @@ -565,7 +566,7 @@ abstract class _ViewQuery extends _Query { /// ) /// class SomeCmp { /// @ViewChildren('child1, child2, child3', read: Element) -/// List children; +/// List? children; /// } /// ``` /// @@ -596,7 +597,7 @@ class ViewChildren extends _ViewQuery { /// represents a single (or first, if more than one is found) node being queried /// - similar to `querySelector` instead of `querySelectorAll`. /// -/// ```dart +/// ``` /// @Component( /// selector: 'child-cmp', /// template: '

child

', @@ -610,7 +611,7 @@ class ViewChildren extends _ViewQuery { /// ) /// class SomeCmp { /// @ViewChild(ChildCmp) -/// ChildCmp child; +/// ChildCmp? child; /// } /// ``` /// @@ -638,32 +639,34 @@ class ViewChild extends _ViewQuery { /// /// The following example creates a component with two input properties. /// -/// ```dart +/// ``` +/// @Component( +/// selector: 'bank-account', +/// template: ''' +/// Bank Name: {{bankName}} +/// Account Id: {{id}} +/// ''', +/// ) +/// class BankAccount { +/// @Input() +/// String bankName; +/// +/// @Input('account-id') +/// String id; +/// +/// // this property is not bound, and won't be automatically updated +/// String normalizedBankName; +/// } +/// /// @Component( -/// selector: 'bank-account', -/// template: ''' -/// Bank Name: {{bankName}} -/// Account Id: {{id}} -/// ''') -/// class BankAccount { -/// @Input() -/// String bankName; -/// -/// @Input('account-id') -/// String id; -/// -/// // this property is not bound, and won't be automatically updated -/// String normalizedBankName; -/// } -/// -/// @Component( -/// selector: 'app', -/// template: ''' -/// -/// ''', -/// directives: const [BankAccount]) -/// class App {} -/// ``` +/// selector: 'app', +/// template: ''' +/// +/// ''', +/// directives: [BankAccount], +/// ) +/// class App {} +/// ``` @Target({ TargetKind.field, TargetKind.setter, @@ -685,14 +688,14 @@ class Input { /// /// ### Example /// -/// ```dart +/// ``` /// @Directive(selector: 'interval-dir') /// class IntervalDir { -/// final _everySecond = new StreamController(); +/// final _everySecond = StreamController(); /// @Output() /// final get everySecond => _everySecond.stream; /// -/// final _every5Secs = new StreamController(); +/// final _every5Secs = StreamController(); /// @Output('everyFiveSeconds') /// final get every5Secs => _every5Secs.stream; /// @@ -710,7 +713,7 @@ class Input { /// (everyFiveSeconds)="everyFiveSeconds()"> /// /// ''', -/// directives: const [IntervalDir]) +/// directives: [IntervalDir]) /// class App { /// void everySecond() { /// print('second'); @@ -780,7 +783,7 @@ class HostBinding { /// either `@Directive` or `@Component`, and is inherited when a class /// implements, extends, or mixes-in a class with this annotation. /// -/// ```dart +/// ``` /// @Component( /// selector: 'button-like', /// template: 'CLICK ME', @@ -795,13 +798,13 @@ class HostBinding { /// method with, including a magic argument `'\$event'`, which is replaced with /// the value of the event stream. In most cases [args] can be inferred when /// bound to a method with a single argument: -/// ```dart +/// ``` /// @Component( /// selector: 'button-like', /// template: 'CLICK ME', /// ) /// class ButtonLikeComponent { -/// @HostListener('click') // == @HostListener('click', const ['\$event']) +/// @HostListener('click') // == @HostListener('click', ['\$event']) /// void onClick(MouseEvent e) {} /// } /// ``` diff --git a/ngdart/lib/src/meta/lifecycle_hooks.dart b/ngdart/lib/src/meta/lifecycle_hooks.dart index 15d36b7d2f..eba3fd3c7c 100644 --- a/ngdart/lib/src/meta/lifecycle_hooks.dart +++ b/ngdart/lib/src/meta/lifecycle_hooks.dart @@ -9,6 +9,8 @@ /// - `onDestroy` (at the very end before destruction) library lifecycle_hooks; +import 'dart:async'; + /// Implement this interface to get notified when any data-bound property of /// your directive is changed by the Angular framework. /// @@ -27,11 +29,11 @@ abstract class AfterChanges { /// children have been checked. It is normally only invoked once when the /// directive is instantiated: /// -/// ```dart +/// ``` /// @Component( /// selector: 'user-panel', -/// directives: const [NgFor], -/// template: r''' +/// directives: [NgFor], +/// template: ''' ///
  • /// {{user}} ///
  • @@ -70,7 +72,7 @@ abstract class OnInit { /// component is being destroyed. [ngOnDestroy] may be used to cleanup resources /// such as [StreamSubscription]s: /// -/// ```dart +/// ``` /// @Component( /// selector: 'user-panel', /// template: 'Online users: {{count}}', @@ -140,7 +142,7 @@ abstract class DoCheck { /// Try this [live example][ex] from the [Lifecycle Hooks][docs] page: /// /// -/// ```dart +/// ``` /// template: ''' ///
    -- projected content begins --
    /// @@ -150,7 +152,7 @@ abstract class DoCheck { /// ``` /// /// -/// ```dart +/// ``` /// class AfterContentComponent implements AfterContentChecked, AfterContentInit { /// String _prevHero = ''; /// String comment = ''; @@ -182,8 +184,8 @@ abstract class DoCheck { /// } /// ``` /// -/// [docs]: https://webdev.dartlang.org/angular/guide/lifecycle-hooks.html#aftercontent -/// [ex]: https://webdev.dartlang.org/examples/lifecycle-hooks#after-content +/// [docs]: https://angulardart.xyz/guide/lifecycle-hooks.html#aftercontent +/// [ex]: https://angulardart.xyz/examples/lifecycle-hooks#after-content abstract class AfterContentInit { void ngAfterContentInit(); } @@ -196,7 +198,7 @@ abstract class AfterContentInit { /// Try this [live example][ex] from the [Lifecycle Hooks][docs] page: /// /// -/// ```dart +/// ``` /// template: ''' ///
    -- projected content begins --
    /// @@ -206,7 +208,7 @@ abstract class AfterContentInit { /// ``` /// /// -/// ```dart +/// ``` /// class AfterContentComponent implements AfterContentChecked, AfterContentInit { /// String _prevHero = ''; /// String comment = ''; @@ -238,8 +240,8 @@ abstract class AfterContentInit { /// } /// ``` /// -/// [docs]: https://webdev.dartlang.org/angular/guide/lifecycle-hooks.html#aftercontent -/// [ex]: https://webdev.dartlang.org/examples/lifecycle-hooks#after-content +/// [docs]: https://angulardart.xyz/guide/lifecycle-hooks.html#aftercontent +/// [ex]: https://angulardart.xyz/examples/lifecycle-hooks#after-content abstract class AfterContentChecked { void ngAfterContentChecked(); } @@ -252,7 +254,7 @@ abstract class AfterContentChecked { /// Try this [live example][ex] from the [Lifecycle Hooks][docs] page: /// /// -/// ```dart +/// ``` /// template: ''' ///
    -- child view begins --
    /// @@ -261,7 +263,7 @@ abstract class AfterContentChecked { /// ``` /// /// -/// ```dart +/// ``` /// class AfterViewComponent implements AfterViewChecked, AfterViewInit { /// var _prevHero = ''; /// @@ -291,8 +293,8 @@ abstract class AfterContentChecked { /// } /// ``` /// -/// [docs]: https://webdev.dartlang.org/angular/guide/lifecycle-hooks.html#afterview -/// [ex]: https://webdev.dartlang.org/examples/lifecycle-hooks#after-view +/// [docs]: https://angulardart.xyz/guide/lifecycle-hooks.html#afterview +/// [ex]: https://angulardart.xyz/examples/lifecycle-hooks#after-view abstract class AfterViewInit { void ngAfterViewInit(); } @@ -305,7 +307,7 @@ abstract class AfterViewInit { /// Try this [live example][ex] from the [Lifecycle Hooks][docs] page: /// /// -/// ```dart +/// ``` /// template: ''' ///
    -- child view begins --
    /// @@ -314,7 +316,7 @@ abstract class AfterViewInit { /// ``` /// /// -/// ```dart +/// ``` /// class AfterViewComponent implements AfterViewChecked, AfterViewInit { /// var _prevHero = ''; /// @@ -344,8 +346,8 @@ abstract class AfterViewInit { /// } /// ``` /// -/// [docs]: https://webdev.dartlang.org/angular/guide/lifecycle-hooks.html#afterview -/// [ex]: https://webdev.dartlang.org/examples/lifecycle-hooks#after-view +/// [docs]: https://angulardart.xyz/guide/lifecycle-hooks.html#afterview +/// [ex]: https://angulardart.xyz/examples/lifecycle-hooks#after-view abstract class AfterViewChecked { void ngAfterViewChecked(); } diff --git a/ngdart/lib/src/meta/typed.dart b/ngdart/lib/src/meta/typed.dart index e0eb11ebfc..93b3de11ad 100644 --- a/ngdart/lib/src/meta/typed.dart +++ b/ngdart/lib/src/meta/typed.dart @@ -88,10 +88,8 @@ class Typed { /// ``` /// /// See [on] for details about this optional parameter. - const Typed({ - this.on, - }) : - // This actually needs to be null, the compiler checks if typeArguments + const Typed({this.on}) + : // This actually needs to be null, the compiler checks if typeArguments // is non-null to determine which constructor was used. typeArguments = null; @@ -126,11 +124,8 @@ class Typed { /// /// See the [typeArguments] and [on] fields for details about these /// parameters. - const Typed.of( - List typeArguments, { - this.on, - }) : - // We prevent passing in a non-null value (because this constructor + const Typed.of(List typeArguments, {this.on}) + : // We prevent passing in a non-null value (because this constructor // requires an actual List). The compiler checks this field and whether // it is null (or not) to determine which constructor was used. // ignore: prefer_initializing_formals diff --git a/ngdart/lib/src/meta/visibility.dart b/ngdart/lib/src/meta/visibility.dart index 3ec722cc73..b4c6e41b82 100644 --- a/ngdart/lib/src/meta/visibility.dart +++ b/ngdart/lib/src/meta/visibility.dart @@ -1,3 +1,5 @@ +import '../meta.dart'; + /// Options for configuring whether a directive class can be injected. /// /// See [Directive.visibility] for details including the default behavior. @@ -5,10 +7,10 @@ enum Visibility { /// The directive can only be injected "locally"; i.e. not from another view. /// /// For example, the following code will fail at runtime: - /// ```dart + /// ``` /// @Component( /// selector: 'parent', - /// directives: const [Child], + /// directives: [Child], /// template: '', /// /// // The default, but here explicitly for clarity. @@ -28,7 +30,7 @@ enum Visibility { /// /// However, if the `Parent` and `Child` components are in the same view, the /// example works: - /// ```dart + /// ``` /// @Component( /// selector: 'parent', /// template: '', @@ -49,7 +51,7 @@ enum Visibility { /// /// @Component( /// selector: 'app', - /// directives: const [Child, Parent], + /// directives: [Child, Parent], /// template: ''' /// /// @@ -63,15 +65,15 @@ enum Visibility { /// each other regardless of visibility. /// /// Furthermore, it is possible to provide another interface to children: - /// ```dart + /// ``` /// // An interface that will be provided by the Parent class. /// abstract class Example {} /// /// @Component( /// selector: 'parent', - /// directives: const [Child], - /// providers: const [ - /// const ExistingProvider(Example, useExisting: Parent), + /// directives: [Child], + /// providers: [ + /// ExistingProvider(Example, useExisting: Parent), /// ], /// template: '', /// ) @@ -88,7 +90,7 @@ enum Visibility { /// } /// ``` /// - /// ... like all uses of `providers: const [ ... ]`, this increases the cost + /// ... like all uses of `providers: [ ... ]`, this increases the cost /// of the component or directive, and should only be added when injection /// is truly needed, similar to [Visibility.all]. /// @@ -99,10 +101,10 @@ enum Visibility { /// The directive can be injected anywhere in the sub tree. /// - /// ```dart + /// ``` /// @Component( /// selector: 'parent', - /// directives: const [Child], + /// directives: [Child], /// template: '', /// visibility: Visibility.all, /// ) diff --git a/ngdart/lib/src/runtime/dom_helpers.dart b/ngdart/lib/src/runtime/dom_helpers.dart index aa702dc741..4ab1e3e4ee 100644 --- a/ngdart/lib/src/runtime/dom_helpers.dart +++ b/ngdart/lib/src/runtime/dom_helpers.dart @@ -36,7 +36,7 @@ var domRootRendererIsDirty = false; /// ``` /// /// ... would emit: -/// ```dart +/// ``` /// updateClassBinding(_divElement, 'warning', isWarning); /// ``` /// @@ -135,7 +135,7 @@ void setProperty( /// /// For example, the naive way of creating text nodes would be: /// -/// ```dart +/// ``` /// var a = Text('Hello'); /// var b = Text('World'); /// var c = Text('!') @@ -153,7 +153,7 @@ void setProperty( /// /// Where-as using [createText] minimizes the amount of code: /// -/// ```dart +/// ``` /// var d = document; /// var a = createText(d, 'Hello'); /// var b = createText(d, 'World'); diff --git a/ngdart/lib/src/security/safe_inner_html.dart b/ngdart/lib/src/security/safe_inner_html.dart index 88b884f7ce..2080f1c17d 100644 --- a/ngdart/lib/src/security/safe_inner_html.dart +++ b/ngdart/lib/src/security/safe_inner_html.dart @@ -7,7 +7,9 @@ import 'dom_sanitization_service.dart' show SafeHtml; /// Sets [Element.innerHtml] _without_ sanitizing the HTML output. /// /// Requires use of a [SafeHtml] wrapper created by [DomSanitizationService]: -/// var safeHtml = domSanitizationService.bypassSecurityTrustHtml('...'); +/// ``` +/// var safeHtml = domSanitizationService.bypassSecurityTrustHtml('...'); +/// ``` /// /// (This allows security reviews to easily search for and catch exceptions) /// @@ -17,10 +19,10 @@ import 'dom_sanitization_service.dart' show SafeHtml; /// /// __Example use__: /// -/// ```dart +/// ``` /// @Component( /// selector: 'my-component', -/// directives: const [SafeInnerHtmlDirective], +/// directives: [SafeInnerHtmlDirective], /// template: ''' ///
    /// ''', @@ -34,7 +36,9 @@ import 'dom_sanitization_service.dart' show SafeHtml; /// 'I solemnly swear that this is OK!'); /// } /// ``` -@Directive(selector: '[safeInnerHtml]') +@Directive( + selector: '[safeInnerHtml]', +) class SafeInnerHtmlDirective { final Element _element; diff --git a/ngforms/lib/ngforms.dart b/ngforms/lib/ngforms.dart index fc115faa61..d1b433815f 100644 --- a/ngforms/lib/ngforms.dart +++ b/ngforms/lib/ngforms.dart @@ -10,6 +10,8 @@ library ngforms; // name the library so we can run dartdoc on it by name. import 'src/directives/radio_control_value_accessor.dart' show RadioControlRegistry; +import 'src/model.dart' show Control, ControlGroup; + export 'src/directives.dart' show composeValidators, @@ -61,8 +63,11 @@ export 'src/validators.dart' show ngValidators, Validators; /// /// ### Example /// -/// ```dart -/// runApp(MyAppNgFactory, [formProviders]); +/// ``` +/// @GenerateInjector(formProviders) +/// final InjectorFactory injector = ng.injector$Injector; +/// +/// runApp(MyAppNgFactory, createInjector: injector); /// ```` const List formProviders = [RadioControlRegistry]; diff --git a/ngforms/lib/src/directives.dart b/ngforms/lib/src/directives.dart index 9b40f54098..2b183cba4f 100644 --- a/ngforms/lib/src/directives.dart +++ b/ngforms/lib/src/directives.dart @@ -60,10 +60,10 @@ export 'directives/validators.dart' /// /// ### Example /// -/// ```dart +/// ``` /// @Component( /// selector: 'my-app', -/// directives: const [formDirectives] +/// directives: [formDirectives] /// ) /// class MyApp {} /// ``` diff --git a/ngforms/lib/src/directives/ng_control_group.dart b/ngforms/lib/src/directives/ng_control_group.dart index 886a4ea63a..f3374fc8c0 100644 --- a/ngforms/lib/src/directives/ng_control_group.dart +++ b/ngforms/lib/src/directives/ng_control_group.dart @@ -6,6 +6,8 @@ import '../model.dart' show AbstractControlGroup; import '../validators.dart' show ngValidators; import 'control_container.dart' show ControlContainer; import 'form_interface.dart' show Form; +import 'ng_form.dart' show NgForm; +import 'ng_form_model.dart' show NgFormModel; import 'shared.dart' show controlPath, composeValidators; import 'validators.dart' show ValidatorFn; @@ -15,37 +17,37 @@ import 'validators.dart' show ValidatorFn; /// /// ### Example: /// -/// ```dart +/// ``` /// @Component( /// selector: 'my-app', -/// directives: const [formDirectives], +/// directives: [formDirectives], /// template: ''' ///
    ///

    Angular Control & AbstractControlGroup Example

    ///
    -///
    +///
    ///

    Enter your name:

    ///

    First:

    ///

    Middle:

    ///

    Last:

    ///
    ///

    Name value:

    -///
    {{valueOf(cgName)}}
    -///

    Name is {{cgName?.control?.valid ? "valid" : "invalid"}}

    +///
    {{valueOf(name)}}
    +///

    Name is {{name.control!.valid ? "valid" : "invalid"}}

    ///

    What's your favorite food?

    ///

    ///

    Form value

    ///
    {{valueOf(f)}}
    /// ///
    -/// ''' -/// }) +/// ''', +/// ) /// class App { -/// String valueOf(NgControlGroup cg) { -/// if (cg.control == null) { +/// String? valueOf(ControlContainer cc) { +/// if (cc.control == null) { /// return null; /// } -/// return json.encode(cg.control.value, null, 2); +/// return json.encode(cc.control!.value); /// } /// } /// ``` diff --git a/ngforms/lib/src/directives/ng_control_name.dart b/ngforms/lib/src/directives/ng_control_name.dart index 49cdc3555c..750b1dc70c 100644 --- a/ngforms/lib/src/directives/ng_control_name.dart +++ b/ngforms/lib/src/directives/ng_control_name.dart @@ -8,6 +8,8 @@ import 'control_container.dart' show ControlContainer; import 'control_value_accessor.dart' show ControlValueAccessor, ngValueAccessor; import 'form_interface.dart' show Form; import 'ng_control.dart' show NgControl; +import 'ng_form.dart' show NgForm; +import 'ng_form_model.dart' show NgFormModel; import 'shared.dart' show controlPath; /// Creates and binds a control with a specified name to a DOM element. @@ -20,47 +22,50 @@ import 'shared.dart' show controlPath; /// We can work with each control separately: check its validity, get its value, listen to its /// changes. /// -/// ```dart +/// ``` /// @Component( -/// selector: "login-comp", -/// directives: const [formDirectives], -/// template: ''' -///
    -/// Login -///
    Login is invalid
    +/// selector: 'login-comp', +/// directives: [coreDirectives, formDirectives], +/// template: ''' +/// +/// Login +///
    Login is invalid
    /// -/// Password -/// -///
    -/// ''') +/// Password +/// +/// +/// ''', +/// ) /// class LoginComp { /// void onLogIn(value) { -/// // value === {'login': 'some login', 'password': 'some password'} +/// // value == {'login': 'some login', 'password': 'some password'} /// } /// } /// ``` /// /// We can also use ngModel to bind a domain model to the form. /// -/// ```dart +/// ``` /// @Component( -/// selector: "login-comp", -/// directives: [formDirectives], -/// template: ''' -///
    -/// Login -/// Password -/// -///
    -/// ''') +/// selector: 'login-comp', +/// directives: [formDirectives], +/// template: ''' +///
    +/// Login +/// Password +/// +///
    +/// ''') /// class LoginComp { -/// credentials: {login:string, password:string}; +/// String? login; /// -/// onLogIn(): void { -/// // credentials.login === "some login" -/// // credentials.password === "some password" -/// } +/// String? password; +/// +/// void onLogIn() { +/// // login == 'some login' +/// // password == some password' +/// } /// } /// ``` @Directive( diff --git a/ngforms/lib/src/directives/ng_form.dart b/ngforms/lib/src/directives/ng_form.dart index f28b9d0baa..8eff255583 100644 --- a/ngforms/lib/src/directives/ng_form.dart +++ b/ngforms/lib/src/directives/ng_form.dart @@ -33,9 +33,10 @@ import 'shared.dart' show setUpControl, setUpControlGroup, composeValidators; /// /// ### Example /// -/// ```dart +/// ``` /// @Component( /// selector: 'my-app', +/// directives: [coreDirectives, formDirectives], /// template: ''' ///
    ///

    Submit the form to see the data object Angular builds

    @@ -55,15 +56,14 @@ import 'shared.dart' show setUpControl, setUpControlGroup, composeValidators; ///

    Form data submitted:

    /// ///
    {{data}}
    -///
    ''', -/// directives: const [coreDirectives, formDirectives] -/// }) +///
    +/// ''', +/// ) /// class App { -/// -/// String data; +/// String? data; /// /// void onSubmit(data) { -/// data = JSON.encode(data); +/// this.data = json.encode(data); /// } /// } /// ``` diff --git a/ngforms/lib/src/directives/ng_form_control.dart b/ngforms/lib/src/directives/ng_form_control.dart index 85fb402af2..21f528858e 100644 --- a/ngforms/lib/src/directives/ng_form_control.dart +++ b/ngforms/lib/src/directives/ng_form_control.dart @@ -16,9 +16,10 @@ import 'shared.dart' show setUpControl; /// changes, the value of the control will reflect that change. Likewise, if the value of the /// control changes, the input element reflects that change. /// -/// ```dart +/// ``` /// @Component( /// selector: 'my-app', +/// directives: [coreDirectives, formDirectives] /// template: ''' ///
    ///

    NgFormControl Example

    @@ -30,10 +31,9 @@ import 'shared.dart' show setUpControl; /// ///
    /// ''', -/// directives: const [coreDirectives, formDirectives] /// ) /// class App { -/// Control loginControl = new Control(''); +/// Control loginControl = Control(''); /// } /// ``` /// @@ -43,15 +43,17 @@ import 'shared.dart' show setUpControl; /// /// ### Example /// -/// ```dart +/// ``` /// @Component( -/// selector: "login-comp", -/// directives: const [formDirectives], -/// template: "" -/// ) +/// selector: 'login-comp', +/// directives: [formDirectives], +/// template: ''' +/// +/// ''', +/// ) /// class LoginComp { -/// Control loginControl = new Control(''); -/// String login; +/// Control loginControl = new Control(''); +/// String? login; /// } /// ``` @Directive( diff --git a/ngforms/lib/src/directives/ng_form_model.dart b/ngforms/lib/src/directives/ng_form_model.dart index 0b61c35be4..2c82da8901 100644 --- a/ngforms/lib/src/directives/ng_form_model.dart +++ b/ngforms/lib/src/directives/ng_form_model.dart @@ -16,13 +16,14 @@ import 'validators.dart' show ValidatorFn; /// In this example, we bind the control group to the form element, and we bind /// the login and password controls to the login and password elements. /// -/// ```dart +/// ``` /// @Component( /// selector: 'my-app', +/// directives: [formDirectives], /// template: ''' ///
    ///

    NgFormModel Example

    -///
    {{value}} ///
    /// ''', -/// directives: const [formDirectives] -/// }) +/// ) /// class App { -/// ControlGroup loginForm; -/// -/// App() { -/// loginForm = new ControlGroup({ -/// login: new Control(""), -/// password: new Control("") -/// }); -/// } +/// ControlGroup loginForm = ControlGroup({ +/// 'login': Control(''), +/// 'password': Control(''), +/// }); /// /// String get value { -/// return JSON.encode(loginForm.value); +/// return json.encode(loginForm.value); /// } /// } /// ``` /// /// We can also use ngModel to bind a domain model to the form. /// -/// ```dart +/// ``` /// @Component( -/// selector: "login-comp", -/// directives: const [formDirectives], -/// template: ''' -/// -/// Login -/// Password -/// -/// ''' -/// ) -/// class LoginComp { -/// credentials: {login: string, password: string}; -/// ControlGroup loginForm; +/// selector: 'login-comp', +/// directives: [formDirectives], +/// template: ''' +///
    +/// Login +/// Password +/// +///
    +/// ''', +/// ) +/// class HelloWorldComponent { +/// String? login; +/// String? password; /// -/// LoginComp() { -/// loginForm = new ControlGroup({ -/// login: new Control(""), -/// password: new Control("") -/// }); -/// } +/// ControlGroup loginForm = ControlGroup({ +/// 'login': Control(''), +/// 'password': Control(''), +/// }); /// -/// void onLogin() { -/// // credentials.login === 'some login' -/// // credentials.password === 'some password' -/// } +/// void onLogin() { +/// // login == 'some login' +/// // password == 'some password' +/// } /// } /// ``` @Directive( diff --git a/ngforms/lib/src/directives/ng_model.dart b/ngforms/lib/src/directives/ng_model.dart index a30cd430aa..3d32991670 100644 --- a/ngforms/lib/src/directives/ng_model.dart +++ b/ngforms/lib/src/directives/ng_model.dart @@ -25,8 +25,8 @@ import 'shared.dart' show setUpControl; /// /// Learn more about `ngModel` in the [Forms][] and [Template Syntax][TS] pages. /// -/// [Forms]: https://angulardart.dev/angular/guide/forms#ngModel -/// [TS]: https://angulardart.dev/angular/guide/template-syntax#ngModel +/// [Forms]: https://angulardart.xyz/angular/guide/forms#ngModel +/// [TS]: https://angulardart.xyz/angular/guide/template-syntax#ngModel /// /// ### Examples /// @@ -46,7 +46,7 @@ import 'shared.dart' show setUpControl; /// /// Try the [live example][ex]. /// -/// [ex]: https://angulardart.dev/examples/template-syntax/#ngModel +/// [ex]: https://angulardart.xyz/examples/template-syntax/#ngModel @Directive( selector: '[ngModel]:not([ngControl]):not([ngFormControl])', providers: [ diff --git a/ngforms/lib/src/directives/radio_control_value_accessor.dart b/ngforms/lib/src/directives/radio_control_value_accessor.dart index 9f0d4657d0..9cebecdc4e 100644 --- a/ngforms/lib/src/directives/radio_control_value_accessor.dart +++ b/ngforms/lib/src/directives/radio_control_value_accessor.dart @@ -55,7 +55,7 @@ class RadioButtonState { /// /// ### Example /// -/// ```dart +/// ``` /// @Component( /// template: ''' /// diff --git a/ngforms/lib/src/directives/validators.dart b/ngforms/lib/src/directives/validators.dart index 98b3c3293d..151660ccdd 100644 --- a/ngforms/lib/src/directives/validators.dart +++ b/ngforms/lib/src/directives/validators.dart @@ -7,11 +7,11 @@ import '../validators.dart' show Validators, ngValidators; /// /// ## Usage /// -/// ```dart +/// ``` /// @Directive( /// selector: '[custom-validator]', -/// providers: const [ -/// const ExistingProvider.forToken( +/// providers: [ +/// ExistingProvider.forToken( /// ngValidators, /// CustomValidatorDirective, /// ), @@ -19,7 +19,7 @@ import '../validators.dart' show Validators, ngValidators; /// ) /// class CustomValidatorDirective implements Validator { /// @override -/// Map validate(AbstractControl control) { +/// Map? validate(AbstractControl control) { /// // The length of the input string can't be longer than 14 characters. /// final value = c.value; /// if (value is String && value.length > 14) { diff --git a/ngforms/lib/src/form_builder.dart b/ngforms/lib/src/form_builder.dart index d23ea13c69..418d4110ff 100644 --- a/ngforms/lib/src/form_builder.dart +++ b/ngforms/lib/src/form_builder.dart @@ -1,12 +1,13 @@ import 'directives/validators.dart'; -import 'model.dart' as model_module; +import 'model.dart'; /// Creates a form object from a user-specified configuration. /// -/// ```dart +/// ``` /// @Component( /// selector: 'my-app', -/// viewProviders: const [FORM_BINDINGS] +/// directives: [formDirectives], +/// viewProviders: [formBindings], /// template: ''' ///
    ///

    Login

    @@ -19,62 +20,55 @@ import 'model.dart' as model_module; ///

    Form value:

    ///
    {{value}}
    /// ''', -/// directives: const [formDirectives] /// ) /// class App { -/// ControlGroup loginForm; -/// -/// App() { -/// final builder = new FormBuilder(); -/// loginForm = builder.group({ -/// "login": ["", Validators.required], -/// "passwordRetry": builder.group({ -/// "password": ["", Validators.required], -/// "passwordConfirmation": ["", Validators.required] -/// }) -/// }); -/// } +/// ControlGroup loginForm = FormBuilder.controlGroup({ +/// 'login': ['', Validators.required], +/// 'passwordRetry': FormBuilder.controlGroup({ +/// 'password': ['', Validators.required], +/// 'passwordConfirmation': ['', Validators.required] +/// }) +/// }); /// /// String get value { -/// return JSON.encode(loginForm.value); +/// return json.encode(loginForm.value); /// } /// } /// ``` class FormBuilder { - /// Construct a new [ControlGroup] with the given map of configuration. - /// Valid keys for the `extra` parameter map are [optionals] and [validator]. + /// Construct a new [ControlGroup] with the given map of configuration, + /// with the given optional [validator]. /// /// See the [ControlGroup] constructor for more details. - static model_module.ControlGroup controlGroup( - Map controlsConfig, + static ControlGroup controlGroup(Map controlsConfig, {ValidatorFn? validator}) { var controls = _reduceControls(controlsConfig); - return model_module.ControlGroup(controls, validator); + return ControlGroup(controls, validator); } /// Construct an array of [Control]s from the given [controlsConfig] array of /// configuration, with the given optional [validator]. - static model_module.ControlArray controlArray(List controlsConfig, + static ControlArray controlArray(List controlsConfig, [ValidatorFn? validator]) { var controls = controlsConfig.map(_createControl).toList(); - return model_module.ControlArray(controls, validator); + return ControlArray(controls, validator); } - static Map _reduceControls( + static Map _reduceControls( Map controlsConfig) => controlsConfig.map((controlName, controlConfig) => MapEntry(controlName, _createControl(controlConfig))); - static model_module.AbstractControl _createControl(dynamic controlConfig) { - if (controlConfig is model_module.AbstractControl) { + static AbstractControl _createControl(dynamic controlConfig) { + if (controlConfig is AbstractControl) { return controlConfig; } else if (controlConfig is List) { var value = controlConfig[0]; var validator = controlConfig.length > 1 ? controlConfig[1] as ValidatorFn : null; - return model_module.Control(value, validator); + return Control(value, validator); } else { - return model_module.Control(controlConfig, null); + return Control(controlConfig, null); } } diff --git a/ngforms/lib/src/model.dart b/ngforms/lib/src/model.dart index 9e7ae376d9..15f1c9e30f 100644 --- a/ngforms/lib/src/model.dart +++ b/ngforms/lib/src/model.dart @@ -2,6 +2,9 @@ import 'dart:async'; import 'package:meta/meta.dart'; +import 'directives/control_value_accessor.dart' show ControlValueAccessor; +import 'directives/ng_form_control.dart' show NgFormControl; +import 'directives/ng_form_model.dart' show NgFormModel; import 'directives/validators.dart' show ValidatorFn; AbstractControl? _find(AbstractControl control, List? path) { @@ -267,11 +270,9 @@ abstract class AbstractControl { /// /// ## Usage /// - /// ```dart - /// Control login = new Control("someLogin"); - /// login.setErrors({ - /// "notUnique": true - /// }); + /// ``` + /// Control login = Control("someLogin"); + /// login.setErrors({"notUnique": true}); /// /// expect(login.valid).toEqual(false); /// expect(login.errors).toEqual({"notUnique": true}); @@ -303,7 +304,7 @@ abstract class AbstractControl { /// /// If no match is found, returns null. /// - /// For [ControlGroups], matches on name. For [ControlArray], it parses an int + /// For [ControlGroup]s, matches on name. For [ControlArray], it parses an int /// to match on index. AbstractControl? findPath(List? path) => _find(this, path); @@ -467,8 +468,8 @@ class Control extends AbstractControl { /// Register a listener for change events. /// - /// Used internally to connect the model with the [ValueAccessor] which will - /// write the model value to the View. + /// Used internally to connect the model with the [ControlValueAccessor] + /// which will write the model value to the View. /// NOTE: Should only be called internally by angular. Use [valueChanges] or /// [statusChanges] to get updates on the [Control]. void registerOnChange(Function fn) { diff --git a/ngforms/lib/src/validators.dart b/ngforms/lib/src/validators.dart index 5274e9f1bd..3dc1fb7666 100644 --- a/ngforms/lib/src/validators.dart +++ b/ngforms/lib/src/validators.dart @@ -16,8 +16,8 @@ const ngValidators = MultiToken('NgValidators'); /// /// ### Example /// -/// ```dart -/// Control loginControl = new Control("", Validators.required) +/// ``` +/// Control loginControl = Control("", Validators.required) /// ``` class Validators { /// Validator that requires controls to have a non-empty value. diff --git a/ngrouter/lib/src/constants.dart b/ngrouter/lib/src/constants.dart index c1d332198e..0b9e65ca93 100644 --- a/ngrouter/lib/src/constants.dart +++ b/ngrouter/lib/src/constants.dart @@ -27,7 +27,7 @@ const routerDirectives = [RouterOutlet, RouterLink, RouterLinkActive]; /// ``` /// @GenerateInjector([routerProviders]) /// final InjectorFactory appInjector = ng.appInjector$Injector; -/// ... +/// // ... /// runApp(ng.MyAppComponentNgFactory, createInjector: appInjector); /// ``` const routerProviders = [ @@ -54,7 +54,7 @@ const routerModule = Module(provide: routerProviders); /// ``` /// @GenerateInjector([routerProvidersHash]) /// final InjectorFactory appInjector = ng.appInjector$Injector; -/// ... +/// // ... /// runApp(ng.MyAppComponentNgFactory, createInjector: appInjector); /// ``` const routerProvidersHash = [ @@ -70,7 +70,7 @@ const routerProvidersHash = [ /// ``` /// @GenerateInjector.fromModules([routerHashModule]) /// final InjectorFactory appInjector = ng.appInjector$Injector; -/// ... +/// // ... /// runApp(ng.MyAppComponentNgFactory, createInjector: appInjector); /// ``` const routerHashModule = Module(provide: routerProvidersHash); diff --git a/ngrouter/lib/src/directives/router_link_directive.dart b/ngrouter/lib/src/directives/router_link_directive.dart index b9b5141498..42f2423354 100644 --- a/ngrouter/lib/src/directives/router_link_directive.dart +++ b/ngrouter/lib/src/directives/router_link_directive.dart @@ -5,6 +5,7 @@ import 'dart:html' import 'package:ngdart/angular.dart'; import '../location.dart' show Location; +import '../route_path.dart'; import '../router/navigation_params.dart'; import '../router/router.dart'; import '../url.dart'; @@ -14,7 +15,7 @@ import '../url.dart'; /// ```html /// Heroes /// ``` -/// Can also be used with [RouterPath]. +/// Can also be used with [RoutePath]. /// ```html /// Heroes /// ``` diff --git a/ngrouter/lib/src/lifecycle.dart b/ngrouter/lib/src/lifecycle.dart index 9447940108..4f5703eb46 100644 --- a/ngrouter/lib/src/lifecycle.dart +++ b/ngrouter/lib/src/lifecycle.dart @@ -26,7 +26,7 @@ abstract class CanActivate { /// ``` /// class MyComponent implements CanActivate { /// @override - /// Future canActivate(RouterState _, RouterState __) async { + /// Future canActivate(RouterState current, RouterState next) async { /// // Maybe this page isn't ready yet for production, so always reject. /// return false; /// } @@ -65,8 +65,9 @@ abstract class CanDeactivate { /// Future canDeactivate( /// RouterState current, /// RouterState next, - /// ) async => - /// current.parameters['id'] != next.parameters['id']; + /// ) async { + /// return current.parameters['id'] != next.parameters['id']; + /// } /// } /// ``` /// @@ -156,12 +157,12 @@ abstract class OnActivate { /// **NOTE**: If the component also extends [CanReuse] and is reused, this /// will be called again on the same instance. /// - /// ```dart + /// ``` /// class MyComponent extends CanReuse implements OnActivate { /// User user; /// /// @override - /// void onActivate(_, RouterState current) { + /// void onActivate(RouterState? previous, RouterState current) { /// var userId = current.getParameter('userId'); /// getUserById(userId).then((user) => this.user = user); /// } diff --git a/ngrouter/lib/src/location/hash_location_strategy.dart b/ngrouter/lib/src/location/hash_location_strategy.dart index f974b8f560..c35eab9ea9 100644 --- a/ngrouter/lib/src/location/hash_location_strategy.dart +++ b/ngrouter/lib/src/location/hash_location_strategy.dart @@ -22,9 +22,7 @@ import 'platform_location.dart' show PlatformLocation; /// /// @Component( /// // Should only be provided at the root. -/// providers: [ -/// routerProvidersHash, -/// ], +/// providers: [routerProvidersHash], /// ) /// class AppComponent { /// AppComponent(Location location) { diff --git a/ngrouter/lib/src/location/location_strategy.dart b/ngrouter/lib/src/location/location_strategy.dart index d5bc17199c..cf376fd42b 100644 --- a/ngrouter/lib/src/location/location_strategy.dart +++ b/ngrouter/lib/src/location/location_strategy.dart @@ -2,6 +2,10 @@ import 'dart:html'; import 'package:ngdart/angular.dart' show OpaqueToken; +import '../location/hash_location_strategy.dart'; +import '../location/path_location_strategy.dart'; +import '../router/router.dart'; + /// `LocationStrategy` is responsible for representing and reading route state /// from the browser's URL. Angular provides two strategies: /// [HashLocationStrategy] and [PathLocationStrategy] (default). @@ -32,7 +36,7 @@ abstract class LocationStrategy { /// The [appBaseHref] token represents the base HREF to be used for the router. /// /// For example, if your site is at `/my/app` on your host: -/// ```dart +/// ``` /// const ValueProvider.forToken(appBaseHref, '/my/app'); /// ``` const appBaseHref = OpaqueToken('appBaseHref'); diff --git a/ngrouter/lib/src/router/navigation_params.dart b/ngrouter/lib/src/router/navigation_params.dart index df2ec976da..0ae3c4d355 100644 --- a/ngrouter/lib/src/router/navigation_params.dart +++ b/ngrouter/lib/src/router/navigation_params.dart @@ -1,8 +1,10 @@ +import '../router/router.dart'; + /// Additional parameters for [Router.navigate]. class NavigationParams { /// A map of parameters for the querystring of a URL. /// - /// For example: /url?name=john has queryParameters of {'name': 'john'} + /// For example: `/url?name=john` has queryParameters of `{'name': 'john'}` final Map queryParameters; /// The hash fragment for a URL. diff --git a/ngrouter/lib/src/router/router.dart b/ngrouter/lib/src/router/router.dart index 38d9a8b700..c7d514eeb2 100644 --- a/ngrouter/lib/src/router/router.dart +++ b/ngrouter/lib/src/router/router.dart @@ -1,4 +1,6 @@ import '../directives/router_outlet_directive.dart'; +import '../lifecycle.dart'; +import '../router_hook.dart'; import 'navigation_params.dart'; import 'router_state.dart'; @@ -46,7 +48,7 @@ abstract class Router { /// /// This occurs after the [RouterHook] (if any) has rewritten the path and /// parameters and the final non-redirecting route has been resolved, but - /// before any [CanActivate] and [CanDeactive] implementations are checked. + /// before any [CanActivate] and [CanDeactivate] implementations are checked. Stream get onRouteResolved; /// Emits the next router state after a new route is activated. diff --git a/ngrouter/lib/src/router/router_outlet_token.dart b/ngrouter/lib/src/router/router_outlet_token.dart index 5d21363f54..79427f4645 100644 --- a/ngrouter/lib/src/router/router_outlet_token.dart +++ b/ngrouter/lib/src/router/router_outlet_token.dart @@ -1,6 +1,7 @@ import 'package:ngdart/angular.dart'; import '../directives/router_outlet_directive.dart'; +import '../router/router.dart'; /// **INTERNAL ONLY**: An injected token to access [RouterOutlet]s. /// diff --git a/ngrouter/lib/src/router/router_state.dart b/ngrouter/lib/src/router/router_state.dart index 459710a0fa..1dbcd8947f 100644 --- a/ngrouter/lib/src/router/router_state.dart +++ b/ngrouter/lib/src/router/router_state.dart @@ -12,8 +12,8 @@ class RouterState extends Url { /// A map of URL parameters. /// - /// If matched RouteDefinition has a path '/customer/:id' and the URL is - /// '/customer/5', parameters would equal { 'id': '5' }. + /// If matched RouteDefinition has a path `/customer/:id` and the URL is + /// `/customer/5`, parameters would equal `{ 'id': '5' }`. final Map parameters; /// Whether this state was caused by a `popstate` event. diff --git a/ngrouter/lib/testing.dart b/ngrouter/lib/testing.dart index 1ce3eb20f5..8f223b2a6b 100644 --- a/ngrouter/lib/testing.dart +++ b/ngrouter/lib/testing.dart @@ -21,9 +21,7 @@ export 'src/route_definition.dart' /// ``` /// @Component( /// selector: '...', -/// providers: [ -/// routerProvidersTest, -/// ], +/// providers: [routerProvidersTest], /// ) /// class TestComponent {} /// ``` @@ -42,7 +40,7 @@ const routerProvidersTest = [ /// ``` /// @GenerateInjector.fromModules([routerTestModule]) /// final InjectorFactory testInjector = ng.testInjector$Injector; -/// ... +/// // ... /// final testBed = NgTestBed( /// ng.TestComponentNgFactory, /// rootInjector: testInjector); diff --git a/ngtest/lib/src/frontend/bed.dart b/ngtest/lib/src/frontend/bed.dart index c528f5b6d8..1ca84a28ed 100644 --- a/ngtest/lib/src/frontend/bed.dart +++ b/ngtest/lib/src/frontend/bed.dart @@ -19,7 +19,7 @@ NgTestFixture? activeTest; /// /// This function is meant to be used within /// the `tearDown` function of `package:test`: -/// ```dart +/// ``` /// tearDown(() => disposeAnyRunningTest()); /// ``` Future disposeAnyRunningTest() async { @@ -32,7 +32,7 @@ Future disposeAnyRunningTest() async { /// root application component you would create normally with `bootstrap`. /// /// For a simple test: -/// ```dart +/// ``` /// group('$HelloWorldComponent', () { /// tearDown(() => disposeAnyRunningTest()); /// @@ -45,7 +45,7 @@ Future disposeAnyRunningTest() async { /// ``` /// /// New behavior and features can be added in a hierarchy of tests: -/// ```dart +/// ``` /// group('My tests', () { /// NgTestBed bed; /// NgTestFixture fixture; @@ -60,7 +60,7 @@ Future disposeAnyRunningTest() async { /// /// test('should render "Hello World" in all-caps', () async { /// bed = bed.addProviders(const [ -/// const Provider(TextFormatter, useClass: AllCapsTextFormatter), +/// ClassProvider(TextFormatter, AllCapsTextFormatter), /// ]); /// fixture = await bed.create(); /// expect(fixture.text, contains('HELLO WORLD')); @@ -106,19 +106,12 @@ class NgTestBed { /// Create a new [NgTestBed] that uses the provided [component] factory. /// - /// Some APIs are not supported outside of [NgTestBed.useInitReflector]: - /// - /// * [addProviders] will throw [UnsupportedError]; instead, the [addInjector] - /// API allows you to wrap the previous [Injector], if any, to provide - /// additional services. In most cases just [rootInjector] is enough, and - /// you could re-use providers via [GenerateInjector]. - /// - /// ```dart + /// ``` /// void main() { /// final ngTestBed = NgTestBed( /// SomeComponentNgFactory, - /// rootInjector: ([parent]) => new Injector.map({ - /// Service: new Service(), + /// rootInjector: ([parent]) => Injector.map({ + /// Service: Service(), /// }, parent), /// ); /// } diff --git a/ngtest/lib/src/frontend/fixture.dart b/ngtest/lib/src/frontend/fixture.dart index 47e4989465..ed52699608 100644 --- a/ngtest/lib/src/frontend/fixture.dart +++ b/ngtest/lib/src/frontend/fixture.dart @@ -54,7 +54,7 @@ class NgTestFixture { /// and often you'd want to assert against the _final_ state. /// /// #Example use - /// ```dart + /// ``` /// expect(fixture.text, contains('Loading...')); /// await fixture.update(); /// expect(fixture.text, contains('Hello World')); @@ -90,7 +90,7 @@ class NgTestFixture { /// expects of the instance state. /// /// #Example - /// ```dart + /// ``` /// await fixture.update((c) { /// c.value = 5; /// }); diff --git a/ngtest/lib/src/frontend/stabilizer.dart b/ngtest/lib/src/frontend/stabilizer.dart index 951f9ffa25..b481fb5927 100644 --- a/ngtest/lib/src/frontend/stabilizer.dart +++ b/ngtest/lib/src/frontend/stabilizer.dart @@ -40,18 +40,18 @@ NgTestStabilizerFactory composeStabilizers( /// DOM as-if you were a user with a browser, and assert the state of the DOM /// instead of the state of the component. For example, a toggle button that /// switches between 'Yes' and 'No' when clicked: -/// ```dart +/// ``` /// testToggleButton(ButtonElement button) { /// expect(button.text, 'Yes'); /// button.click(); /// expect(button.text, 'No'); /// } -/// ```dart +/// ``` /// /// In the case of Angular, and of other DOM-related libraries, however, the /// changes are not always applied immediately (synchronously). Instead, we need /// a contract that lets us `await` any possible changes, and then assert state: -/// ```dart +/// ``` /// testToggleButton(ButtonElement button, NgTestStabilizer dom) async { /// expect(button.text, 'Yes'); /// await dom.update(() => button.click());