Skip to content

Commit

Permalink
refactor(ngforms)!: rename providers & fix all static warnings (#54)
Browse files Browse the repository at this point in the history
* Fix all analyzer warnings. Move control statuses.

* test(ngforms): remove unnecessary lint

Signed-off-by: Gavin Zhao <[email protected]>

---------

Signed-off-by: Gavin Zhao <[email protected]>
Co-authored-by: Gavin Zhao <[email protected]>
  • Loading branch information
ykmnkmi and GZGavinZhao authored Apr 25, 2023
1 parent 2ed10cd commit 629c87c
Show file tree
Hide file tree
Showing 24 changed files with 113 additions and 107 deletions.
4 changes: 1 addition & 3 deletions ngforms/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ include: ../analysis_options.yaml

analyzer:
errors:
# False positives related to missing .template.dart files
invalid_assignment: ignore
argument_type_not_assignable: ignore
implementation_imports: ignore
11 changes: 6 additions & 5 deletions ngforms/lib/ngforms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,21 @@ export 'src/form_builder.dart' show FormBuilder;
export 'src/model.dart'
show
AbstractControl,
ControlStatus,
Control,
AbstractControlGroup,
ControlGroup,
ControlArray;
export 'src/validators.dart' show NG_VALIDATORS, Validators;
export 'src/validators.dart' show ngValidators, Validators;

/// Shorthand set of providers used for building Angular forms.
///
/// ### Example
///
/// ```dart
/// runApp(createMyAppFactory(), [FORM_PROVIDERS]);
/// runApp(MyAppNgFactory, [formProviders]);
/// ````
const List<Type> FORM_PROVIDERS = [RadioControlRegistry];
const List<Type> formProviders = [RadioControlRegistry];

/// See [FORM_PROVIDERS] instead.
const FORM_BINDINGS = FORM_PROVIDERS;
/// See [formProviders] instead.
const List<Type> formBindings = formProviders;
4 changes: 2 additions & 2 deletions ngforms/lib/src/directives/checkbox_value_accessor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:ngdart/angular.dart';
import 'control_value_accessor.dart'
show ChangeHandler, ControlValueAccessor, ngValueAccessor, TouchHandler;

const CHECKBOX_VALUE_ACCESSOR = ExistingProvider.forToken(
const checkboxValueAccessor = ExistingProvider.forToken(
ngValueAccessor,
CheckboxControlValueAccessor,
);
Expand All @@ -21,7 +21,7 @@ const CHECKBOX_VALUE_ACCESSOR = ExistingProvider.forToken(
selector: 'input[type=checkbox][ngControl],'
'input[type=checkbox][ngFormControl],'
'input[type=checkbox][ngModel]',
providers: [CHECKBOX_VALUE_ACCESSOR],
providers: [checkboxValueAccessor],
)
class CheckboxControlValueAccessor extends Object
with TouchHandler, ChangeHandler<bool>
Expand Down
4 changes: 2 additions & 2 deletions ngforms/lib/src/directives/default_value_accessor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:ngforms/src/directives/shared.dart' show setElementDisabled;

import 'control_value_accessor.dart';

const DEFAULT_VALUE_ACCESSOR = ExistingProvider.forToken(
const defaultValueAccessor = ExistingProvider.forToken(
ngValueAccessor,
DefaultValueAccessor,
);
Expand All @@ -23,7 +23,7 @@ const DEFAULT_VALUE_ACCESSOR = ExistingProvider.forToken(
'textarea[ngFormControl],'
'input:not([type=checkbox])[ngModel],'
'textarea[ngModel],[ngDefaultControl]',
providers: [DEFAULT_VALUE_ACCESSOR],
providers: [defaultValueAccessor],
)
class DefaultValueAccessor extends Object
with TouchHandler, ChangeHandler<String>
Expand Down
4 changes: 2 additions & 2 deletions ngforms/lib/src/directives/memorized_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:async';
import 'package:ngdart/angular.dart';

import '../model.dart' show AbstractControlGroup, Control, ControlGroup;
import '../validators.dart' show NG_VALIDATORS;
import '../validators.dart' show ngValidators;
import 'control_container.dart' show ControlContainer;
import 'ng_control.dart' show NgControl;
import 'ng_control_group.dart' show NgControlGroup;
Expand All @@ -22,7 +22,7 @@ import 'shared.dart' show setUpControl, setUpControlGroup;
)
class MemorizedForm extends NgForm {
MemorizedForm(
@Optional() @Self() @Inject(NG_VALIDATORS) List<dynamic>? validators,
@Optional() @Self() @Inject(ngValidators) List<dynamic>? validators,
ChangeDetectorRef changeDetectorRef,
) : super(validators, changeDetectorRef);

Expand Down
8 changes: 4 additions & 4 deletions ngforms/lib/src/directives/ng_control_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:async';
import 'package:ngdart/angular.dart';

import '../model.dart' show AbstractControlGroup;
import '../validators.dart' show NG_VALIDATORS;
import '../validators.dart' show ngValidators;
import 'control_container.dart' show ControlContainer;
import 'form_interface.dart' show Form;
import 'shared.dart' show controlPath, composeValidators;
Expand All @@ -21,7 +21,7 @@ import 'validators.dart' show ValidatorFn;
/// directives: const [formDirectives],
/// template: '''
/// <div>
/// <h2>Angular2 Control &amp; AbstractControlGroup Example</h2>
/// <h2>Angular Control &amp; AbstractControlGroup Example</h2>
/// <form #f="ngForm">
/// <div ngControlGroup="name" #cg-name="form">
/// <h3>Enter your name:</h3>
Expand All @@ -45,7 +45,7 @@ import 'validators.dart' show ValidatorFn;
/// if (cg.control == null) {
/// return null;
/// }
/// return JSON.encode(cg.control.value, null, 2);
/// return json.encode(cg.control.value, null, 2);
/// }
/// }
/// ```
Expand All @@ -70,7 +70,7 @@ class NgControlGroup extends ControlContainer<AbstractControlGroup>

NgControlGroup(
@SkipSelf() this._parent,
@Optional() @Self() @Inject(NG_VALIDATORS) List<dynamic>? validators,
@Optional() @Self() @Inject(ngValidators) List<dynamic>? validators,
) : validator = composeValidators(validators);

@Input('ngControlGroup')
Expand Down
4 changes: 2 additions & 2 deletions ngforms/lib/src/directives/ng_control_name.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:async';
import 'package:ngdart/angular.dart';

import '../model.dart' show Control;
import '../validators.dart' show NG_VALIDATORS;
import '../validators.dart' show ngValidators;
import 'control_container.dart' show ControlContainer;
import 'control_value_accessor.dart' show ControlValueAccessor, ngValueAccessor;
import 'form_interface.dart' show Form;
Expand Down Expand Up @@ -91,7 +91,7 @@ class NgControlName extends NgControl implements AfterChanges, OnDestroy {

NgControlName(
@SkipSelf() this._parent,
@Optional() @Self() @Inject(NG_VALIDATORS) List<dynamic>? validators,
@Optional() @Self() @Inject(ngValidators) List<dynamic>? validators,
@Optional()
@Self()
@Inject(ngValueAccessor)
Expand Down
6 changes: 3 additions & 3 deletions ngforms/lib/src/directives/ng_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:ngdart/angular.dart';

import '../model.dart'
show AbstractControl, AbstractControlGroup, ControlGroup, Control;
import '../validators.dart' show NG_VALIDATORS;
import '../validators.dart' show ngValidators;
import 'abstract_form.dart' show AbstractForm;
import 'control_container.dart' show ControlContainer;
import 'ng_control.dart' show NgControl;
Expand Down Expand Up @@ -78,14 +78,14 @@ import 'shared.dart' show setUpControl, setUpControlGroup, composeValidators;
)
class NgForm extends AbstractNgForm<ControlGroup> {
NgForm(
@Optional() @Self() @Inject(NG_VALIDATORS) List<dynamic>? validators,
@Optional() @Self() @Inject(ngValidators) List<dynamic>? validators,
ChangeDetectorRef changeDetectorRef,
) : super(changeDetectorRef) {
form = ControlGroup({}, composeValidators(validators));
}

@override
ControlGroup createGroup(NgControlGroup _) => ControlGroup({});
ControlGroup createGroup(NgControlGroup dir) => ControlGroup({});
}

/// Abstract class to easily create forms that are template driven.
Expand Down
6 changes: 3 additions & 3 deletions ngforms/lib/src/directives/ng_form_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:async';
import 'package:ngdart/angular.dart';

import '../model.dart' show Control;
import '../validators.dart' show NG_VALIDATORS;
import '../validators.dart' show ngValidators;
import 'control_value_accessor.dart' show ControlValueAccessor, ngValueAccessor;
import 'ng_control.dart' show NgControl;
import 'shared.dart' show setUpControl;
Expand Down Expand Up @@ -86,8 +86,8 @@ class NgFormControl extends NgControl implements AfterChanges {
NgFormControl(
@Optional()
@Self()
@Inject(NG_VALIDATORS)
List<dynamic>? validators,
@Inject(ngValidators)
List<Object>? validators,
@Optional()
@Self()
@Inject(ngValueAccessor)
Expand Down
4 changes: 2 additions & 2 deletions ngforms/lib/src/directives/ng_form_model.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:ngdart/angular.dart';

import '../model.dart' show AbstractControlGroup;
import '../validators.dart' show Validators, NG_VALIDATORS;
import '../validators.dart' show Validators, ngValidators;
import 'abstract_form.dart' show AbstractForm;
import 'control_container.dart' show ControlContainer;
import 'ng_control.dart' show NgControl;
Expand Down Expand Up @@ -106,7 +106,7 @@ class NgFormModel extends AbstractForm<AbstractControlGroup>
List<NgControl> directives = [];

NgFormModel(
@Optional() @Self() @Inject(NG_VALIDATORS) List<dynamic>? validators,
@Optional() @Self() @Inject(ngValidators) List<dynamic>? validators,
) : _validator = composeValidators(validators);

@override
Expand Down
6 changes: 3 additions & 3 deletions ngforms/lib/src/directives/ng_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:meta/dart2js.dart' as dart2js;
import 'package:ngdart/angular.dart';

import '../model.dart' show Control;
import '../validators.dart' show NG_VALIDATORS;
import '../validators.dart' show ngValidators;
import 'control_value_accessor.dart' show ControlValueAccessor, ngValueAccessor;
import 'ng_control.dart' show NgControl;
import 'shared.dart' show setUpControl;
Expand Down Expand Up @@ -79,8 +79,8 @@ class NgModel extends NgControl implements AfterChanges, OnInit {
NgModel(
@Optional()
@Self()
@Inject(NG_VALIDATORS)
List<dynamic>? validators,
@Inject(ngValidators)
List<Object>? validators,
@Optional()
@Self()
@Inject(ngValueAccessor)
Expand Down
4 changes: 2 additions & 2 deletions ngforms/lib/src/directives/number_value_accessor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:ngdart/angular.dart';
import 'control_value_accessor.dart'
show ChangeHandler, ControlValueAccessor, ngValueAccessor, TouchHandler;

const NUMBER_VALUE_ACCESSOR = ExistingProvider.forToken(
const numberValueAccessor = ExistingProvider.forToken(
ngValueAccessor,
NumberValueAccessor,
);
Expand All @@ -20,7 +20,7 @@ const NUMBER_VALUE_ACCESSOR = ExistingProvider.forToken(
selector: 'input[type=number][ngControl],'
'input[type=number][ngFormControl],'
'input[type=number][ngModel]',
providers: [NUMBER_VALUE_ACCESSOR],
providers: [numberValueAccessor],
)
class NumberValueAccessor extends Object
with TouchHandler, ChangeHandler<double?>
Expand Down
4 changes: 2 additions & 2 deletions ngforms/lib/src/directives/radio_control_value_accessor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'control_value_accessor.dart'
show ChangeHandler, ControlValueAccessor, ngValueAccessor, TouchHandler;
import 'ng_control.dart' show NgControl;

const RADIO_VALUE_ACCESSOR = ExistingProvider.forToken(
const radioValueAccessor = ExistingProvider.forToken(
ngValueAccessor,
RadioControlValueAccessor,
);
Expand Down Expand Up @@ -71,7 +71,7 @@ class RadioButtonState {
selector: 'input[type=radio][ngControl],'
'input[type=radio][ngFormControl],'
'input[type=radio][ngModel]',
providers: [RADIO_VALUE_ACCESSOR],
providers: [radioValueAccessor],
)
class RadioControlValueAccessor extends Object
with TouchHandler, ChangeHandler<RadioButtonState>
Expand Down
4 changes: 2 additions & 2 deletions ngforms/lib/src/directives/select_control_value_accessor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:ngdart/src/utilities.dart';
import 'control_value_accessor.dart'
show ChangeHandler, ControlValueAccessor, ngValueAccessor, TouchHandler;

const SELECT_VALUE_ACCESSOR = ExistingProvider.forToken(
const selectValueAccessor = ExistingProvider.forToken(
ngValueAccessor,
SelectControlValueAccessor,
);
Expand All @@ -33,7 +33,7 @@ String _extractId(String valueString) => valueString.split(':')[0];
/// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/4660045
@Directive(
selector: 'select[ngControl],select[ngFormControl],select[ngModel]',
providers: [SELECT_VALUE_ACCESSOR],
providers: [selectValueAccessor],
// SelectControlValueAccessor must be visible to NgSelectOption.
visibility: Visibility.all,
)
Expand Down
12 changes: 6 additions & 6 deletions ngforms/lib/src/directives/validators.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:ngdart/angular.dart';

import '../model.dart' show AbstractControl;
import '../validators.dart' show Validators, NG_VALIDATORS;
import '../validators.dart' show Validators, ngValidators;

/// An interface to be implemented as classes acting as validators.
///
Expand All @@ -12,7 +12,7 @@ import '../validators.dart' show Validators, NG_VALIDATORS;
/// selector: '[custom-validator]',
/// providers: const [
/// const ExistingProvider.forToken(
/// NG_VALIDATORS,
/// ngValidators,
/// CustomValidatorDirective,
/// ),
/// ]
Expand Down Expand Up @@ -64,7 +64,7 @@ typedef ValidatorFn = Map<String, dynamic>? Function(AbstractControl c);
'[required][ngFormControl],'
'[required][ngModel]',
providers: [
ExistingProvider.forToken(NG_VALIDATORS, RequiredValidator),
ExistingProvider.forToken(ngValidators, RequiredValidator),
],
)
class RequiredValidator implements Validator {
Expand All @@ -87,7 +87,7 @@ class RequiredValidator implements Validator {
'[minlength][ngFormControl],'
'[minlength][ngModel]',
providers: [
ExistingProvider.forToken(NG_VALIDATORS, MinLengthValidator),
ExistingProvider.forToken(ngValidators, MinLengthValidator),
],
)
class MinLengthValidator implements Validator {
Expand Down Expand Up @@ -126,7 +126,7 @@ class MinLengthValidator implements Validator {
'[maxlength][ngFormControl],'
'[maxlength][ngModel]',
providers: [
ExistingProvider.forToken(NG_VALIDATORS, MaxLengthValidator),
ExistingProvider.forToken(ngValidators, MaxLengthValidator),
],
)
class MaxLengthValidator implements Validator {
Expand Down Expand Up @@ -168,7 +168,7 @@ class MaxLengthValidator implements Validator {
'[pattern][ngFormControl],'
'[pattern][ngModel]',
providers: [
ExistingProvider.forToken(NG_VALIDATORS, PatternValidator),
ExistingProvider.forToken(ngValidators, PatternValidator),
],
)
class PatternValidator implements Validator {
Expand Down
Loading

0 comments on commit 629c87c

Please sign in to comment.