refactor: remove some facades (#12335)
This commit is contained in:

committed by
Alex Rickabaugh

parent
0ecd9b2df0
commit
76dd026447
@ -9,7 +9,7 @@
|
||||
import {Directive, ElementRef, Host, Input, OnDestroy, OpaqueToken, Optional, Renderer, Type, forwardRef} from '@angular/core';
|
||||
|
||||
import {MapWrapper} from '../facade/collection';
|
||||
import {isBlank, isPresent, isPrimitive, isString, looseIdentical} from '../facade/lang';
|
||||
import {isBlank, isPresent, isPrimitive, looseIdentical} from '../facade/lang';
|
||||
|
||||
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor';
|
||||
|
||||
@ -21,7 +21,7 @@ export const SELECT_MULTIPLE_VALUE_ACCESSOR = {
|
||||
|
||||
function _buildValueString(id: string, value: any): string {
|
||||
if (isBlank(id)) return `${value}`;
|
||||
if (isString(value)) value = `'${value}'`;
|
||||
if (typeof value === 'string') value = `'${value}'`;
|
||||
if (!isPrimitive(value)) value = 'Object';
|
||||
return `${id}: ${value}`.slice(0, 50);
|
||||
}
|
||||
|
@ -6,9 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
|
||||
import {ListWrapper} from '../facade/collection';
|
||||
import {hasConstructor, isBlank, isPresent, looseIdentical} from '../facade/lang';
|
||||
import {isBlank, isPresent, looseIdentical} from '../facade/lang';
|
||||
import {FormArray, FormControl, FormGroup} from '../model';
|
||||
import {Validators} from '../validators';
|
||||
|
||||
@ -30,9 +28,7 @@ import {AsyncValidatorFn, Validator, ValidatorFn} from './validators';
|
||||
|
||||
|
||||
export function controlPath(name: string, parent: ControlContainer): string[] {
|
||||
var p = ListWrapper.clone(parent.path);
|
||||
p.push(name);
|
||||
return p;
|
||||
return [...parent.path, name];
|
||||
}
|
||||
|
||||
export function setUpControl(control: FormControl, dir: NgControl): void {
|
||||
@ -128,14 +124,17 @@ export function isPropertyUpdated(changes: {[key: string]: any}, viewModel: any)
|
||||
return !looseIdentical(viewModel, change.currentValue);
|
||||
}
|
||||
|
||||
const BUILTIN_ACCESSORS = [
|
||||
CheckboxControlValueAccessor,
|
||||
RangeValueAccessor,
|
||||
NumberValueAccessor,
|
||||
SelectControlValueAccessor,
|
||||
SelectMultipleControlValueAccessor,
|
||||
RadioControlValueAccessor,
|
||||
];
|
||||
|
||||
export function isBuiltInAccessor(valueAccessor: ControlValueAccessor): boolean {
|
||||
return (
|
||||
hasConstructor(valueAccessor, CheckboxControlValueAccessor) ||
|
||||
hasConstructor(valueAccessor, RangeValueAccessor) ||
|
||||
hasConstructor(valueAccessor, NumberValueAccessor) ||
|
||||
hasConstructor(valueAccessor, SelectControlValueAccessor) ||
|
||||
hasConstructor(valueAccessor, SelectMultipleControlValueAccessor) ||
|
||||
hasConstructor(valueAccessor, RadioControlValueAccessor));
|
||||
return BUILTIN_ACCESSORS.some(a => valueAccessor.constructor === a);
|
||||
}
|
||||
|
||||
// TODO: vsavkin remove it once https://github.com/angular/angular/issues/3011 is implemented
|
||||
@ -147,24 +146,24 @@ export function selectValueAccessor(
|
||||
var builtinAccessor: ControlValueAccessor;
|
||||
var customAccessor: ControlValueAccessor;
|
||||
valueAccessors.forEach((v: ControlValueAccessor) => {
|
||||
if (hasConstructor(v, DefaultValueAccessor)) {
|
||||
if (v.constructor === DefaultValueAccessor) {
|
||||
defaultAccessor = v;
|
||||
|
||||
} else if (isBuiltInAccessor(v)) {
|
||||
if (isPresent(builtinAccessor))
|
||||
if (builtinAccessor)
|
||||
_throwError(dir, 'More than one built-in value accessor matches form control with');
|
||||
builtinAccessor = v;
|
||||
|
||||
} else {
|
||||
if (isPresent(customAccessor))
|
||||
if (customAccessor)
|
||||
_throwError(dir, 'More than one custom value accessor matches form control with');
|
||||
customAccessor = v;
|
||||
}
|
||||
});
|
||||
|
||||
if (isPresent(customAccessor)) return customAccessor;
|
||||
if (isPresent(builtinAccessor)) return builtinAccessor;
|
||||
if (isPresent(defaultAccessor)) return defaultAccessor;
|
||||
if (customAccessor) return customAccessor;
|
||||
if (builtinAccessor) return builtinAccessor;
|
||||
if (defaultAccessor) return defaultAccessor;
|
||||
|
||||
_throwError(dir, 'No valid value accessor for form control with');
|
||||
return null;
|
||||
|
@ -9,7 +9,7 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
|
||||
import {AsyncValidatorFn, ValidatorFn} from './directives/validators';
|
||||
import {isArray, isPresent} from './facade/lang';
|
||||
import {isPresent} from './facade/lang';
|
||||
import {AbstractControl, FormArray, FormControl, FormGroup} from './model';
|
||||
|
||||
/**
|
||||
@ -86,10 +86,10 @@ export class FormBuilder {
|
||||
controlConfig instanceof FormArray) {
|
||||
return controlConfig;
|
||||
|
||||
} else if (isArray(controlConfig)) {
|
||||
var value = controlConfig[0];
|
||||
var validator: ValidatorFn = controlConfig.length > 1 ? controlConfig[1] : null;
|
||||
var asyncValidator: AsyncValidatorFn = controlConfig.length > 2 ? controlConfig[2] : null;
|
||||
} else if (Array.isArray(controlConfig)) {
|
||||
const value = controlConfig[0];
|
||||
const validator: ValidatorFn = controlConfig.length > 1 ? controlConfig[1] : null;
|
||||
const asyncValidator: AsyncValidatorFn = controlConfig.length > 2 ? controlConfig[2] : null;
|
||||
return this.control(value, validator, asyncValidator);
|
||||
|
||||
} else {
|
||||
|
@ -11,8 +11,7 @@ import {fromPromise} from 'rxjs/observable/fromPromise';
|
||||
import {composeAsyncValidators, composeValidators} from './directives/shared';
|
||||
import {AsyncValidatorFn, ValidatorFn} from './directives/validators';
|
||||
import {EventEmitter, Observable} from './facade/async';
|
||||
import {StringMapWrapper} from './facade/collection';
|
||||
import {isBlank, isPresent, isStringMap, normalizeBool} from './facade/lang';
|
||||
import {isBlank, isPresent, normalizeBool} from './facade/lang';
|
||||
import {isPromise} from './private_import_core';
|
||||
|
||||
|
||||
@ -605,8 +604,8 @@ export abstract class AbstractControl {
|
||||
|
||||
/** @internal */
|
||||
_isBoxedValue(formState: any): boolean {
|
||||
return isStringMap(formState) && Object.keys(formState).length === 2 && 'value' in formState &&
|
||||
'disabled' in formState;
|
||||
return typeof formState === 'object' && formState !== null &&
|
||||
Object.keys(formState).length === 2 && 'value' in formState && 'disabled' in formState;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
Reference in New Issue
Block a user