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

Commit

Permalink
Annotate some overrides
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=140383298
  • Loading branch information
kevmoo authored and matanlurey committed Nov 28, 2016
1 parent 7b2953f commit 4a94de1
Show file tree
Hide file tree
Showing 18 changed files with 82 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/src/common/directives/ng_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class NgClass implements DoCheck, OnDestroy {
}
}

@override
void ngDoCheck() {
if (_iterableDiffer != null) {
var changes = _iterableDiffer.diff(_rawClass);
Expand All @@ -96,6 +97,7 @@ class NgClass implements DoCheck, OnDestroy {
}
}

@override
void ngOnDestroy() {
_cleanupClasses(_rawClass);
}
Expand Down
1 change: 1 addition & 0 deletions lib/src/common/directives/ng_for.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class NgFor implements DoCheck {
this._ngForTrackBy = value;
}

@override
void ngDoCheck() {
if (_differ != null) {
var changes = this._differ.diff(this._ngForOf);
Expand Down
1 change: 1 addition & 0 deletions lib/src/common/directives/ng_plural.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class NgPlural implements AfterContentInit {
this._updateView();
}

@override
void ngAfterContentInit() {
this.cases.forEach(/* void */ (NgPluralCase pluralCase) {
this._caseViews[this._formatValue(pluralCase)] = pluralCase._view;
Expand Down
1 change: 1 addition & 0 deletions lib/src/common/directives/ng_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class NgStyle implements DoCheck {
}
}

@override
void ngDoCheck() {
if (_differ == null) return;
var changes = _differ.diff(_rawStyle);
Expand Down
4 changes: 4 additions & 0 deletions lib/src/common/directives/observable_list_diff.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ObservableListDiff extends DefaultIterableDiffer {
ObservableList _collection;
StreamSubscription _subscription;

@override
void onDestroy() {
if (this._subscription != null) {
this._subscription.cancel();
Expand All @@ -21,6 +22,7 @@ class ObservableListDiff extends DefaultIterableDiffer {
}
}

@override
DefaultIterableDiffer diff(Iterable iterable) {
assert(iterable is ObservableList);
ObservableList collection = iterable;
Expand Down Expand Up @@ -56,7 +58,9 @@ class ObservableListDiff extends DefaultIterableDiffer {
@Deprecated('No longer part of Angular. Copy into your project if needed')
class ObservableListDiffFactory implements IterableDifferFactory {
const ObservableListDiffFactory();
@override
bool supports(obj) => obj is ObservableList;
@override
IterableDiffer create(ChangeDetectorRef cdRef, [Function trackByFn]) {
return new ObservableListDiff(cdRef);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/src/common/forms/directives/checkbox_value_accessor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ class CheckboxControlValueAccessor implements ControlValueAccessor {
var onChange = (dynamic _) {};
var onTouched = () {};
CheckboxControlValueAccessor(this._elementRef);
@override
void writeValue(dynamic value) {
InputElement elm = this._elementRef.nativeElement;
elm.checked = value;
}

@override
void registerOnChange(dynamic fn) {
this.onChange = fn;
}

@override
void registerOnTouched(dynamic fn) {
this.onTouched = fn;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/src/common/forms/directives/default_value_accessor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ class DefaultValueAccessor implements ControlValueAccessor {
var onChange = (dynamic _) {};
var onTouched = () {};
DefaultValueAccessor(this._elementRef);
@override
void writeValue(dynamic value) {
var normalizedValue = value ?? '';
DOM.setProperty(_elementRef.nativeElement, 'value', normalizedValue);
}

@override
void registerOnChange(void fn(dynamic _)) {
this.onChange = fn;
}

@override
void registerOnTouched(void fn()) {
this.onTouched = fn;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/src/common/forms/directives/ng_control_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,30 @@ class NgControlGroup extends ControlContainer implements OnInit, OnDestroy {
@Optional() @Self() @Inject(NG_VALIDATORS) this._validators,
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) this._asyncValidators);

@override
void ngOnInit() {
this.formDirective.addControlGroup(this);
}

@override
void ngOnDestroy() {
this.formDirective.removeControlGroup(this);
}

/// Get the [ControlGroup] backing this binding.
@override
ControlGroup get control {
return this.formDirective.getControlGroup(this);
}

/// Get the path to this control group.
@override
List<String> get path {
return controlPath(this.name, this._parent);
}

/// Get the [Form] to which this group belongs.
@override
Form get formDirective {
return this._parent.formDirective;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/src/common/forms/directives/ng_control_name.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class NgControlName extends NgControl implements OnChanges, OnDestroy {
List<ControlValueAccessor> valueAccessors) {
this.valueAccessor = selectValueAccessor(this, valueAccessors);
}
@override
ngOnChanges(Map<String, SimpleChange> changes) {
if (!this._added) {
this.formDirective.addControl(this);
Expand All @@ -124,15 +125,18 @@ class NgControlName extends NgControl implements OnChanges, OnDestroy {
}
}

@override
void ngOnDestroy() {
this.formDirective.removeControl(this);
}

@override
void viewToModelUpdate(dynamic newValue) {
this.viewModel = newValue;
this.update.add(newValue);
}

@override
List<String> get path {
return controlPath(this.name, this._parent);
}
Expand All @@ -141,14 +145,17 @@ class NgControlName extends NgControl implements OnChanges, OnDestroy {
return this._parent.formDirective;
}

@override
ValidatorFn get validator {
return composeValidators(this._validators);
}

@override
AsyncValidatorFn get asyncValidator {
return composeAsyncValidators(this._asyncValidators);
}

@override
Control get control {
return this.formDirective.getControl(this);
}
Expand Down
10 changes: 10 additions & 0 deletions lib/src/common/forms/directives/ng_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,17 @@ class NgForm extends ControlContainer implements Form {
this.form = new ControlGroup({}, null, composeValidators(validators),
composeAsyncValidators(asyncValidators));
}
@override
Form get formDirective {
return this;
}

@override
ControlGroup get control {
return this.form;
}

@override
List<String> get path {
return [];
}
Expand All @@ -113,6 +116,7 @@ class NgForm extends ControlContainer implements Form {
return this.form.controls;
}

@override
void addControl(NgControl dir) {
var container = _findContainer(dir.path);
var ctrl = new Control();
Expand All @@ -123,10 +127,12 @@ class NgForm extends ControlContainer implements Form {
});
}

@override
Control getControl(NgControl dir) {
return (this.form.find(dir.path) as Control);
}

@override
void removeControl(NgControl dir) {
scheduleMicrotask(() {
var container = this._findContainer(dir.path);
Expand All @@ -137,6 +143,7 @@ class NgForm extends ControlContainer implements Form {
});
}

@override
void addControlGroup(NgControlGroup dir) {
var container = _findContainer(dir.path);
var group = new ControlGroup({});
Expand All @@ -147,6 +154,7 @@ class NgForm extends ControlContainer implements Form {
});
}

@override
void removeControlGroup(NgControlGroup dir) {
scheduleMicrotask(() {
var container = this._findContainer(dir.path);
Expand All @@ -157,10 +165,12 @@ class NgForm extends ControlContainer implements Form {
});
}

@override
ControlGroup getControlGroup(NgControlGroup dir) {
return (this.form.find(dir.path) as ControlGroup);
}

@override
void updateModel(NgControl dir, dynamic value) {
scheduleMicrotask(() {
var ctrl = (this.form.find(dir.path) as Control);
Expand Down
6 changes: 6 additions & 0 deletions lib/src/common/forms/directives/ng_form_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class NgFormControl extends NgControl implements OnChanges {
List<ControlValueAccessor> valueAccessors) {
this.valueAccessor = selectValueAccessor(this, valueAccessors);
}
@override
void ngOnChanges(Map<String, SimpleChange> changes) {
if (this._isControlChanged(changes)) {
setUpControl(this.form, this);
Expand All @@ -104,22 +105,27 @@ class NgFormControl extends NgControl implements OnChanges {
}
}

@override
List<String> get path {
return [];
}

@override
ValidatorFn get validator {
return composeValidators(this._validators);
}

@override
AsyncValidatorFn get asyncValidator {
return composeAsyncValidators(this._asyncValidators);
}

@override
Control get control {
return this.form;
}

@override
void viewToModelUpdate(dynamic newValue) {
this.viewModel = newValue;
this.update.add(newValue);
Expand Down
12 changes: 12 additions & 0 deletions lib/src/common/forms/directives/ng_form_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class NgFormModel extends ControlContainer implements Form, OnChanges {
NgFormModel(@Optional() @Self() @Inject(NG_VALIDATORS) this._validators,
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) this._asyncValidators);

@override
void ngOnChanges(Map<String, SimpleChange> changes) {
_checkFormPresent();
if (changes.containsKey('form')) {
Expand All @@ -120,38 +121,49 @@ class NgFormModel extends ControlContainer implements Form, OnChanges {
_updateDomValue();
}

@override
Form get formDirective => this;

@override
ControlGroup get control => form;

@override
List<String> get path => [];

@override
void addControl(NgControl dir) {
dynamic ctrl = form.find(dir.path);
setUpControl(ctrl, dir);
ctrl.updateValueAndValidity(emitEvent: false);
directives.add(dir);
}

@override
Control getControl(NgControl dir) {
return (form.find(dir.path) as Control);
}

@override
void removeControl(NgControl dir) {
directives.remove(dir);
}

@override
void addControlGroup(NgControlGroup dir) {
dynamic ctrl = form.find(dir.path);
setUpControlGroup(ctrl, dir);
ctrl.updateValueAndValidity(emitEvent: false);
}

@override
void removeControlGroup(NgControlGroup dir) {}

@override
ControlGroup getControlGroup(NgControlGroup dir) {
return (form.find(dir.path) as ControlGroup);
}

@override
void updateModel(NgControl dir, dynamic value) {
var ctrl = (form.find(dir.path) as Control);
ctrl.updateValue(value);
Expand Down
6 changes: 6 additions & 0 deletions lib/src/common/forms/directives/ng_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class NgModel extends NgControl implements OnChanges {
: super() {
this.valueAccessor = selectValueAccessor(this, valueAccessors);
}
@override
void ngOnChanges(Map<String, SimpleChange> changes) {
if (!this._added) {
setUpControl(this._control, this);
Expand All @@ -83,22 +84,27 @@ class NgModel extends NgControl implements OnChanges {
}
}

@override
Control get control {
return this._control;
}

@override
List<String> get path {
return [];
}

@override
ValidatorFn get validator {
return composeValidators(this._validators);
}

@override
AsyncValidatorFn get asyncValidator {
return composeAsyncValidators(this._asyncValidators);
}

@override
void viewToModelUpdate(dynamic newValue) {
this.viewModel = newValue;
this.update.add(newValue);
Expand Down
3 changes: 3 additions & 0 deletions lib/src/common/forms/directives/number_value_accessor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@ class NumberValueAccessor implements ControlValueAccessor {
var onChange = (_) {};
var onTouched = () {};
NumberValueAccessor(this._elementRef);
@override
void writeValue(value) {
InputElement elm = _elementRef.nativeElement;
elm.value = '$value';
}

@override
void registerOnChange(dynamic fn) {
this.onChange = (value) {
fn(value == "" ? null : double.parse(value));
};
}

@override
void registerOnTouched(dynamic fn) {
this.onTouched = fn;
}
Expand Down
Loading

0 comments on commit 4a94de1

Please sign in to comment.