Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit f572ba0

Browse files
matskomhevery
authored andcommitted
refactor(forms): add return types and noop values for boolean getters
1 parent 4458ce8 commit f572ba0

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

lib/directive/ng_control.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ abstract class NgControl implements NgAttachAware, NgDetachAware {
8080

8181
get element => _element;
8282

83-
get pristine => !_dirty;
83+
bool get pristine => !_dirty;
8484
set pristine(value) {
8585
//only mark as pristine if all the child controls are pristine
8686
if (_controls.any((control) => control.dirty)) return;
@@ -91,7 +91,7 @@ abstract class NgControl implements NgAttachAware, NgDetachAware {
9191
_parentControl.pristine = true;
9292
}
9393

94-
get dirty => _dirty;
94+
bool get dirty => _dirty;
9595
set dirty(value) {
9696
_dirty = true;
9797
_animate.addClass(element, NG_DIRTY_CLASS);
@@ -102,21 +102,21 @@ abstract class NgControl implements NgAttachAware, NgDetachAware {
102102
_parentControl.dirty = true;
103103
}
104104

105-
get valid => _valid;
105+
bool get valid => _valid;
106106
set valid(value) {
107107
_valid = true;
108108
_animate.addClass(element, NG_VALID_CLASS);
109109
_animate.removeClass(element, NG_INVALID_CLASS);
110110
}
111111

112-
get invalid => !_valid;
112+
bool get invalid => !_valid;
113113
set invalid(value) {
114114
_valid = false;
115115
_animate.addClass(element, NG_INVALID_CLASS);
116116
_animate.removeClass(element, NG_VALID_CLASS);
117117
}
118118

119-
get touched => _touched;
119+
bool get touched => _touched;
120120
set touched(value) {
121121
_touched = true;
122122
_animate.addClass(element, NG_TOUCHED_CLASS);
@@ -126,7 +126,7 @@ abstract class NgControl implements NgAttachAware, NgDetachAware {
126126
_parentControl.touched = true;
127127
}
128128

129-
get untouched => !_touched;
129+
bool get untouched => !_touched;
130130
set untouched(value) {
131131
_touched = false;
132132
_animate.addClass(element, NG_UNTOUCHED_CLASS);
@@ -212,26 +212,26 @@ class NgNullControl implements NgControl {
212212
get name => null;
213213
set name(name) {}
214214

215-
get submitted => null;
216-
get valid_submit => null;
217-
get invalid_submit => null;
215+
bool get submitted => false;
216+
bool get valid_submit => true;
217+
bool get invalid_submit => false;
218218

219-
get pristine => null;
219+
bool get pristine => true;
220220
set pristine(value) {}
221221

222-
get dirty => null;
222+
bool get dirty => false;
223223
set dirty(value) {}
224224

225-
get valid => null;
225+
bool get valid => true;
226226
set valid(value) {}
227227

228-
get invalid => null;
228+
bool get invalid => false;
229229
set invalid(value) {}
230230

231-
get touched => null;
231+
bool get touched => false;
232232
set touched(value) {}
233233

234-
get untouched => null;
234+
bool get untouched => true;
235235
set untouched(value) {}
236236

237237
reset() => null;

lib/directive/ng_model.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ class NgModel extends NgControl implements NgAttachAware {
3535
watchCollection = false;
3636
}
3737

38-
process(value, [_]) {
38+
void process(value, [_]) {
3939
validate();
4040
_scope.rootScope.domWrite(() => render(value));
4141
}
4242

43-
attach() {
43+
void attach() {
4444
watchCollection = false;
4545
}
4646

47-
reset() {
47+
void reset() {
4848
untouched = true;
4949
modelValue = _lastValue;
5050
}
5151

52-
onSubmit(bool valid) {
52+
void onSubmit(bool valid) {
5353
super.onSubmit(valid);
5454
if (valid) {
5555
_lastValue = modelValue;
@@ -108,7 +108,7 @@ class NgModel extends NgControl implements NgAttachAware {
108108
/**
109109
* Executes a validation on the form against each of the validation present on the model.
110110
*/
111-
validate() {
111+
void validate() {
112112
if (validators.isNotEmpty) {
113113
validators.forEach((validator) {
114114
setValidity(validator.name, validator.isValid(viewValue));
@@ -118,22 +118,22 @@ class NgModel extends NgControl implements NgAttachAware {
118118
}
119119
}
120120

121-
setValidity(String name, bool valid) {
121+
void setValidity(String name, bool valid) {
122122
this.updateControlValidity(this, name, valid);
123123
}
124124

125125
/**
126126
* Registers a validator into the model to consider when running validate().
127127
*/
128-
addValidator(NgValidatable v) {
128+
void addValidator(NgValidatable v) {
129129
validators.add(v);
130130
validate();
131131
}
132132

133133
/**
134134
* De-registers a validator from the model.
135135
*/
136-
removeValidator(NgValidatable v) {
136+
void removeValidator(NgValidatable v) {
137137
validators.remove(v);
138138
validate();
139139
}

0 commit comments

Comments
 (0)