Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(forms) : Change interface AsyncValidatorFn #14435

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
759d72e
fix(core): Remove reference to "Angular 2" in dev mode warning
wKoza Jan 2, 2017
1b51d1e
Merge pull request #2 from angular/master
wKoza Jan 10, 2017
608f9f7
Merge pull request #1 from wKoza/wKoza-patch-1
wKoza Jan 10, 2017
d72058c
refactor(Compiler): misc cleanup
vicb Jan 4, 2017
fb49a2d
docs(NgPlural): fix API docs
vicb Jan 5, 2017
2920925
fix(i18n): translate attributes inside elements marked for translation
vicb Jan 6, 2017
c4241d8
refactor(test): `<template>`/`<ng-container>`/*-directives
vicb Jan 6, 2017
70b7a45
refactor(common): remove some facade usages
pkozlowski-opensource Jan 10, 2017
5d0210e
fix(compiler-cli): avoid handling functions in loadChildren as lazy l…
Meligy Dec 31, 2016
fe6cb8b
chore(owners): configure pullapprove.com
alexeagle Jan 9, 2017
138ba40
docs(release-schedule): add release schedule doc (#13827)
IgorMinar Jan 11, 2017
f65cb2d
chore(release): cut the 4.0.0-beta.3 release
matsko Jan 11, 2017
b24b930
docs(changelog): add changelog for 2.4.3
matsko Jan 11, 2017
35f149d
docs(changelog): add changelog for 4.0.0-beta.3
matsko Jan 11, 2017
687c146
docs(http): Spelling Fix #13867
josenicomaia Jan 12, 2017
86611ed
fix(animations): fix internal jscompiler issue and AOT quoting (#13798)
matsko Jan 5, 2017
2e9cbc2
fix(common): support numeric value as discrete cases for NgPlural (#1…
marclaval Jan 11, 2017
0d98288
chore(compiler-cli): Move calculateEmitPath into CompilerHost (#13904)
vikerman Jan 12, 2017
6c20ba0
test(upgrade): reorganise test layout (#13812)
petebacondarwin Jan 13, 2017
b1b2c31
fix(upgrade): detect async downgrade component changes (#13812)
petebacondarwin Jan 13, 2017
815471d
docs(changelog): fix typo (#13934)
gkalpak Jan 15, 2017
3966f2a
feat(security): allow calc and gradient functions. (#13943)
mprobst Jan 16, 2017
9f757f9
refactor(core): opaque_token.ts -> injection_token.ts (must include s…
mhevery Jan 13, 2017
f3a2ccf
feat(core): Add type information to injector.get() (#13785)
mhevery Jan 4, 2017
05b4b6d
chore(tsc-wrapped): update tsickle to latest (#13471)
alexeagle Jan 13, 2017
7eca76c
feature(tsc-wrapped): re-write /index imports for closure compiler (#…
alexeagle Jan 13, 2017
711ff82
feature(tsc-wrapped): accept any tsc command line option (#13471)
alexeagle Jan 13, 2017
174bd09
feat(build): optionally build an ES2015 distro (#13471)
alexeagle Jan 13, 2017
333da93
refactor(router): clean up RouterLinkActive (#13273)
Dec 6, 2016
4247ed7
fix(router): routerLinkActive should not throw when not initialized (…
Dec 7, 2016
434bc1e
docs(CHANGELOG): added reference to closed issue in CHANGELOG for inf…
maartentibau Jan 18, 2017
213fdcd
refactor(core): remove an unused import in application_ref (#13901)
tcoz Jan 18, 2017
fac2a07
fix(router): enable loadChildren with function in aot (#13909)
DzmitryShylovich Jan 18, 2017
ac1236b
fix(http): don't create a blob out of ArrayBuffer when type is applic…
DzmitryShylovich Jan 19, 2017
fa7289c
docs(changelog): add changelog for 2.4.4
mhevery Jan 19, 2017
c5540cb
chore(release): cut the 4.0.0-beta.4 release
mhevery Jan 19, 2017
02f4622
docs(changelog): add changelog for 4.0.0-beta.4
mhevery Jan 19, 2017
d7d7cc7
chore(docs): add missing comments (#14003)
alexeagle Jan 19, 2017
67d738f
ci: fix travis environment to build es2015 distro (#13976)
alexeagle Jan 19, 2017
9af80c5
build(es2015): fix bad merge of #13471 (#14020)
alexeagle Jan 19, 2017
d3f035a
feat(core): add initial view engine (#14014)
tbosch Jan 20, 2017
e5312af
Fixed documentation reference to canActivate in canDeactivate (#14018)
Jan 20, 2017
a01abd2
Merge branch 'master' of https://github.com/angular/angular
wKoza Feb 12, 2017
10cbcd7
update upstream
wKoza Feb 12, 2017
be05fb5
refactor(forms) : Change interface AsyncValidatorFn
wKoza Feb 12, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions modules/@angular/forms/src/directives/normalize_validator.ts
Expand Up @@ -8,7 +8,7 @@

import {AbstractControl} from '../model';

import {AsyncValidatorFn, Validator, ValidatorFn} from './validators';
import {AsyncValidatorFn, Validator, ValidatorFn, AsyncValidator} from './validators';

export function normalizeValidator(validator: ValidatorFn | Validator): ValidatorFn {
if ((<Validator>validator).validate) {
Expand All @@ -18,9 +18,9 @@ export function normalizeValidator(validator: ValidatorFn | Validator): Validato
}
}

export function normalizeAsyncValidator(validator: AsyncValidatorFn | Validator): AsyncValidatorFn {
if ((<Validator>validator).validate) {
return (c: AbstractControl) => (<Validator>validator).validate(c);
export function normalizeAsyncValidator(validator: AsyncValidatorFn | AsyncValidator): AsyncValidatorFn {
if ((<AsyncValidator>validator).validate) {
return (c: AbstractControl) => (<AsyncValidator>validator).validate(c);
} else {
return <AsyncValidatorFn>validator;
}
Expand Down
27 changes: 26 additions & 1 deletion modules/@angular/forms/src/directives/validators.ts
Expand Up @@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Directive, Input, OnChanges, Provider, SimpleChanges, forwardRef} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {AbstractControl} from '../model';
import {NG_VALIDATORS, Validators} from '../validators';

Expand Down Expand Up @@ -33,6 +34,30 @@ export interface Validator {
registerOnValidatorChange?(fn: () => void): void;
}

/**
* An interface that can be implemented by classes that can act as AsyncValidators.
*
* ## Usage
*
* ```typescript
* @Directive({
* selector: '[custom-async-validator]',
* providers: [{provide: NG_ASYNC_VALIDATORS, useExisting: CustomAsyncValidatorDirective, multi: true}]
* })
* class CustomAsyncValidatorDirective implements AsyncValidator {
* validate(c: Control): Observable<{[key: string]: any}> {
* return Observable.of({custom: true});
* }
* }
* ```
*
* @stable
*/
export interface AsyncValidator {
validate(c: AbstractControl): Promise<{[key: string]: any}> | Observable<{[key: string]: any}>;
registerOnValidatorChange?(fn: () => void): void;
}

