refactor: remove lang.ts (#14837)

This commit is contained in:
Miško Hevery
2017-03-02 09:37:01 -08:00
committed by Chuck Jazdzewski
parent 84a65cf788
commit 8343fb7740
139 changed files with 406 additions and 676 deletions

View File

@ -6,10 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Directive, ElementRef, Host, Input, OnDestroy, Optional, Provider, Renderer, forwardRef} from '@angular/core';
import {isPrimitive, looseIdentical} from '../facade/lang';
import {Directive, ElementRef, Host, Input, OnDestroy, Optional, Provider, Renderer, forwardRef, ɵlooseIdentical as looseIdentical} from '@angular/core';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor';
export const SELECT_VALUE_ACCESSOR: Provider = {
@ -20,7 +17,7 @@ export const SELECT_VALUE_ACCESSOR: Provider = {
function _buildValueString(id: string, value: any): string {
if (id == null) return `${value}`;
if (!isPrimitive(value)) value = 'Object';
if (value && typeof value === 'object') value = 'Object';
return `${id}: ${value}`.slice(0, 50);
}

View File

@ -6,10 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Directive, ElementRef, Host, Input, OnDestroy, Optional, Provider, Renderer, forwardRef} from '@angular/core';
import {isPrimitive, looseIdentical} from '../facade/lang';
import {Directive, ElementRef, Host, Input, OnDestroy, Optional, Provider, Renderer, forwardRef, ɵlooseIdentical as looseIdentical} from '@angular/core';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor';
export const SELECT_MULTIPLE_VALUE_ACCESSOR: Provider = {
@ -21,7 +18,7 @@ export const SELECT_MULTIPLE_VALUE_ACCESSOR: Provider = {
function _buildValueString(id: string, value: any): string {
if (id == null) return `${value}`;
if (typeof value === 'string') value = `'${value}'`;
if (!isPrimitive(value)) value = 'Object';
if (value && typeof value === 'object') value = 'Object';
return `${id}: ${value}`.slice(0, 50);
}

View File

@ -6,10 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {isBlank, isPresent, looseIdentical} from '../facade/lang';
import {ɵlooseIdentical as looseIdentical} from '@angular/core';
import {FormArray, FormControl, FormGroup} from '../model';
import {Validators} from '../validators';
import {AbstractControlDirective} from './abstract_control_directive';
import {AbstractFormGroupDirective} from './abstract_form_group_directive';
import {CheckboxControlValueAccessor} from './checkbox_value_accessor';
@ -95,7 +94,7 @@ export function cleanUpControl(control: FormControl, dir: NgControl) {
export function setUpFormContainer(
control: FormGroup | FormArray, dir: AbstractFormGroupDirective | FormArrayName) {
if (isBlank(control)) _throwError(dir, 'Cannot find control with');
if (control == null) _throwError(dir, 'Cannot find control with');
control.validator = Validators.compose([control.validator, dir.validator]);
control.asyncValidator = Validators.composeAsync([control.asyncValidator, dir.asyncValidator]);
}
@ -117,12 +116,12 @@ function _throwError(dir: AbstractControlDirective, message: string): void {
}
export function composeValidators(validators: Array<Validator|Function>): ValidatorFn {
return isPresent(validators) ? Validators.compose(validators.map(normalizeValidator)) : null;
return validators != null ? Validators.compose(validators.map(normalizeValidator)) : null;
}
export function composeAsyncValidators(validators: Array<Validator|Function>): AsyncValidatorFn {
return isPresent(validators) ? Validators.composeAsync(validators.map(normalizeAsyncValidator)) :
null;
return validators != null ? Validators.composeAsync(validators.map(normalizeAsyncValidator)) :
null;
}
export function isPropertyUpdated(changes: {[key: string]: any}, viewModel: any): boolean {

View File

@ -1 +0,0 @@
../../facade/src

View File

@ -9,7 +9,6 @@
import {Injectable} from '@angular/core';
import {AsyncValidatorFn, ValidatorFn} from './directives/validators';
import {isPresent} from './facade/lang';
import {AbstractControl, FormArray, FormControl, FormGroup} from './model';
/**
@ -42,8 +41,8 @@ export class FormBuilder {
*/
group(controlsConfig: {[key: string]: any}, extra: {[key: string]: any} = null): FormGroup {
const controls = this._reduceControls(controlsConfig);
const validator: ValidatorFn = isPresent(extra) ? extra['validator'] : null;
const asyncValidator: AsyncValidatorFn = isPresent(extra) ? extra['asyncValidator'] : null;
const validator: ValidatorFn = extra != null ? extra['validator'] : null;
const asyncValidator: AsyncValidatorFn = extra != null ? extra['asyncValidator'] : null;
return new FormGroup(controls, validator, asyncValidator);
}
/**

View File

@ -9,7 +9,6 @@
import {InjectionToken, ɵisPromise as isPromise, ɵmerge as merge} from '@angular/core';
import {toPromise} from 'rxjs/operator/toPromise';
import {AsyncValidatorFn, Validator, ValidatorFn} from './directives/validators';
import {isPresent} from './facade/lang';
import {AbstractControl, FormControl, FormGroup} from './model';
function isEmptyInputValue(value: any): boolean {
@ -187,6 +186,10 @@ export class Validators {
}
}
function isPresent(o: any): boolean {
return o != null;
}
function _convertToPromise(obj: any): Promise<any> {
return isPromise(obj) ? obj : toPromise.call(obj);
}
@ -202,7 +205,7 @@ function _executeAsyncValidators(control: AbstractControl, validators: AsyncVali
function _mergeErrors(arrayOfErrors: any[]): {[key: string]: any} {
const res: {[key: string]: any} =
arrayOfErrors.reduce((res: {[key: string]: any}, errors: {[key: string]: any}) => {
return isPresent(errors) ? merge(res, errors) : res;
return errors != null ? merge(res, errors) : res;
}, {});
return Object.keys(res).length === 0 ? null : res;
}

View File

@ -10,7 +10,6 @@ import {fakeAsync, tick} from '@angular/core/testing';
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/testing_internal';
import {AbstractControl, FormArray, FormControl, FormGroup} from '@angular/forms';
import {isPresent} from '../src/facade/lang';
import {Validators} from '../src/validators';
export function main() {
@ -18,7 +17,7 @@ export function main() {
return (c: AbstractControl) => {
let resolve: (result: any) => void;
const promise = new Promise(res => { resolve = res; });
const t = isPresent((timeouts as any)[c.value]) ? (timeouts as any)[c.value] : 0;
const t = (timeouts as any)[c.value] != null ? (timeouts as any)[c.value] : 0;
const res = c.value != expected ? {'async': true} : null;
if (t == 0) {

View File

@ -11,7 +11,6 @@ import {fakeAsync, tick} from '@angular/core/testing';
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/testing_internal';
import {FormControl, FormGroup, Validators} from '@angular/forms';
import {isPresent} from '../src/facade/lang';
import {FormArray} from '../src/model';
export function main() {
@ -19,7 +18,7 @@ export function main() {
return (c: FormControl) => {
let resolve: (result: any) => void;
const promise = new Promise(res => { resolve = res; });
const t = isPresent((timeouts as any)[c.value]) ? (timeouts as any)[c.value] : 0;
const t = (timeouts as any)[c.value] != null ? (timeouts as any)[c.value] : 0;
const res = c.value != expected ? {'async': true} : null;
if (t == 0) {

View File

@ -11,14 +11,13 @@ import {async, fakeAsync, tick} from '@angular/core/testing';
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/testing_internal';
import {AbstractControl, FormArray, FormControl, FormGroup, Validators} from '@angular/forms';
import {isPresent} from '../src/facade/lang';
export function main() {
function asyncValidator(expected: string, timeouts = {}) {
return (c: AbstractControl) => {
let resolve: (result: any) => void;
const promise = new Promise(res => { resolve = res; });
const t = isPresent((timeouts as any)[c.value]) ? (timeouts as any)[c.value] : 0;
const t = (timeouts as any)[c.value] != null ? (timeouts as any)[c.value] : 0;
const res = c.value != expected ? {'async': true} : null;
if (t == 0) {