@@ -44,12 +44,13 @@ abstract class NgControl implements NgAttachAware, NgDetachAware {
44
44
: _parentControl = injector.parent.get (NgControl );
45
45
46
46
@override
47
- attach () => _parentControl.addControl (this );
47
+ void attach () {
48
+ _parentControl.addControl (this );
49
+ }
48
50
49
51
@override
50
- detach () {
51
- _parentControl.removeStates (this );
52
- _parentControl.removeControl (this );
52
+ void detach () {
53
+ _parentControl..removeStates (this )..removeControl (this );
53
54
}
54
55
55
56
/**
@@ -92,7 +93,7 @@ abstract class NgControl implements NgAttachAware, NgDetachAware {
92
93
bool get invalidSubmit => _submitValid == false ;
93
94
94
95
String get name => _name;
95
- set name (value) {
96
+ void set name (value) {
96
97
_name = value;
97
98
}
98
99
@@ -139,7 +140,7 @@ abstract class NgControl implements NgAttachAware, NgDetachAware {
139
140
void addControl (NgControl control) {
140
141
_controls.add (control);
141
142
if (control.name != null ) {
142
- _controlByName.putIfAbsent (control.name, () => new List <NgControl >() ).add (control);
143
+ _controlByName.putIfAbsent (control.name, () => < NgControl > [] ).add (control);
143
144
}
144
145
}
145
146
@@ -154,9 +155,7 @@ abstract class NgControl implements NgAttachAware, NgDetachAware {
154
155
String key = control.name;
155
156
if (key != null && _controlByName.containsKey (key)) {
156
157
_controlByName[key].remove (control);
157
- if (_controlByName[key].isEmpty) {
158
- _controlByName.remove (key);
159
- }
158
+ if (_controlByName[key].isEmpty) _controlByName.remove (key);
160
159
}
161
160
}
162
161
@@ -185,9 +184,7 @@ abstract class NgControl implements NgAttachAware, NgDetachAware {
185
184
}
186
185
});
187
186
188
- if (hasRemovals) {
189
- _parentControl.removeStates (this );
190
- }
187
+ if (hasRemovals) _parentControl.removeStates (this );
191
188
}
192
189
193
190
/**
@@ -213,19 +210,16 @@ abstract class NgControl implements NgAttachAware, NgDetachAware {
213
210
/**
214
211
* Removes the given childControl/errorName from the list of errors present on the control. Once
215
212
* removed the control will update any parent controls depending if error is not present on
216
- * any other inner controls and or models.
213
+ * any other inner controls and or models.
217
214
*
218
215
* * [childControl] - The child control that contains the error.
219
216
* * [errorName] - The name of the given error (e.g. ng-required, ng-pattern, etc...).
220
217
*/
221
218
void removeErrorState (NgControl childControl, String errorName) {
222
219
if (! errorStates.containsKey (errorName)) return ;
223
220
224
- bool hasError = _controls.isEmpty ||
225
- _controls.every ((childControl) {
226
- return ! childControl.hasErrorState (errorName);
227
- });
228
- if (hasError) {
221
+ bool hasError = _controls.any ((child) => child.hasErrorState (errorName));
222
+ if (! hasError) {
229
223
errorStates.remove (errorName);
230
224
_parentControl.removeErrorState (this , errorName);
231
225
element..removeClass (errorName + '-invalid' )..addClass (errorName + '-valid' );
@@ -253,9 +247,7 @@ abstract class NgControl implements NgAttachAware, NgDetachAware {
253
247
*/
254
248
void addInfoState (NgControl childControl, String stateName) {
255
249
String oppositeState = _getOppositeInfoState (stateName);
256
- if (oppositeState != null ) {
257
- element.removeClass (oppositeState);
258
- }
250
+ if (oppositeState != null ) element.removeClass (oppositeState);
259
251
element.addClass (stateName);
260
252
infoStates.putIfAbsent (stateName, () => new Set ()).add (childControl);
261
253
_parentControl.addInfoState (this , stateName);
@@ -273,14 +265,10 @@ abstract class NgControl implements NgAttachAware, NgDetachAware {
273
265
void removeInfoState (NgControl childControl, String stateName) {
274
266
String oppositeState = _getOppositeInfoState (stateName);
275
267
if (infoStates.containsKey (stateName)) {
276
- bool hasState = _controls.isEmpty ||
277
- _controls.every ((childControl) {
278
- return ! childControl.infoStates.containsKey (stateName);
279
- });
280
- if (hasState) {
281
- if (oppositeState != null ) {
282
- element.addClass (oppositeState);
283
- }
268
+ bool hasState = _controls.any ((child) =>
269
+ child.infoStates.containsKey (stateName));
270
+ if (! hasState) {
271
+ if (oppositeState != null ) element.addClass (oppositeState);
284
272
element.removeClass (stateName);
285
273
infoStates.remove (stateName);
286
274
_parentControl.removeInfoState (this , stateName);
@@ -291,7 +279,7 @@ abstract class NgControl implements NgAttachAware, NgDetachAware {
291
279
parent.element..addClass (oppositeState)..removeClass (stateName);
292
280
parent = parent.parentControl;
293
281
}
294
- while (parent != null && ! ( parent is NgNullControl ) );
282
+ while (parent != null && parent is ! NgNullControl );
295
283
}
296
284
}
297
285
}
@@ -302,15 +290,14 @@ class NgNullControl implements NgControl {
302
290
var errors, _controlByName;
303
291
NgElement element;
304
292
305
- NgNullControl () {}
306
- onSubmit (bool valid) {}
293
+ void onSubmit (bool valid) {}
307
294
308
- addControl (control) {}
309
- removeControl (control) {}
310
- updateControlValidity (NgControl control , String errorType, bool isValid) {}
295
+ void addControl (control) {}
296
+ void removeControl (control) {}
297
+ void updateControlValidity (NgControl ctrl , String errorType, bool isValid) {}
311
298
312
- get name => null ;
313
- set name (name) {}
299
+ String get name => null ;
300
+ void set name (name) {}
314
301
315
302
bool get submitted => false ;
316
303
bool get validSubmit => true ;
@@ -324,16 +311,17 @@ class NgNullControl implements NgControl {
324
311
325
312
get parentControl => null ;
326
313
327
- _getOppositeInfoState (String state) {}
328
- addErrorState (NgControl control, String state) {}
329
- removeErrorState (NgControl control, String state) {}
330
- addInfoState (NgControl control, String state) {}
331
- removeInfoState (NgControl control, String state) {}
314
+ String _getOppositeInfoState (String state) => null ;
315
+ void addErrorState (NgControl control, String state) {}
316
+ void removeErrorState (NgControl control, String state) {}
317
+ void addInfoState (NgControl control, String state) {}
318
+ void removeInfoState (NgControl control, String state) {}
332
319
333
- reset () => null ;
334
- attach () => null ;
335
- detach () => null ;
320
+ void reset () {}
321
+ void attach () {}
322
+ void detach () {}
336
323
337
324
bool hasErrorState (String key) => false ;
338
- removeStates (NgControl control) {}
325
+
326
+ void removeStates (NgControl control) {}
339
327
}
0 commit comments