export const REQUIRED_VALIDATOR: Provider = {
provide: NG_VALIDATORS,
useExisting: forwardRef(() => RequiredValidator),
Expand Down Expand Up @@ -159,7 +184,7 @@ export interface ValidatorFn { (c: AbstractControl): {[key: string]: any}; }
* @stable
*/
export interface AsyncValidatorFn {
(c: AbstractControl): any /*Promise<{[key: string]: any}>|Observable<{[key: string]: any}>*/;
(c: AbstractControl): Promise<{[key: string]: any}>|Observable<{[key: string]: any}>;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions modules/@angular/forms/test/validators_spec.ts
Expand Up @@ -26,7 +26,7 @@ export function main() {
class AsyncValidatorDirective {
constructor(private expected: string, private error: any) {}

validate(c: any): {[key: string]: any;} {
validate(c: any): Observable<{[key: string]: any;}> {
return Observable.create((obs: any) => {
const error = this.expected !== c.value ? this.error : null;
obs.next(error);
Expand Down Expand Up @@ -271,7 +271,7 @@ export function main() {
]);

let value: any /** TODO #9100 */ = null;
(<Promise<any>>c(new FormControl('invalid'))).then(v => value = v);
(<Promise<{[key: string]: any}>>c(new FormControl('invalid'))).then(v => value = v);

tick(1);

Expand All @@ -283,7 +283,7 @@ export function main() {
[normalizeAsyncValidator(new AsyncValidatorDirective('expected', {'one': true}))]);

let value: any = null;
c(new FormControl()).then((v: any) => value = v);
(<Promise<{[key: string]: any}>>c(new FormControl())).then((v: any) => value = v);
tick(1);

expect(value).toEqual({'one': true});
Expand Down
6 changes: 5 additions & 1 deletion tools/public_api_guard/forms/index.d.ts
Expand Up @@ -103,7 +103,11 @@ export declare class AbstractFormGroupDirective extends ControlContainer impleme

/** @stable */
export interface AsyncValidatorFn {
(c: AbstractControl): any;
(c: AbstractControl): Promise<{
[key: string]: any;
}> | Observable<{
[key: string]: any;
}>;
}

/** @stable */
Expand Down