diff --git a/modules/@angular/common/src/forms-deprecated/directives/ng_control_name.ts b/modules/@angular/common/src/forms-deprecated/directives/ng_control_name.ts index 89aea96e99..23e281e061 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/ng_control_name.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/ng_control_name.ts @@ -8,7 +8,7 @@ import {Directive, Host, Inject, OnChanges, OnDestroy, Optional, Self, SimpleChanges, SkipSelf, forwardRef} from '@angular/core'; -import {EventEmitter, ObservableWrapper} from '../../facade/async'; +import {EventEmitter} from '../../facade/async'; import {Control} from '../model'; import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators'; @@ -122,7 +122,7 @@ export class NgControlName extends NgControl implements OnChanges, viewToModelUpdate(newValue: any): void { this.viewModel = newValue; - ObservableWrapper.callEmit(this.update, newValue); + this.update.emit(newValue); } get path(): string[] { return controlPath(this.name, this._parent); } diff --git a/modules/@angular/common/src/forms-deprecated/directives/ng_form.ts b/modules/@angular/common/src/forms-deprecated/directives/ng_form.ts index 23d7f3dd9f..261f7d4ea2 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/ng_form.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/ng_form.ts @@ -8,7 +8,7 @@ import {Directive, Inject, Optional, Self, forwardRef} from '@angular/core'; -import {EventEmitter, ObservableWrapper, PromiseWrapper} from '../../facade/async'; +import {EventEmitter} from '../../facade/async'; import {ListWrapper} from '../../facade/collection'; import {isPresent} from '../../facade/lang'; import {AbstractControl, Control, ControlGroup} from '../model'; @@ -27,6 +27,8 @@ export const formDirectiveProvider: any = { let _formWarningDisplayed: boolean = false; +const resolvedPromise = Promise.resolve(null); + /** * If `NgForm` is bound in a component, `
` elements in that component will be * upgraded to use the Angular form system. @@ -136,7 +138,7 @@ export class NgForm extends ControlContainer implements Form { get controls(): {[key: string]: AbstractControl} { return this.form.controls; } addControl(dir: NgControl): void { - PromiseWrapper.scheduleMicrotask(() => { + resolvedPromise.then(() => { var container = this._findContainer(dir.path); var ctrl = new Control(); setUpControl(ctrl, dir); @@ -148,7 +150,7 @@ export class NgForm extends ControlContainer implements Form { getControl(dir: NgControl): Control { return this.form.find(dir.path); } removeControl(dir: NgControl): void { - PromiseWrapper.scheduleMicrotask(() => { + resolvedPromise.then(() => { var container = this._findContainer(dir.path); if (isPresent(container)) { container.removeControl(dir.name); @@ -157,7 +159,7 @@ export class NgForm extends ControlContainer implements Form { } addControlGroup(dir: NgControlGroup): void { - PromiseWrapper.scheduleMicrotask(() => { + resolvedPromise.then(() => { var container = this._findContainer(dir.path); var group = new ControlGroup({}); setUpControlGroup(group, dir); @@ -167,7 +169,7 @@ export class NgForm extends ControlContainer implements Form { } removeControlGroup(dir: NgControlGroup): void { - PromiseWrapper.scheduleMicrotask(() => { + resolvedPromise.then(() => { var container = this._findContainer(dir.path); if (isPresent(container)) { container.removeControl(dir.name); @@ -180,7 +182,7 @@ export class NgForm extends ControlContainer implements Form { } updateModel(dir: NgControl, value: any): void { - PromiseWrapper.scheduleMicrotask(() => { + resolvedPromise.then(() => { var ctrl = this.form.find(dir.path); ctrl.updateValue(value); }); @@ -188,7 +190,7 @@ export class NgForm extends ControlContainer implements Form { onSubmit(): boolean { this._submitted = true; - ObservableWrapper.callEmit(this.ngSubmit, null); + this.ngSubmit.emit(null); return false; } diff --git a/modules/@angular/common/src/forms-deprecated/directives/ng_form_control.ts b/modules/@angular/common/src/forms-deprecated/directives/ng_form_control.ts index c003f1d562..13b7bfcd0d 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/ng_form_control.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/ng_form_control.ts @@ -8,7 +8,7 @@ import {Directive, Inject, OnChanges, Optional, Self, SimpleChanges, forwardRef} from '@angular/core'; -import {EventEmitter, ObservableWrapper} from '../../facade/async'; +import {EventEmitter} from '../../facade/async'; import {StringMapWrapper} from '../../facade/collection'; import {Control} from '../model'; import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators'; @@ -118,7 +118,7 @@ export class NgFormControl extends NgControl implements OnChanges { viewToModelUpdate(newValue: any): void { this.viewModel = newValue; - ObservableWrapper.callEmit(this.update, newValue); + this.update.emit(newValue); } private _isControlChanged(changes: {[key: string]: any}): boolean { diff --git a/modules/@angular/common/src/forms-deprecated/directives/ng_form_model.ts b/modules/@angular/common/src/forms-deprecated/directives/ng_form_model.ts index b987b521d0..c5e4a15316 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/ng_form_model.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/ng_form_model.ts @@ -8,7 +8,7 @@ import {Directive, Inject, OnChanges, Optional, Self, SimpleChanges, forwardRef} from '@angular/core'; -import {EventEmitter, ObservableWrapper} from '../../facade/async'; +import {EventEmitter} from '../../facade/async'; import {ListWrapper, StringMapWrapper} from '../../facade/collection'; import {BaseException} from '../../facade/exceptions'; import {isBlank} from '../../facade/lang'; @@ -191,7 +191,7 @@ export class NgFormModel extends ControlContainer implements Form, onSubmit(): boolean { this._submitted = true; - ObservableWrapper.callEmit(this.ngSubmit, null); + this.ngSubmit.emit(null); return false; } diff --git a/modules/@angular/common/src/forms-deprecated/directives/ng_model.ts b/modules/@angular/common/src/forms-deprecated/directives/ng_model.ts index 86ce0ec797..5853c4eb5d 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/ng_model.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/ng_model.ts @@ -8,7 +8,7 @@ import {Directive, Inject, OnChanges, Optional, Self, SimpleChanges, forwardRef} from '@angular/core'; -import {EventEmitter, ObservableWrapper} from '../../facade/async'; +import {EventEmitter} from '../../facade/async'; import {Control} from '../model'; import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators'; @@ -94,6 +94,6 @@ export class NgModel extends NgControl implements OnChanges { viewToModelUpdate(newValue: any): void { this.viewModel = newValue; - ObservableWrapper.callEmit(this.update, newValue); + this.update.emit(newValue); } } diff --git a/modules/@angular/common/src/forms-deprecated/model.ts b/modules/@angular/common/src/forms-deprecated/model.ts index 38bc4436b1..307a45c7ca 100644 --- a/modules/@angular/common/src/forms-deprecated/model.ts +++ b/modules/@angular/common/src/forms-deprecated/model.ts @@ -6,11 +6,15 @@ * found in the LICENSE file at https://angular.io/license */ -import {EventEmitter, Observable, ObservableWrapper} from '../facade/async'; +import {PromiseObservable} from 'rxjs/observable/PromiseObservable'; + +import {EventEmitter, Observable} from '../facade/async'; import {ListWrapper, StringMapWrapper} from '../facade/collection'; import {isBlank, isPresent, isPromise, normalizeBool} from '../facade/lang'; + import {AsyncValidatorFn, ValidatorFn} from './directives/validators'; + /** * Indicates that a Control is valid, i.e. that no errors exist in the input value. */ @@ -52,7 +56,7 @@ function _find(control: AbstractControl, path: Array| string) { } function toObservable(r: any): Observable { - return isPromise(r) ? ObservableWrapper.fromPromise(r) : r; + return isPromise(r) ? PromiseObservable.create(r) : r; } /** @@ -135,8 +139,8 @@ export abstract class AbstractControl { } if (emitEvent) { - ObservableWrapper.callEmit(this._valueChanges, this._value); - ObservableWrapper.callEmit(this._statusChanges, this._status); + this._valueChanges.emit(this._value); + this._statusChanges.emit(this._status); } if (isPresent(this._parent) && !onlySelf) { @@ -153,14 +157,14 @@ export abstract class AbstractControl { this._status = PENDING; this._cancelExistingSubscription(); var obs = toObservable(this.asyncValidator(this)); - this._asyncValidationSubscription = ObservableWrapper.subscribe( - obs, (res: {[key: string]: any}) => this.setErrors(res, {emitEvent: emitEvent})); + this._asyncValidationSubscription = obs.subscribe( + {next: (res: {[key: string]: any}) => this.setErrors(res, {emitEvent: emitEvent})}); } } private _cancelExistingSubscription(): void { if (isPresent(this._asyncValidationSubscription)) { - ObservableWrapper.dispose(this._asyncValidationSubscription); + this._asyncValidationSubscription.unsubscribe(); } } @@ -194,7 +198,7 @@ export abstract class AbstractControl { this._status = this._calculateStatus(); if (emitEvent) { - ObservableWrapper.callEmit(this._statusChanges, this._status); + this._statusChanges.emit(this._status); } if (isPresent(this._parent)) { diff --git a/modules/@angular/common/src/forms-deprecated/validators.ts b/modules/@angular/common/src/forms-deprecated/validators.ts index bbcb8765a2..b75f4f2b4d 100644 --- a/modules/@angular/common/src/forms-deprecated/validators.ts +++ b/modules/@angular/common/src/forms-deprecated/validators.ts @@ -7,13 +7,15 @@ */ import {OpaqueToken} from '@angular/core'; -import {ObservableWrapper} from '../facade/async'; +import {toPromise} from 'rxjs/operator/toPromise'; + import {StringMapWrapper} from '../facade/collection'; import {isBlank, isPresent, isPromise, isString} from '../facade/lang'; -import {PromiseWrapper} from '../facade/promise'; + import {AsyncValidatorFn, ValidatorFn} from './directives/validators'; import {AbstractControl} from './model'; + /** * Providers for validators to be used for {@link Control}s in a form. * @@ -127,13 +129,13 @@ export class Validators { return function(control: AbstractControl) { let promises = _executeAsyncValidators(control, presentValidators).map(_convertToPromise); - return PromiseWrapper.all(promises).then(_mergeErrors); + return Promise.all(promises).then(_mergeErrors); }; } } function _convertToPromise(obj: any): Promise { - return isPromise(obj) ? obj : ObservableWrapper.toPromise(obj); + return isPromise(obj) ? obj : toPromise.call(obj); } function _executeValidators(control: AbstractControl, validators: ValidatorFn[]): any[] { diff --git a/modules/@angular/common/src/location/location.ts b/modules/@angular/common/src/location/location.ts index f19b41b7a7..6739a5029e 100644 --- a/modules/@angular/common/src/location/location.ts +++ b/modules/@angular/common/src/location/location.ts @@ -8,8 +8,6 @@ import {EventEmitter, Injectable} from '@angular/core'; -import {ObservableWrapper} from '../facade/async'; - import {LocationStrategy} from './location_strategy'; @@ -69,10 +67,8 @@ export class Location { this._platformStrategy = platformStrategy; var browserBaseHref = this._platformStrategy.getBaseHref(); this._baseHref = Location.stripTrailingSlash(_stripIndexHtml(browserBaseHref)); - this._platformStrategy.onPopState((ev) => { - ObservableWrapper.callEmit( - this._subject, {'url': this.path(true), 'pop': true, 'type': ev.type}); - }); + this._platformStrategy.onPopState( + (ev) => { this._subject.emit({'url': this.path(true), 'pop': true, 'type': ev.type}); }); } /** @@ -145,7 +141,7 @@ export class Location { subscribe( onNext: (value: any) => void, onThrow: (exception: any) => void = null, onReturn: () => void = null): Object { - return ObservableWrapper.subscribe(this._subject, onNext, onThrow, onReturn); + return this._subject.subscribe({next: onNext, error: onThrow, complete: onReturn}); } /** diff --git a/modules/@angular/common/src/pipes/async_pipe.ts b/modules/@angular/common/src/pipes/async_pipe.ts index 4ba96aff35..2507794282 100644 --- a/modules/@angular/common/src/pipes/async_pipe.ts +++ b/modules/@angular/common/src/pipes/async_pipe.ts @@ -7,7 +7,7 @@ */ import {ChangeDetectorRef, OnDestroy, Pipe, WrappedValue} from '@angular/core'; -import {EventEmitter, Observable, ObservableWrapper} from '../facade/async'; +import {EventEmitter, Observable} from '../facade/async'; import {isBlank, isPresent, isPromise} from '../facade/lang'; import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception'; @@ -19,12 +19,12 @@ interface SubscriptionStrategy { class ObservableStrategy implements SubscriptionStrategy { createSubscription(async: any, updateLatestValue: any): any { - return ObservableWrapper.subscribe(async, updateLatestValue, e => { throw e; }); + return async.subscribe({next: updateLatestValue, error: (e: any) => { throw e; }}); } - dispose(subscription: any): void { ObservableWrapper.dispose(subscription); } + dispose(subscription: any): void { subscription.unsubscribe(); } - onDestroy(subscription: any): void { ObservableWrapper.dispose(subscription); } + onDestroy(subscription: any): void { subscription.unsubscribe(); } } class PromiseStrategy implements SubscriptionStrategy { @@ -125,7 +125,7 @@ export class AsyncPipe implements OnDestroy { _selectStrategy(obj: Observable|Promise|EventEmitter): any { if (isPromise(obj)) { return _promiseStrategy; - } else if (ObservableWrapper.isObservable(obj)) { + } else if ((obj).subscribe) { return _observableStrategy; } else { throw new InvalidPipeArgumentException(AsyncPipe, obj); diff --git a/modules/@angular/common/test/directives/ng_for_spec.ts b/modules/@angular/common/test/directives/ng_for_spec.ts index 528a405f55..283979ecf9 100644 --- a/modules/@angular/common/test/directives/ng_for_spec.ts +++ b/modules/@angular/common/test/directives/ng_for_spec.ts @@ -6,13 +6,14 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; -import {TestComponentBuilder} from '@angular/core/testing'; -import {ListWrapper} from '../../src/facade/collection'; -import {Component, TemplateRef, ContentChild} from '@angular/core'; import {NgFor, NgIf} from '@angular/common'; -import {expect} from '@angular/platform-browser/testing/matchers'; +import {Component, ContentChild, TemplateRef} from '@angular/core'; +import {TestComponentBuilder} from '@angular/core/testing'; +import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; import {By} from '@angular/platform-browser/src/dom/debug/by'; +import {expect} from '@angular/platform-browser/testing/matchers'; + +import {ListWrapper} from '../../src/facade/collection'; let thisArg: any; diff --git a/modules/@angular/common/test/directives/ng_if_spec.ts b/modules/@angular/common/test/directives/ng_if_spec.ts index 779c7db625..5a61a0648b 100644 --- a/modules/@angular/common/test/directives/ng_if_spec.ts +++ b/modules/@angular/common/test/directives/ng_if_spec.ts @@ -6,13 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, ddescribe, describe, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; -import {TestComponentBuilder} from '@angular/core/testing'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; - -import {Component} from '@angular/core'; import {NgIf} from '@angular/common'; +import {Component} from '@angular/core'; +import {TestComponentBuilder} from '@angular/core/testing'; +import {AsyncTestCompleter, beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; +import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; +import {expect} from '@angular/platform-browser/testing/matchers'; export function main() { describe('ngIf directive', () => { diff --git a/modules/@angular/common/test/directives/ng_plural_spec.ts b/modules/@angular/common/test/directives/ng_plural_spec.ts index a298e45ac4..aef41421c2 100644 --- a/modules/@angular/common/test/directives/ng_plural_spec.ts +++ b/modules/@angular/common/test/directives/ng_plural_spec.ts @@ -6,12 +6,11 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEachProviders, beforeEach, ddescribe, describe, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {TestComponentBuilder} from '@angular/core/testing'; - +import {NgLocalization, NgPlural, NgPluralCase} from '@angular/common'; import {Component, Injectable} from '@angular/core'; -import {NgPlural, NgPluralCase, NgLocalization} from '@angular/common'; +import {TestComponentBuilder} from '@angular/core/testing'; +import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; +import {expect} from '@angular/platform-browser/testing/matchers'; export function main() { describe('switch', () => { diff --git a/modules/@angular/common/test/directives/ng_switch_spec.ts b/modules/@angular/common/test/directives/ng_switch_spec.ts index 10759199a1..17b82b35b4 100644 --- a/modules/@angular/common/test/directives/ng_switch_spec.ts +++ b/modules/@angular/common/test/directives/ng_switch_spec.ts @@ -6,12 +6,11 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, ddescribe, describe, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; +import {NgSwitch, NgSwitchCase, NgSwitchDefault} from '@angular/common'; import {Component} from '@angular/core'; import {TestComponentBuilder} from '@angular/core/testing'; - -import {NgSwitch, NgSwitchCase, NgSwitchDefault} from '@angular/common'; +import {AsyncTestCompleter, beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; +import {expect} from '@angular/platform-browser/testing/matchers'; export function main() { describe('switch', () => { diff --git a/modules/@angular/common/test/directives/ng_template_outlet_spec.ts b/modules/@angular/common/test/directives/ng_template_outlet_spec.ts index cdc6e2cc27..98d7c86747 100644 --- a/modules/@angular/common/test/directives/ng_template_outlet_spec.ts +++ b/modules/@angular/common/test/directives/ng_template_outlet_spec.ts @@ -6,11 +6,11 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, ddescribe, describe, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {TestComponentBuilder} from '@angular/core/testing'; -import {Component, Directive, TemplateRef, ContentChildren, QueryList} from '@angular/core'; import {NgTemplateOutlet} from '@angular/common'; +import {Component, ContentChildren, Directive, QueryList, TemplateRef} from '@angular/core'; +import {TestComponentBuilder} from '@angular/core/testing'; +import {AsyncTestCompleter, beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; +import {expect} from '@angular/platform-browser/testing/matchers'; export function main() { describe('insert', () => { diff --git a/modules/@angular/common/test/directives/non_bindable_spec.ts b/modules/@angular/common/test/directives/non_bindable_spec.ts index c7416f25b1..64f9f3af48 100644 --- a/modules/@angular/common/test/directives/non_bindable_spec.ts +++ b/modules/@angular/common/test/directives/non_bindable_spec.ts @@ -6,12 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, ddescribe, describe, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {TestComponentBuilder} from '@angular/core/testing'; -import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {Component, Directive} from '@angular/core'; import {ElementRef} from '@angular/core/src/linker/element_ref'; +import {TestComponentBuilder} from '@angular/core/testing'; +import {AsyncTestCompleter, beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; +import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; +import {expect} from '@angular/platform-browser/testing/matchers'; export function main() { describe('non-bindable', () => { diff --git a/modules/@angular/common/test/forms-deprecated/directives_spec.ts b/modules/@angular/common/test/forms-deprecated/directives_spec.ts index 31dc054f21..0980e2db50 100644 --- a/modules/@angular/common/test/forms-deprecated/directives_spec.ts +++ b/modules/@angular/common/test/forms-deprecated/directives_spec.ts @@ -6,20 +6,14 @@ * found in the LICENSE file at https://angular.io/license */ +import {CheckboxControlValueAccessor, Control, ControlGroup, ControlValueAccessor, DefaultValueAccessor, NgControl, NgControlGroup, NgControlName, NgForm, NgFormControl, NgFormModel, NgModel, SelectControlValueAccessor, Validator, Validators} from '@angular/common/src/forms-deprecated'; +import {composeValidators, selectValueAccessor} from '@angular/common/src/forms-deprecated/directives/shared'; +import {SimpleChange} from '@angular/core/src/change_detection'; +import {fakeAsync, flushMicrotasks, tick} from '@angular/core/testing'; import {afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; -import {fakeAsync, flushMicrotasks, tick,} from '@angular/core/testing'; - import {SpyNgControl, SpyValueAccessor} from '../spies'; -import {ControlGroup, Control, NgControlName, NgControlGroup, NgFormModel, ControlValueAccessor, Validators, NgForm, NgModel, NgFormControl, NgControl, DefaultValueAccessor, CheckboxControlValueAccessor, SelectControlValueAccessor, Validator} from '@angular/common/src/forms-deprecated'; - - -import {selectValueAccessor, composeValidators} from '@angular/common/src/forms-deprecated/directives/shared'; -import {TimerWrapper} from '../../src/facade/async'; -import {PromiseWrapper} from '../../src/facade/promise'; -import {SimpleChange} from '@angular/core/src/change_detection'; - class DummyControlValueAccessor implements ControlValueAccessor { writtenValue: any /** TODO #9100 */; @@ -35,14 +29,14 @@ class CustomValidatorDirective implements Validator { function asyncValidator(expected: any /** TODO #9100 */, timeout = 0) { return (c: any /** TODO #9100 */) => { - var completer = PromiseWrapper.completer(); - var res = c.value != expected ? {'async': true} : null; - if (timeout == 0) { - completer.resolve(res); - } else { - TimerWrapper.setTimeout(() => { completer.resolve(res); }, timeout); - } - return completer.promise; + return new Promise((resolve) => { + var res = c.value != expected ? {'async': true} : null; + if (timeout == 0) { + resolve(res); + } else { + setTimeout(() => { resolve(res); }, timeout); + } + }); }; } diff --git a/modules/@angular/common/test/forms-deprecated/form_builder_spec.ts b/modules/@angular/common/test/forms-deprecated/form_builder_spec.ts index ac6a133f7c..7b6b50cdc8 100644 --- a/modules/@angular/common/test/forms-deprecated/form_builder_spec.ts +++ b/modules/@angular/common/test/forms-deprecated/form_builder_spec.ts @@ -9,11 +9,9 @@ import {Control, FormBuilder} from '@angular/common/src/forms-deprecated'; import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from '@angular/core/testing/testing_internal'; -import {PromiseWrapper} from '../../src/facade/promise'; - export function main() { function syncValidator(_: any): any { return null; } - function asyncValidator(_: any) { return PromiseWrapper.resolve(null); } + function asyncValidator(_: any) { return Promise.resolve(null); } describe('Form Builder', () => { var b: any /** TODO #9100 */; diff --git a/modules/@angular/common/test/forms-deprecated/integration_spec.ts b/modules/@angular/common/test/forms-deprecated/integration_spec.ts index dee202fce2..8ab1f76611 100644 --- a/modules/@angular/common/test/forms-deprecated/integration_spec.ts +++ b/modules/@angular/common/test/forms-deprecated/integration_spec.ts @@ -15,9 +15,7 @@ import {By} from '@angular/platform-browser/src/dom/debug/by'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {dispatchEvent} from '@angular/platform-browser/testing/browser_util'; -import {ObservableWrapper, TimerWrapper} from '../../src/facade/async'; import {ListWrapper} from '../../src/facade/collection'; -import {PromiseWrapper} from '../../src/facade/promise'; export function main() { describe('integration tests', () => { @@ -98,8 +96,8 @@ export function main() { input.nativeElement.value = 'updatedValue'; - ObservableWrapper.subscribe( - form.valueChanges, (value) => { throw 'Should not happen'; }); + + form.valueChanges.subscribe({next: (value: any) => { throw 'Should not happen'; }}); dispatchEvent(input.nativeElement, 'change'); async.done(); @@ -606,7 +604,7 @@ export function main() { select.nativeElement.value = '2: Object'; dispatchEvent(select.nativeElement, 'change'); fixture.detectChanges(); - TimerWrapper.setTimeout(() => { + setTimeout(() => { expect(testComp.selectedCity['name']).toEqual('Buffalo'); async.done(); }, 0); @@ -831,11 +829,13 @@ export function main() { expect(input.componentInstance.value).toEqual('!aa!'); input.componentInstance.value = '!bb!'; - ObservableWrapper.subscribe(input.componentInstance.onInput, (value) => { - expect(fixture.debugElement.componentInstance.form.value).toEqual({ - 'name': 'bb' - }); - async.done(); + input.componentInstance.onInput.subscribe({ + next: (value: any) => { + expect(fixture.debugElement.componentInstance.form.value).toEqual({ + 'name': 'bb' + }); + async.done(); + } }); input.componentInstance.dispatchChangeEvent(); }); @@ -1491,21 +1491,16 @@ class MyInput implements ControlValueAccessor { writeValue(value: any /** TODO #9100 */) { this.value = `!${value}!`; } - registerOnChange(fn: any /** TODO #9100 */) { ObservableWrapper.subscribe(this.onInput, fn); } + registerOnChange(fn: any /** TODO #9100 */) { this.onInput.subscribe({next: fn}); } registerOnTouched(fn: any /** TODO #9100 */) {} - dispatchChangeEvent() { - ObservableWrapper.callEmit(this.onInput, this.value.substring(1, this.value.length - 1)); - } + dispatchChangeEvent() { this.onInput.emit(this.value.substring(1, this.value.length - 1)); } } function uniqLoginAsyncValidator(expectedValue: string) { return (c: any /** TODO #9100 */) => { - var completer = PromiseWrapper.completer(); - var res = (c.value == expectedValue) ? null : {'uniqLogin': true}; - completer.resolve(res); - return completer.promise; + return Promise.resolve((c.value == expectedValue) ? null : {'uniqLogin': true}); }; } diff --git a/modules/@angular/common/test/forms-deprecated/model_spec.ts b/modules/@angular/common/test/forms-deprecated/model_spec.ts index f68b1060f3..bdf95318ec 100644 --- a/modules/@angular/common/test/forms-deprecated/model_spec.ts +++ b/modules/@angular/common/test/forms-deprecated/model_spec.ts @@ -6,35 +6,34 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, inject,} from '@angular/core/testing/testing_internal'; +import {Control, ControlArray, ControlGroup, Validators} from '@angular/common/src/forms-deprecated'; import {fakeAsync, flushMicrotasks, tick} from '@angular/core/testing'; -import {ControlGroup, Control, ControlArray, Validators} from '@angular/common/src/forms-deprecated'; +import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; + +import {EventEmitter} from '../../src/facade/async'; import {isPresent} from '../../src/facade/lang'; -import {PromiseWrapper} from '../../src/facade/promise'; -import {TimerWrapper, ObservableWrapper, EventEmitter} from '../../src/facade/async'; export function main() { function asyncValidator(expected: any /** TODO #9100 */, timeouts = {}) { return (c: any /** TODO #9100 */) => { - var completer = PromiseWrapper.completer(); - var t = isPresent((timeouts as any /** TODO #9100 */)[c.value]) ? - (timeouts as any /** TODO #9100 */)[c.value] : - 0; - var res = c.value != expected ? {'async': true} : null; + return new Promise((resolve) => { + var t = isPresent((timeouts as any /** TODO #9100 */)[c.value]) ? + (timeouts as any /** TODO #9100 */)[c.value] : + 0; + var res = c.value != expected ? {'async': true} : null; - if (t == 0) { - completer.resolve(res); - } else { - TimerWrapper.setTimeout(() => { completer.resolve(res); }, t); - } - - return completer.promise; + if (t == 0) { + resolve(res); + } else { + setTimeout(() => { resolve(res); }, t); + } + }); }; } function asyncValidatorReturningObservable(c: any /** TODO #9100 */) { var e = new EventEmitter(); - PromiseWrapper.scheduleMicrotask(() => ObservableWrapper.callEmit(e, {'async': true})); + Promise.resolve(null).then(() => { e.emit({'async': true}); }); return e; } @@ -179,15 +178,16 @@ export function main() { }); it('should fire an event', fakeAsync(() => { - ObservableWrapper.subscribe( - c.valueChanges, (value) => { expect(value).toEqual('newValue'); }); + + c.valueChanges.subscribe( + {next: (value: any) => { expect(value).toEqual('newValue'); }}); c.updateValue('newValue'); tick(); })); it('should not fire an event when explicitly specified', fakeAsync(() => { - ObservableWrapper.subscribe(c.valueChanges, (value) => { throw 'Should not happen'; }); + c.valueChanges.subscribe({next: (value: any) => { throw 'Should not happen'; }}); c.updateValue('newValue', {emitEvent: false}); @@ -202,18 +202,22 @@ export function main() { it('should fire an event after the value has been updated', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - ObservableWrapper.subscribe(c.valueChanges, (value) => { - expect(c.value).toEqual('new'); - expect(value).toEqual('new'); - async.done(); + c.valueChanges.subscribe({ + next: (value: any) => { + expect(c.value).toEqual('new'); + expect(value).toEqual('new'); + async.done(); + } }); c.updateValue('new'); })); it('should fire an event after the status has been updated to invalid', fakeAsync(() => { - ObservableWrapper.subscribe(c.statusChanges, (status) => { - expect(c.status).toEqual('INVALID'); - expect(status).toEqual('INVALID'); + c.statusChanges.subscribe({ + next: (status: any) => { + expect(c.status).toEqual('INVALID'); + expect(status).toEqual('INVALID'); + } }); c.updateValue(''); @@ -224,9 +228,9 @@ export function main() { var c = new Control('old', Validators.required, asyncValidator('expected')); var log: any[] /** TODO #9100 */ = []; - ObservableWrapper.subscribe(c.valueChanges, (value) => log.push(`value: '${value}'`)); - ObservableWrapper.subscribe( - c.statusChanges, (status) => log.push(`status: '${status}'`)); + c.valueChanges.subscribe({next: (value: any) => log.push(`value: '${value}'`)}); + + c.statusChanges.subscribe({next: (status: any) => log.push(`status: '${status}'`)}); c.updateValue(''); tick(); @@ -264,9 +268,11 @@ export function main() { it('should return a cold observable', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { c.updateValue('will be ignored'); - ObservableWrapper.subscribe(c.valueChanges, (value) => { - expect(value).toEqual('new'); - async.done(); + c.valueChanges.subscribe({ + next: (value: any) => { + expect(value).toEqual('new'); + async.done(); + } }); c.updateValue('new'); })); @@ -480,10 +486,12 @@ export function main() { it('should fire an event after the value has been updated', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - ObservableWrapper.subscribe(g.valueChanges, (value) => { - expect(g.value).toEqual({'one': 'new1', 'two': 'old2'}); - expect(value).toEqual({'one': 'new1', 'two': 'old2'}); - async.done(); + g.valueChanges.subscribe({ + next: (value: any) => { + expect(g.value).toEqual({'one': 'new1', 'two': 'old2'}); + expect(value).toEqual({'one': 'new1', 'two': 'old2'}); + async.done(); + } }); c1.updateValue('new1'); })); @@ -492,12 +500,14 @@ export function main() { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { var controlCallbackIsCalled = false; - ObservableWrapper.subscribe( - c1.valueChanges, (value) => { controlCallbackIsCalled = true; }); - ObservableWrapper.subscribe(g.valueChanges, (value) => { - expect(controlCallbackIsCalled).toBe(true); - async.done(); + c1.valueChanges.subscribe({next: (value: any) => { controlCallbackIsCalled = true; }}); + + g.valueChanges.subscribe({ + next: (value: any) => { + expect(controlCallbackIsCalled).toBe(true); + async.done(); + } }); c1.updateValue('new1'); @@ -505,9 +515,11 @@ export function main() { it('should fire an event when a control is excluded', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - ObservableWrapper.subscribe(g.valueChanges, (value) => { - expect(value).toEqual({'one': 'old1'}); - async.done(); + g.valueChanges.subscribe({ + next: (value: any) => { + expect(value).toEqual({'one': 'old1'}); + async.done(); + } }); g.exclude('two'); @@ -517,9 +529,11 @@ export function main() { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { g.exclude('two'); - ObservableWrapper.subscribe(g.valueChanges, (value) => { - expect(value).toEqual({'one': 'old1', 'two': 'old2'}); - async.done(); + g.valueChanges.subscribe({ + next: (value: any) => { + expect(value).toEqual({'one': 'old1', 'two': 'old2'}); + async.done(); + } }); g.include('two'); @@ -529,14 +543,16 @@ export function main() { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { var loggedValues: any[] /** TODO #9100 */ = []; - ObservableWrapper.subscribe(g.valueChanges, (value) => { - loggedValues.push(value); + g.valueChanges.subscribe({ + next: (value: any) => { + loggedValues.push(value); - if (loggedValues.length == 2) { - expect(loggedValues).toEqual([ - {'one': 'new1', 'two': 'old2'}, {'one': 'new1', 'two': 'new2'} - ]); - async.done(); + if (loggedValues.length == 2) { + expect(loggedValues).toEqual([ + {'one': 'new1', 'two': 'old2'}, {'one': 'new1', 'two': 'new2'} + ]); + async.done(); + } } }); @@ -735,10 +751,12 @@ export function main() { it('should fire an event after the value has been updated', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - ObservableWrapper.subscribe(a.valueChanges, (value) => { - expect(a.value).toEqual(['new1', 'old2']); - expect(value).toEqual(['new1', 'old2']); - async.done(); + a.valueChanges.subscribe({ + next: (value: any) => { + expect(a.value).toEqual(['new1', 'old2']); + expect(value).toEqual(['new1', 'old2']); + async.done(); + } }); c1.updateValue('new1'); })); @@ -747,12 +765,14 @@ export function main() { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { var controlCallbackIsCalled = false; - ObservableWrapper.subscribe( - c1.valueChanges, (value) => { controlCallbackIsCalled = true; }); - ObservableWrapper.subscribe(a.valueChanges, (value) => { - expect(controlCallbackIsCalled).toBe(true); - async.done(); + c1.valueChanges.subscribe({next: (value: any) => { controlCallbackIsCalled = true; }}); + + a.valueChanges.subscribe({ + next: (value: any) => { + expect(controlCallbackIsCalled).toBe(true); + async.done(); + } }); c1.updateValue('new1'); @@ -760,9 +780,11 @@ export function main() { it('should fire an event when a control is removed', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - ObservableWrapper.subscribe(a.valueChanges, (value) => { - expect(value).toEqual(['old1']); - async.done(); + a.valueChanges.subscribe({ + next: (value: any) => { + expect(value).toEqual(['old1']); + async.done(); + } }); a.removeAt(1); @@ -772,9 +794,11 @@ export function main() { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { a.removeAt(1); - ObservableWrapper.subscribe(a.valueChanges, (value) => { - expect(value).toEqual(['old1', 'old2']); - async.done(); + a.valueChanges.subscribe({ + next: (value: any) => { + expect(value).toEqual(['old1', 'old2']); + async.done(); + } }); a.push(c2); diff --git a/modules/@angular/common/test/forms-deprecated/validators_spec.ts b/modules/@angular/common/test/forms-deprecated/validators_spec.ts index 00ec51a75c..0515ae1aeb 100644 --- a/modules/@angular/common/test/forms-deprecated/validators_spec.ts +++ b/modules/@angular/common/test/forms-deprecated/validators_spec.ts @@ -11,8 +11,7 @@ import {fakeAsync, flushMicrotasks, tick} from '@angular/core/testing'; import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from '@angular/core/testing/testing_internal'; import {Observable} from 'rxjs/Observable'; -import {EventEmitter, ObservableWrapper, TimerWrapper} from '../../src/facade/async'; -import {PromiseWrapper} from '../../src/facade/promise'; +import {EventEmitter} from '../../src/facade/async'; import {normalizeAsyncValidator} from '../../src/forms-deprecated/directives/normalize_validator'; export function main() { @@ -143,14 +142,14 @@ export function main() { return (c: any /** TODO #9100 */) => { var emitter = new EventEmitter(); var res = c.value != expected ? response : null; - - PromiseWrapper.scheduleMicrotask(() => { - ObservableWrapper.callEmit(emitter, res); + Promise.resolve(null).then(() => { + emitter.emit(res); // this is required because of a bug in ObservableWrapper // where callComplete can fire before callEmit // remove this one the bug is fixed - TimerWrapper.setTimeout(() => { ObservableWrapper.callComplete(emitter); }, 0); + setTimeout(() => { emitter.complete(); }, 0); }); + return emitter; }; } diff --git a/modules/@angular/common/test/pipes/async_pipe_spec.ts b/modules/@angular/common/test/pipes/async_pipe_spec.ts index 90f6d1d8bb..a0240a89e1 100644 --- a/modules/@angular/common/test/pipes/async_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/async_pipe_spec.ts @@ -6,16 +6,16 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, inject,} from '@angular/core/testing/testing_internal'; -import {SpyChangeDetectorRef} from '../spies'; -import {isBlank} from '../../src/facade/lang'; import {AsyncPipe} from '@angular/common'; import {WrappedValue} from '@angular/core'; -import {EventEmitter, ObservableWrapper, PromiseWrapper, TimerWrapper} from '../../src/facade/async'; +import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; -import {PromiseCompleter} from '../../src/facade/promise'; import {browserDetection} from '@angular/platform-browser/testing/browser_util'; +import {EventEmitter} from '../../src/facade/async'; +import {isBlank} from '../../src/facade/lang'; +import {SpyChangeDetectorRef} from '../spies'; + export function main() { describe('AsyncPipe', () => { @@ -38,10 +38,9 @@ export function main() { it('should return the latest available value wrapped', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { pipe.transform(emitter); + emitter.emit(message); - ObservableWrapper.callEmit(emitter, message); - - TimerWrapper.setTimeout(() => { + setTimeout(() => { expect(pipe.transform(emitter)).toEqual(new WrappedValue(message)); async.done(); }, 0); @@ -51,9 +50,9 @@ export function main() { it('should return same value when nothing has changed since the last call', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { pipe.transform(emitter); - ObservableWrapper.callEmit(emitter, message); + emitter.emit(message); - TimerWrapper.setTimeout(() => { + setTimeout(() => { pipe.transform(emitter); expect(pipe.transform(emitter)).toBe(message); async.done(); @@ -66,11 +65,10 @@ export function main() { var newEmitter = new EventEmitter(); expect(pipe.transform(newEmitter)).toBe(null); + emitter.emit(message); // this should not affect the pipe - ObservableWrapper.callEmit(emitter, message); - - TimerWrapper.setTimeout(() => { + setTimeout(() => { expect(pipe.transform(newEmitter)).toBe(null); async.done(); }, 0); @@ -79,9 +77,9 @@ export function main() { it('should request a change detection check upon receiving a new value', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { pipe.transform(emitter); - ObservableWrapper.callEmit(emitter, message); + emitter.emit(message); - TimerWrapper.setTimeout(() => { + setTimeout(() => { expect(ref.spy('markForCheck')).toHaveBeenCalled(); async.done(); }, 10); @@ -96,10 +94,9 @@ export function main() { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { pipe.transform(emitter); pipe.ngOnDestroy(); + emitter.emit(message); - ObservableWrapper.callEmit(emitter, message); - - TimerWrapper.setTimeout(() => { + setTimeout(() => { expect(pipe.transform(emitter)).toBe(null); async.done(); }, 0); @@ -110,57 +107,62 @@ export function main() { describe('Promise', () => { var message = new Object(); var pipe: AsyncPipe; - var completer: PromiseCompleter; + var resolve: (result: any) => void; + var reject: (error: any) => void; + var promise: Promise; var ref: SpyChangeDetectorRef; // adds longer timers for passing tests in IE var timer = (!isBlank(getDOM()) && browserDetection.isIE) ? 50 : 10; beforeEach(() => { - completer = PromiseWrapper.completer(); + promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); ref = new SpyChangeDetectorRef(); pipe = new AsyncPipe(ref); }); describe('transform', () => { it('should return null when subscribing to a promise', - () => { expect(pipe.transform(completer.promise)).toBe(null); }); + () => { expect(pipe.transform(promise)).toBe(null); }); it('should return the latest available value', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - pipe.transform(completer.promise); + pipe.transform(promise); - completer.resolve(message); + resolve(message); - TimerWrapper.setTimeout(() => { - expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message)); + setTimeout(() => { + expect(pipe.transform(promise)).toEqual(new WrappedValue(message)); async.done(); }, timer); })); it('should return unwrapped value when nothing has changed since the last call', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - pipe.transform(completer.promise); - completer.resolve(message); + pipe.transform(promise); + resolve(message); - TimerWrapper.setTimeout(() => { - pipe.transform(completer.promise); - expect(pipe.transform(completer.promise)).toBe(message); + setTimeout(() => { + pipe.transform(promise); + expect(pipe.transform(promise)).toBe(message); async.done(); }, timer); })); it('should dispose of the existing subscription when subscribing to a new promise', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - pipe.transform(completer.promise); + pipe.transform(promise); - var newCompleter = PromiseWrapper.completer(); - expect(pipe.transform(newCompleter.promise)).toBe(null); + var promise = new Promise(() => {}); + expect(pipe.transform(promise)).toBe(null); // this should not affect the pipe, so it should return WrappedValue - completer.resolve(message); + resolve(message); - TimerWrapper.setTimeout(() => { - expect(pipe.transform(newCompleter.promise)).toBe(null); + setTimeout(() => { + expect(pipe.transform(promise)).toBe(null); async.done(); }, timer); })); @@ -168,10 +170,10 @@ export function main() { it('should request a change detection check upon receiving a new value', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { var markForCheck = ref.spy('markForCheck'); - pipe.transform(completer.promise); - completer.resolve(message); + pipe.transform(promise); + resolve(message); - TimerWrapper.setTimeout(() => { + setTimeout(() => { expect(markForCheck).toHaveBeenCalled(); async.done(); }, timer); @@ -183,15 +185,15 @@ export function main() { it('should dispose of the existing source', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - pipe.transform(completer.promise); - expect(pipe.transform(completer.promise)).toBe(null); - completer.resolve(message); + pipe.transform(promise); + expect(pipe.transform(promise)).toBe(null); + resolve(message); - TimerWrapper.setTimeout(() => { - expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message)); + setTimeout(() => { + expect(pipe.transform(promise)).toEqual(new WrappedValue(message)); pipe.ngOnDestroy(); - expect(pipe.transform(completer.promise)).toBe(null); + expect(pipe.transform(promise)).toBe(null); async.done(); }, timer); })); diff --git a/modules/@angular/common/test/pipes/json_pipe_spec.ts b/modules/@angular/common/test/pipes/json_pipe_spec.ts index 8d44e702a7..83c5a16ac2 100644 --- a/modules/@angular/common/test/pipes/json_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/json_pipe_spec.ts @@ -6,13 +6,13 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, ddescribe, describe, it, iit, xit, beforeEach, afterEach, inject,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {TestComponentBuilder} from '@angular/core/testing'; -import {Json, StringWrapper} from '../../src/facade/lang'; - -import {Component} from '@angular/core'; import {JsonPipe} from '@angular/common'; +import {Component} from '@angular/core'; +import {TestComponentBuilder} from '@angular/core/testing'; +import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; +import {expect} from '@angular/platform-browser/testing/matchers'; + +import {Json, StringWrapper} from '../../src/facade/lang'; export function main() { describe('JsonPipe', () => { diff --git a/modules/@angular/common/test/pipes/number_pipe_spec.ts b/modules/@angular/common/test/pipes/number_pipe_spec.ts index 057ebb6bbc..bb26effe22 100644 --- a/modules/@angular/common/test/pipes/number_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/number_pipe_spec.ts @@ -6,11 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach,} from '@angular/core/testing/testing_internal'; +import {CurrencyPipe, DecimalPipe, PercentPipe} from '@angular/common'; +import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from '@angular/core/testing/testing_internal'; import {browserDetection} from '@angular/platform-browser/testing/browser_util'; -import {DecimalPipe, PercentPipe, CurrencyPipe} from '@angular/common'; - export function main() { describe('Number pipes', () => { // TODO(mlaval): enable tests when Intl API is no longer used, see diff --git a/modules/@angular/common/test/pipes/replace_pipe_spec.ts b/modules/@angular/common/test/pipes/replace_pipe_spec.ts index a3275dff85..892cb6d26c 100644 --- a/modules/@angular/common/test/pipes/replace_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/replace_pipe_spec.ts @@ -6,10 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ -import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, inject,} from '@angular/core/testing/testing_internal'; - import {ReplacePipe} from '@angular/common'; -import {StringJoiner} from '../../src/facade/lang'; +import {afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; export function main() { describe('ReplacePipe', () => { diff --git a/modules/@angular/common/test/pipes/slice_pipe_spec.ts b/modules/@angular/common/test/pipes/slice_pipe_spec.ts index bdd66db23a..8e5e406cc9 100644 --- a/modules/@angular/common/test/pipes/slice_pipe_spec.ts +++ b/modules/@angular/common/test/pipes/slice_pipe_spec.ts @@ -6,13 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, ddescribe, describe, it, iit, xit, beforeEach, afterEach, inject,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {TestComponentBuilder} from '@angular/core/testing'; -import {browserDetection} from '@angular/platform-browser/testing/browser_util'; - -import {Component} from '@angular/core'; import {SlicePipe} from '@angular/common'; +import {Component} from '@angular/core'; +import {TestComponentBuilder} from '@angular/core/testing'; +import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; +import {browserDetection} from '@angular/platform-browser/testing/browser_util'; +import {expect} from '@angular/platform-browser/testing/matchers'; export function main() { describe('SlicePipe', () => { diff --git a/modules/@angular/common/testing/location_mock.ts b/modules/@angular/common/testing/location_mock.ts index 831fb12162..5c423ebe6a 100644 --- a/modules/@angular/common/testing/location_mock.ts +++ b/modules/@angular/common/testing/location_mock.ts @@ -9,7 +9,6 @@ import {EventEmitter, Injectable} from '@angular/core'; import {Location} from '../index'; -import {ObservableWrapper} from '../src/facade/async'; import {LocationStrategy} from '../src/location/location_strategy'; @@ -46,15 +45,13 @@ export class SpyLocation implements Location { return currPath == givenPath + (query.length > 0 ? ('?' + query) : ''); } - simulateUrlPop(pathname: string) { - ObservableWrapper.callEmit(this._subject, {'url': pathname, 'pop': true}); - } + simulateUrlPop(pathname: string) { this._subject.emit({'url': pathname, 'pop': true}); } simulateHashChange(pathname: string) { // Because we don't prevent the native event, the browser will independently update the path this.setInitialPath(pathname); this.urlChanges.push('hash: ' + pathname); - ObservableWrapper.callEmit(this._subject, {'url': pathname, 'pop': true, 'type': 'hashchange'}); + this._subject.emit({'url': pathname, 'pop': true, 'type': 'hashchange'}); } prepareExternalUrl(url: string): string { @@ -100,21 +97,21 @@ export class SpyLocation implements Location { forward() { if (this._historyIndex < (this._history.length - 1)) { this._historyIndex++; - ObservableWrapper.callEmit(this._subject, {'url': this.path(), 'pop': true}); + this._subject.emit({'url': this.path(), 'pop': true}); } } back() { if (this._historyIndex > 0) { this._historyIndex--; - ObservableWrapper.callEmit(this._subject, {'url': this.path(), 'pop': true}); + this._subject.emit({'url': this.path(), 'pop': true}); } } subscribe( onNext: (value: any) => void, onThrow: (error: any) => void = null, onReturn: () => void = null): Object { - return ObservableWrapper.subscribe(this._subject, onNext, onThrow, onReturn); + return this._subject.subscribe({next: onNext, error: onThrow, complete: onReturn}); } normalize(url: string): string { return null; } diff --git a/modules/@angular/common/testing/mock_location_strategy.ts b/modules/@angular/common/testing/mock_location_strategy.ts index b2dc6d4dcf..38189a229b 100644 --- a/modules/@angular/common/testing/mock_location_strategy.ts +++ b/modules/@angular/common/testing/mock_location_strategy.ts @@ -9,7 +9,7 @@ import {Injectable} from '@angular/core'; import {LocationStrategy} from '../index'; -import {EventEmitter, ObservableWrapper} from '../src/facade/async'; +import {EventEmitter} from '../src/facade/async'; @@ -31,7 +31,7 @@ export class MockLocationStrategy extends LocationStrategy { simulatePopState(url: string): void { this.internalPath = url; - ObservableWrapper.callEmit(this._subject, new _MockPopStateEvent(this.path())); + this._subject.emit(new _MockPopStateEvent(this.path())); } path(includeHash: boolean = false): string { return this.internalPath; } @@ -63,7 +63,7 @@ export class MockLocationStrategy extends LocationStrategy { this.urlChanges.push('replace: ' + externalUrl); } - onPopState(fn: (value: any) => void): void { ObservableWrapper.subscribe(this._subject, fn); } + onPopState(fn: (value: any) => void): void { this._subject.subscribe({next: fn}); } getBaseHref(): string { return this.internalBaseHref; } diff --git a/modules/@angular/compiler/src/html_parser/parser.ts b/modules/@angular/compiler/src/html_parser/parser.ts index 0e9ffe599a..f875aa4996 100644 --- a/modules/@angular/compiler/src/html_parser/parser.ts +++ b/modules/@angular/compiler/src/html_parser/parser.ts @@ -6,13 +6,14 @@ * found in the LICENSE file at https://angular.io/license */ -import {isPresent, isBlank,} from '../facade/lang'; import {ListWrapper} from '../facade/collection'; +import {isBlank, isPresent} from '../facade/lang'; +import {ParseError, ParseSourceSpan} from '../parse_util'; + import * as html from './ast'; -import * as lex from './lexer'; -import {ParseSourceSpan, ParseError} from '../parse_util'; -import {TagDefinition, getNsPrefix, mergeNsAndName} from './tags'; import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from './interpolation_config'; +import * as lex from './lexer'; +import {TagDefinition, getNsPrefix, mergeNsAndName} from './tags'; export class TreeError extends ParseError { static create(elementName: string, span: ParseSourceSpan, msg: string): TreeError { diff --git a/modules/@angular/compiler/src/lifecycle_reflector.ts b/modules/@angular/compiler/src/lifecycle_reflector.ts index 783c32b5ba..a4716562a9 100644 --- a/modules/@angular/compiler/src/lifecycle_reflector.ts +++ b/modules/@angular/compiler/src/lifecycle_reflector.ts @@ -6,11 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ -import {OnInit, OnDestroy, DoCheck, OnChanges, AfterContentInit, AfterContentChecked, AfterViewInit, AfterViewChecked,} from '@angular/core'; -import {reflector, LifecycleHooks} from '../core_private'; +import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnDestroy, OnInit} from '@angular/core'; + +import {LifecycleHooks, reflector} from '../core_private'; -import {Type} from './facade/lang'; import {MapWrapper} from './facade/collection'; +import {Type} from './facade/lang'; const LIFECYCLE_INTERFACES: Map = MapWrapper.createFromPairs([ [LifecycleHooks.OnInit, OnInit], diff --git a/modules/@angular/compiler/src/output/output_interpreter.ts b/modules/@angular/compiler/src/output/output_interpreter.ts index 7c251b2ae0..715e78890d 100644 --- a/modules/@angular/compiler/src/output/output_interpreter.ts +++ b/modules/@angular/compiler/src/output/output_interpreter.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import {ObservableWrapper} from '../facade/async'; import {ListWrapper} from '../facade/collection'; import {BaseException, unimplemented} from '../facade/exceptions'; import {isPresent} from '../facade/lang'; @@ -157,7 +156,7 @@ class StatementInterpreter implements o.StatementVisitor, o.ExpressionVisitor { result = ListWrapper.concat(receiver, args[0]); break; case o.BuiltinMethod.SubscribeObservable: - result = ObservableWrapper.subscribe(receiver, args[0]); + result = receiver.subscribe({next: args[0]}); break; case o.BuiltinMethod.bind: result = receiver.bind(args[0]); diff --git a/modules/@angular/compiler/src/output/output_jit.ts b/modules/@angular/compiler/src/output/output_jit.ts index 55073aa034..67b517af05 100644 --- a/modules/@angular/compiler/src/output/output_jit.ts +++ b/modules/@angular/compiler/src/output/output_jit.ts @@ -6,11 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ -import {isPresent, evalExpression,} from '../facade/lang'; -import * as o from './output_ast'; +import {evalExpression, isPresent} from '../facade/lang'; +import {sanitizeIdentifier} from '../util'; + import {EmitterVisitorContext} from './abstract_emitter'; import {AbstractJsEmitterVisitor} from './abstract_js_emitter'; -import {sanitizeIdentifier} from '../util'; +import * as o from './output_ast'; export function jitStatements( sourceUrl: string, statements: o.Statement[], resultVar: string): any { diff --git a/modules/@angular/compiler/src/runtime_compiler.ts b/modules/@angular/compiler/src/runtime_compiler.ts index e2588cd674..d41b28544d 100644 --- a/modules/@angular/compiler/src/runtime_compiler.ts +++ b/modules/@angular/compiler/src/runtime_compiler.ts @@ -13,7 +13,6 @@ import {Console} from '../core_private'; import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompilePipeMetadata, createHostComponentMeta} from './compile_metadata'; import {CompilerConfig} from './config'; import {DirectiveNormalizer} from './directive_normalizer'; -import {PromiseWrapper} from './facade/async'; import {BaseException} from './facade/exceptions'; import {ConcreteType, Type, isBlank, isString, stringify} from './facade/lang'; import {CompileMetadataResolver} from './metadata_resolver'; @@ -426,8 +425,8 @@ class ModuleBoundCompiler implements Compiler, ComponentResolver { if (this._parentComponentResolver) { return this._parentComponentResolver.resolveComponent(component); } else { - return PromiseWrapper.reject( - new BaseException(`Cannot resolve component using '${component}'.`), null); + return >Promise.reject( + new BaseException(`Cannot resolve component using '${component}'.`)); } } if (this._warnOnComponentResolver) { diff --git a/modules/@angular/compiler/src/template_parser/template_ast.ts b/modules/@angular/compiler/src/template_parser/template_ast.ts index 1a7f3312a8..aad1d61d84 100644 --- a/modules/@angular/compiler/src/template_parser/template_ast.ts +++ b/modules/@angular/compiler/src/template_parser/template_ast.ts @@ -6,13 +6,14 @@ * found in the LICENSE file at https://angular.io/license */ +import {SecurityContext} from '@angular/core'; + +import {LifecycleHooks} from '../../core_private'; +import {CompileDirectiveMetadata, CompileProviderMetadata, CompileTokenMetadata} from '../compile_metadata'; import {AST} from '../expression_parser/ast'; import {isPresent} from '../facade/lang'; - -import {CompileDirectiveMetadata, CompileTokenMetadata, CompileProviderMetadata,} from '../compile_metadata'; import {ParseSourceSpan} from '../parse_util'; -import {SecurityContext} from '@angular/core'; -import {LifecycleHooks} from '../../core_private'; + /** * An Abstract Syntax Tree node representing part of a parsed Angular template. diff --git a/modules/@angular/compiler/src/template_parser/template_parser.ts b/modules/@angular/compiler/src/template_parser/template_parser.ts index af98daff97..f9c55e535c 100644 --- a/modules/@angular/compiler/src/template_parser/template_parser.ts +++ b/modules/@angular/compiler/src/template_parser/template_parser.ts @@ -7,28 +7,30 @@ */ import {Inject, Injectable, OpaqueToken, Optional, SchemaMetadata, SecurityContext} from '@angular/core'; -import {Console, MAX_INTERPOLATION_VALUES} from '../../core_private'; -import {ListWrapper, StringMapWrapper, SetWrapper,} from '../facade/collection'; -import {isPresent, isBlank} from '../facade/lang'; -import {BaseException} from '../facade/exceptions'; -import {EmptyExpr, AST, Interpolation, ASTWithSource, TemplateBinding, RecursiveAstVisitor, BindingPipe, ParserError} from '../expression_parser/ast'; +import {Console, MAX_INTERPOLATION_VALUES} from '../../core_private'; +import {CompileDirectiveMetadata, CompilePipeMetadata, CompileTokenMetadata, removeIdentifierDuplicates} from '../compile_metadata'; +import {AST, ASTWithSource, BindingPipe, EmptyExpr, Interpolation, ParserError, RecursiveAstVisitor, TemplateBinding} from '../expression_parser/ast'; import {Parser} from '../expression_parser/parser'; -import {CompileDirectiveMetadata, CompilePipeMetadata, CompileTokenMetadata, removeIdentifierDuplicates,} from '../compile_metadata'; -import {HtmlParser, ParseTreeResult} from '../html_parser/html_parser'; -import {splitNsName, mergeNsAndName} from '../html_parser/tags'; -import {ParseSourceSpan, ParseError, ParseErrorLevel} from '../parse_util'; -import {InterpolationConfig} from '../html_parser/interpolation_config'; -import {ElementAst, BoundElementPropertyAst, BoundEventAst, ReferenceAst, TemplateAst, TemplateAstVisitor, templateVisitAll, TextAst, BoundTextAst, EmbeddedTemplateAst, AttrAst, NgContentAst, PropertyBindingType, DirectiveAst, BoundDirectivePropertyAst, VariableAst} from './template_ast'; -import {CssSelector, SelectorMatcher} from '../selector'; -import {ElementSchemaRegistry} from '../schema/element_schema_registry'; -import {preparseElement, PreparsedElementType} from './template_preparser'; -import {isStyleUrlResolvable} from '../style_url_resolver'; +import {ListWrapper, SetWrapper, StringMapWrapper} from '../facade/collection'; +import {BaseException} from '../facade/exceptions'; +import {isBlank, isPresent} from '../facade/lang'; import * as html from '../html_parser/ast'; -import {splitAtColon} from '../util'; -import {identifierToken, Identifiers} from '../identifiers'; +import {HtmlParser, ParseTreeResult} from '../html_parser/html_parser'; import {expandNodes} from '../html_parser/icu_ast_expander'; +import {InterpolationConfig} from '../html_parser/interpolation_config'; +import {mergeNsAndName, splitNsName} from '../html_parser/tags'; +import {Identifiers, identifierToken} from '../identifiers'; +import {ParseError, ParseErrorLevel, ParseSourceSpan} from '../parse_util'; import {ProviderElementContext, ProviderViewContext} from '../provider_analyzer'; +import {ElementSchemaRegistry} from '../schema/element_schema_registry'; +import {CssSelector, SelectorMatcher} from '../selector'; +import {isStyleUrlResolvable} from '../style_url_resolver'; +import {splitAtColon} from '../util'; + +import {AttrAst, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventAst, BoundTextAst, DirectiveAst, ElementAst, EmbeddedTemplateAst, NgContentAst, PropertyBindingType, ReferenceAst, TemplateAst, TemplateAstVisitor, TextAst, VariableAst, templateVisitAll} from './template_ast'; +import {PreparsedElementType, preparseElement} from './template_preparser'; + // Group 1 = "bind-" // Group 2 = "var-" diff --git a/modules/@angular/compiler/src/view_compiler/compile_element.ts b/modules/@angular/compiler/src/view_compiler/compile_element.ts index b0596ad630..5707aa1b35 100644 --- a/modules/@angular/compiler/src/view_compiler/compile_element.ts +++ b/modules/@angular/compiler/src/view_compiler/compile_element.ts @@ -8,21 +8,20 @@ import {BaseException} from '@angular/core'; +import {CompileDiDependencyMetadata, CompileDirectiveMetadata, CompileIdentifierMap, CompileIdentifierMetadata, CompileProviderMetadata, CompileQueryMetadata, CompileTokenMetadata} from '../compile_metadata'; import {ListWrapper, StringMapWrapper} from '../facade/collection'; import {isBlank, isPresent} from '../facade/lang'; import {Identifiers, identifierToken} from '../identifiers'; import * as o from '../output/output_ast'; import {convertValueToOutputAst} from '../output/value_util'; import {ProviderAst, ProviderAstType, ReferenceAst, TemplateAst} from '../template_parser/template_ast'; +import {createDiTokenExpression} from '../util'; +import {CompileMethod} from './compile_method'; +import {CompileQuery, addQueryToTokenMap, createQueryList} from './compile_query'; import {CompileView} from './compile_view'; import {InjectMethodVars} from './constants'; - -import {CompileIdentifierMap, CompileDirectiveMetadata, CompileTokenMetadata, CompileQueryMetadata, CompileProviderMetadata, CompileDiDependencyMetadata, CompileIdentifierMetadata,} from '../compile_metadata'; import {getPropertyInView, injectFromViewParentInjector} from './util'; -import {CompileQuery, createQueryList, addQueryToTokenMap} from './compile_query'; -import {CompileMethod} from './compile_method'; -import {createDiTokenExpression} from '../util'; export class CompileNode { constructor( diff --git a/modules/@angular/compiler/src/view_compiler/property_binder.ts b/modules/@angular/compiler/src/view_compiler/property_binder.ts index 0876e3b7ee..9abf817d76 100644 --- a/modules/@angular/compiler/src/view_compiler/property_binder.ts +++ b/modules/@angular/compiler/src/view_compiler/property_binder.ts @@ -6,20 +6,22 @@ * found in the LICENSE file at https://angular.io/license */ +import {SecurityContext} from '@angular/core'; + import {EMPTY_STATE as EMPTY_ANIMATION_STATE, LifecycleHooks, isDefaultChangeDetectionStrategy} from '../../core_private'; import * as cdAst from '../expression_parser/ast'; import {isBlank, isPresent} from '../facade/lang'; import {Identifiers} from '../identifiers'; import * as o from '../output/output_ast'; -import {DetectChangesVars, ViewProperties} from './constants'; -import {BoundTextAst, BoundElementPropertyAst, DirectiveAst, PropertyBindingType,} from '../template_parser/template_ast'; -import {CompileView} from './compile_view'; +import {BoundElementPropertyAst, BoundTextAst, DirectiveAst, PropertyBindingType} from '../template_parser/template_ast'; +import {camelCaseToDashCase} from '../util'; + +import {CompileBinding} from './compile_binding'; import {CompileElement, CompileNode} from './compile_element'; import {CompileMethod} from './compile_method'; -import {camelCaseToDashCase} from '../util'; +import {CompileView} from './compile_view'; +import {DetectChangesVars, ViewProperties} from './constants'; import {convertCdExpressionToIr} from './expression_converter'; -import {CompileBinding} from './compile_binding'; -import {SecurityContext} from '@angular/core'; function createBindFieldExpr(exprIndex: number): o.ReadPropExpr { return o.THIS_EXPR.prop(`_expr_${exprIndex}`); diff --git a/modules/@angular/compiler/src/view_compiler/util.ts b/modules/@angular/compiler/src/view_compiler/util.ts index 2421c35784..ad256513dc 100644 --- a/modules/@angular/compiler/src/view_compiler/util.ts +++ b/modules/@angular/compiler/src/view_compiler/util.ts @@ -6,15 +6,15 @@ * found in the LICENSE file at https://angular.io/license */ +import {CompileDirectiveMetadata, CompileTokenMetadata} from '../compile_metadata'; import {BaseException} from '../facade/exceptions'; import {isBlank, isPresent} from '../facade/lang'; -import * as o from '../output/output_ast'; - -import {CompileTokenMetadata, CompileDirectiveMetadata,} from '../compile_metadata'; -import {CompileView} from './compile_view'; import {Identifiers} from '../identifiers'; +import * as o from '../output/output_ast'; import {createDiTokenExpression} from '../util'; +import {CompileView} from './compile_view'; + export function getPropertyInView( property: o.Expression, callingView: CompileView, definedView: CompileView): o.Expression { if (callingView === definedView) { diff --git a/modules/@angular/compiler/src/view_compiler/view_binder.ts b/modules/@angular/compiler/src/view_compiler/view_binder.ts index b10fdf03ce..a099eb3733 100644 --- a/modules/@angular/compiler/src/view_compiler/view_binder.ts +++ b/modules/@angular/compiler/src/view_compiler/view_binder.ts @@ -6,14 +6,15 @@ * found in the LICENSE file at https://angular.io/license */ -import {ListWrapper,} from '../facade/collection'; -import {TemplateAst, TemplateAstVisitor, NgContentAst, EmbeddedTemplateAst, ElementAst, ReferenceAst, VariableAst, BoundEventAst, BoundElementPropertyAst, AttrAst, BoundTextAst, TextAst, DirectiveAst, BoundDirectivePropertyAst, templateVisitAll,} from '../template_parser/template_ast'; -import {bindRenderText, bindRenderInputs, bindDirectiveInputs, bindDirectiveHostProps} from './property_binder'; -import {bindRenderOutputs, collectEventListeners, bindDirectiveOutputs} from './event_binder'; -import {bindDirectiveAfterContentLifecycleCallbacks, bindDirectiveAfterViewLifecycleCallbacks, bindInjectableDestroyLifecycleCallbacks, bindPipeDestroyLifecycleCallbacks, bindDirectiveDetectChangesLifecycleCallbacks} from './lifecycle_binder'; -import {CompileView} from './compile_view'; -import {CompileElement, CompileNode} from './compile_element'; +import {ListWrapper} from '../facade/collection'; import {identifierToken} from '../identifiers'; +import {AttrAst, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventAst, BoundTextAst, DirectiveAst, ElementAst, EmbeddedTemplateAst, NgContentAst, ReferenceAst, TemplateAst, TemplateAstVisitor, TextAst, VariableAst, templateVisitAll} from '../template_parser/template_ast'; + +import {CompileElement, CompileNode} from './compile_element'; +import {CompileView} from './compile_view'; +import {bindDirectiveOutputs, bindRenderOutputs, collectEventListeners} from './event_binder'; +import {bindDirectiveAfterContentLifecycleCallbacks, bindDirectiveAfterViewLifecycleCallbacks, bindDirectiveDetectChangesLifecycleCallbacks, bindInjectableDestroyLifecycleCallbacks, bindPipeDestroyLifecycleCallbacks} from './lifecycle_binder'; +import {bindDirectiveHostProps, bindDirectiveInputs, bindRenderInputs, bindRenderText} from './property_binder'; export function bindView(view: CompileView, parsedTemplate: TemplateAst[]): void { var visitor = new ViewBinderVisitor(view); diff --git a/modules/@angular/compiler/test/directive_lifecycle_spec.ts b/modules/@angular/compiler/test/directive_lifecycle_spec.ts index 8dbb69c17f..cc96e77dfe 100644 --- a/modules/@angular/compiler/test/directive_lifecycle_spec.ts +++ b/modules/@angular/compiler/test/directive_lifecycle_spec.ts @@ -6,10 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -import {beforeEach, xdescribe, ddescribe, describe, expect, iit, inject, it,} from '@angular/core/testing/testing_internal'; - import {hasLifecycleHook} from '@angular/compiler/src/lifecycle_reflector'; import {LifecycleHooks} from '@angular/core/src/metadata/lifecycle_hooks'; +import {beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe} from '@angular/core/testing/testing_internal'; export function main() { describe('Create DirectiveMetadata', () => { diff --git a/modules/@angular/compiler/test/directive_resolver_mock_spec.ts b/modules/@angular/compiler/test/directive_resolver_mock_spec.ts index 7f14f05dbb..b1e50a317d 100644 --- a/modules/@angular/compiler/test/directive_resolver_mock_spec.ts +++ b/modules/@angular/compiler/test/directive_resolver_mock_spec.ts @@ -6,11 +6,11 @@ * found in the LICENSE file at https://angular.io/license */ -import {beforeEach, ddescribe, describe, expect, iit, it, inject,} from '@angular/core/testing/testing_internal'; +import {Component, ComponentMetadata, Injector, ViewMetadata} from '@angular/core'; +import {beforeEach, ddescribe, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal'; -import {stringify, isBlank} from '../src/facade/lang'; +import {isBlank, stringify} from '../src/facade/lang'; import {MockDirectiveResolver} from '../testing'; -import {Component, ViewMetadata, Injector, ComponentMetadata} from '@angular/core'; export function main() { describe('MockDirectiveResolver', () => { diff --git a/modules/@angular/compiler/test/ng_module_resolver_mock_spec.ts b/modules/@angular/compiler/test/ng_module_resolver_mock_spec.ts index b1b2f88f95..3929a28bd7 100644 --- a/modules/@angular/compiler/test/ng_module_resolver_mock_spec.ts +++ b/modules/@angular/compiler/test/ng_module_resolver_mock_spec.ts @@ -6,11 +6,11 @@ * found in the LICENSE file at https://angular.io/license */ -import {beforeEach, ddescribe, describe, expect, iit, it, inject,} from '@angular/core/testing/testing_internal'; +import {Injector, NgModule, NgModuleMetadata} from '@angular/core'; +import {beforeEach, ddescribe, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal'; -import {stringify, isBlank} from '../src/facade/lang'; +import {isBlank, stringify} from '../src/facade/lang'; import {MockNgModuleResolver} from '../testing'; -import {NgModule, NgModuleMetadata, Injector} from '@angular/core'; export function main() { describe('MockNgModuleResolver', () => { diff --git a/modules/@angular/compiler/test/output/abstract_emitter_spec.ts b/modules/@angular/compiler/test/output/abstract_emitter_spec.ts index 16e688d466..d64edde3c5 100644 --- a/modules/@angular/compiler/test/output/abstract_emitter_spec.ts +++ b/modules/@angular/compiler/test/output/abstract_emitter_spec.ts @@ -6,9 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ -import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; - import {escapeSingleQuoteString} from '@angular/compiler/src/output/abstract_emitter'; +import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; export function main() { describe('AbstractEmitter', () => { diff --git a/modules/@angular/compiler/test/output/js_emitter_spec.ts b/modules/@angular/compiler/test/output/js_emitter_spec.ts index c023152bbc..045170054d 100644 --- a/modules/@angular/compiler/test/output/js_emitter_spec.ts +++ b/modules/@angular/compiler/test/output/js_emitter_spec.ts @@ -6,12 +6,13 @@ * found in the LICENSE file at https://angular.io/license */ -import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; +import {CompileIdentifierMetadata} from '@angular/compiler/src/compile_metadata'; +import {JavaScriptEmitter} from '@angular/compiler/src/output/js_emitter'; +import * as o from '@angular/compiler/src/output/output_ast'; +import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; import {isBlank} from '../../src/facade/lang'; -import {JavaScriptEmitter} from '@angular/compiler/src/output/js_emitter'; -import {CompileIdentifierMetadata} from '@angular/compiler/src/compile_metadata'; -import * as o from '@angular/compiler/src/output/output_ast'; + import {SimpleJsImportGenerator} from './output_emitter_util'; var someModuleUrl = 'asset:somePackage/lib/somePath'; diff --git a/modules/@angular/compiler/test/output/output_emitter_spec.ts b/modules/@angular/compiler/test/output/output_emitter_spec.ts index 8c5ce64cee..8a8f440dde 100644 --- a/modules/@angular/compiler/test/output/output_emitter_spec.ts +++ b/modules/@angular/compiler/test/output/output_emitter_spec.ts @@ -6,18 +6,18 @@ * found in the LICENSE file at https://angular.io/license */ -import {beforeEach, ddescribe, describe, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; +import {interpretStatements} from '@angular/compiler/src/output/output_interpreter'; +import {jitStatements} from '@angular/compiler/src/output/output_jit'; +import {BaseException, EventEmitter} from '@angular/core'; +import {ViewType} from '@angular/core/src/linker/view_type'; +import {beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; +import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; +import {browserDetection} from '@angular/platform-browser/testing/browser_util'; import {expect} from '@angular/platform-browser/testing/matchers'; import * as typed from './output_emitter_codegen_typed'; import * as untyped from './output_emitter_codegen_untyped'; -import {jitStatements} from '@angular/compiler/src/output/output_jit'; -import {interpretStatements} from '@angular/compiler/src/output/output_interpreter'; -import {codegenStmts, ExternalClass} from './output_emitter_util'; -import {BaseException, EventEmitter} from '@angular/core'; -import {ViewType} from '@angular/core/src/linker/view_type'; -import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; -import {browserDetection} from '@angular/platform-browser/testing/browser_util'; +import {ExternalClass, codegenStmts} from './output_emitter_util'; export function main() { var outputDefs: any[] /** TODO #9100 */ = []; diff --git a/modules/@angular/compiler/test/output/ts_emitter_spec.ts b/modules/@angular/compiler/test/output/ts_emitter_spec.ts index d21e8abc8e..158fb06999 100644 --- a/modules/@angular/compiler/test/output/ts_emitter_spec.ts +++ b/modules/@angular/compiler/test/output/ts_emitter_spec.ts @@ -6,12 +6,13 @@ * found in the LICENSE file at https://angular.io/license */ -import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; - -import {isBlank} from '../../src/facade/lang'; -import {TypeScriptEmitter} from '@angular/compiler/src/output/ts_emitter'; import {CompileIdentifierMetadata} from '@angular/compiler/src/compile_metadata'; import * as o from '@angular/compiler/src/output/output_ast'; +import {TypeScriptEmitter} from '@angular/compiler/src/output/ts_emitter'; +import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; + +import {isBlank} from '../../src/facade/lang'; + import {SimpleJsImportGenerator} from './output_emitter_util'; var someModuleUrl = 'asset:somePackage/lib/somePath'; diff --git a/modules/@angular/compiler/test/pipe_resolver_mock_spec.ts b/modules/@angular/compiler/test/pipe_resolver_mock_spec.ts index ff40b096e9..03104cdd61 100644 --- a/modules/@angular/compiler/test/pipe_resolver_mock_spec.ts +++ b/modules/@angular/compiler/test/pipe_resolver_mock_spec.ts @@ -6,11 +6,11 @@ * found in the LICENSE file at https://angular.io/license */ -import {beforeEach, ddescribe, describe, expect, iit, it, inject,} from '@angular/core/testing/testing_internal'; +import {Injector, Pipe, PipeMetadata} from '@angular/core'; +import {beforeEach, ddescribe, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal'; -import {stringify, isBlank} from '../src/facade/lang'; +import {isBlank, stringify} from '../src/facade/lang'; import {MockPipeResolver} from '../testing'; -import {Pipe, PipeMetadata, Injector} from '@angular/core'; export function main() { describe('MockPipeResolver', () => { diff --git a/modules/@angular/compiler/test/runtime_compiler_spec.ts b/modules/@angular/compiler/test/runtime_compiler_spec.ts index c48ef70861..e8d8d0f3d0 100644 --- a/modules/@angular/compiler/test/runtime_compiler_spec.ts +++ b/modules/@angular/compiler/test/runtime_compiler_spec.ts @@ -6,13 +6,14 @@ * found in the LICENSE file at https://angular.io/license */ -import {beforeEach, ddescribe, xdescribe, describe, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {Injectable, Component, Input, ViewMetadata, Compiler, ComponentFactory, Injector, NgModule, NgModuleFactory} from '@angular/core'; -import {ConcreteType, stringify} from '../src/facade/lang'; -import {fakeAsync, tick, TestComponentBuilder, ComponentFixture, TestBed} from '@angular/core/testing'; -import {XHR, DirectiveResolver} from '@angular/compiler'; +import {DirectiveResolver, XHR} from '@angular/compiler'; import {MockDirectiveResolver} from '@angular/compiler/testing'; +import {Compiler, Component, ComponentFactory, Injectable, Injector, Input, NgModule, NgModuleFactory, ViewMetadata} from '@angular/core'; +import {ComponentFixture, TestBed, TestComponentBuilder, fakeAsync, tick} from '@angular/core/testing'; +import {beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; +import {expect} from '@angular/platform-browser/testing/matchers'; + +import {ConcreteType, stringify} from '../src/facade/lang'; import {SpyXHR} from './spies'; diff --git a/modules/@angular/compiler/test/shadow_css_spec.ts b/modules/@angular/compiler/test/shadow_css_spec.ts index 7cdfe2d5ed..a3a57e5ca4 100644 --- a/modules/@angular/compiler/test/shadow_css_spec.ts +++ b/modules/@angular/compiler/test/shadow_css_spec.ts @@ -6,11 +6,11 @@ * found in the LICENSE file at https://angular.io/license */ -import {describe, beforeEach, it, expect, ddescribe, iit,} from '@angular/core/testing/testing_internal'; -import {ShadowCss, processRules, CssRule} from '@angular/compiler/src/shadow_css'; +import {CssRule, ShadowCss, processRules} from '@angular/compiler/src/shadow_css'; +import {beforeEach, ddescribe, describe, expect, iit, it} from '@angular/core/testing/testing_internal'; +import {normalizeCSS} from '@angular/platform-browser/testing/browser_util'; import {StringWrapper, isPresent} from '../src/facade/lang'; -import {normalizeCSS} from '@angular/platform-browser/testing/browser_util'; export function main() { describe('ShadowCss', function() { diff --git a/modules/@angular/compiler/test/test_component_builder_spec.ts b/modules/@angular/compiler/test/test_component_builder_spec.ts index e0a417968d..662f06d9d6 100644 --- a/modules/@angular/compiler/test/test_component_builder_spec.ts +++ b/modules/@angular/compiler/test/test_component_builder_spec.ts @@ -6,14 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {TestComponentBuilder, ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, withProviders} from '@angular/core/testing'; -import {Injectable, Component, Input, ViewMetadata, Pipe, NgModule} from '@angular/core'; import {NgIf} from '@angular/common'; -import {TimerWrapper} from '../src/facade/async'; -import {PromiseWrapper} from '../src/facade/promise'; +import {Component, Injectable, Input, NgModule, Pipe, ViewMetadata} from '@angular/core'; +import {ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, TestComponentBuilder, withProviders} from '@angular/core/testing'; +import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; import {dispatchEvent} from '@angular/platform-browser/testing/browser_util'; +import {expect} from '@angular/platform-browser/testing/matchers'; @Component( {selector: 'child-comp', template: `Original {{childBinding}}`, directives: []}) @@ -80,7 +78,7 @@ class AsyncComp { text: string = '1'; click() { - PromiseWrapper.resolve(null).then((_) => { this.text += '1'; }); + Promise.resolve(null).then((_) => { this.text += '1'; }); } } @@ -90,7 +88,7 @@ class AsyncChildComp { @Input() set text(value: string) { - PromiseWrapper.resolve(null).then((_) => { this.localText = value; }); + Promise.resolve(null).then((_) => { this.localText = value; }); } } @@ -110,7 +108,7 @@ class AsyncTimeoutComp { text: string = '1'; click() { - TimerWrapper.setTimeout(() => { this.text += '1'; }, 10); + setTimeout(() => { this.text += '1'; }, 10); } } @@ -120,8 +118,7 @@ class NestedAsyncTimeoutComp { text: string = '1'; click() { - TimerWrapper.setTimeout( - () => { TimerWrapper.setTimeout(() => { this.text += '1'; }, 10); }, 10); + setTimeout(() => { setTimeout(() => { this.text += '1'; }, 10); }, 10); } } diff --git a/modules/@angular/compiler/test/xhr_mock_spec.ts b/modules/@angular/compiler/test/xhr_mock_spec.ts index 7732c0d679..b7257c1d1e 100644 --- a/modules/@angular/compiler/test/xhr_mock_spec.ts +++ b/modules/@angular/compiler/test/xhr_mock_spec.ts @@ -6,9 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it,} from '@angular/core/testing/testing_internal'; import {MockXHR} from '@angular/compiler/testing/xhr_mock'; -import {PromiseWrapper} from '../src/facade/async'; +import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal'; import {isPresent} from '../src/facade/lang'; export function main() { @@ -39,7 +38,7 @@ export function main() { return error; } - PromiseWrapper.then(request, onResponse, onError); + request.then(onResponse, onError); } it('should return a response from the definitions', diff --git a/modules/@angular/compiler/testing/xhr_mock.ts b/modules/@angular/compiler/testing/xhr_mock.ts index ceac5a9b03..80b7463923 100644 --- a/modules/@angular/compiler/testing/xhr_mock.ts +++ b/modules/@angular/compiler/testing/xhr_mock.ts @@ -9,7 +9,6 @@ import {BaseException} from '@angular/core'; import {XHR} from '../index'; -import {PromiseCompleter, PromiseWrapper} from '../src/facade/async'; import {ListWrapper, Map} from '../src/facade/collection'; import {isBlank, normalizeBlank} from '../src/facade/lang'; @@ -103,19 +102,26 @@ export class MockXHR extends XHR { } class _PendingRequest { - completer: PromiseCompleter; + resolve: (result: string) => void; + reject: (error: any) => void; + promise: Promise; - constructor(public url: string) { this.completer = PromiseWrapper.completer(); } + constructor(public url: string) { + this.promise = new Promise((res, rej) => { + this.resolve = res; + this.reject = rej; + }); + } complete(response: string) { if (isBlank(response)) { - this.completer.reject(`Failed to load ${this.url}`, null); + this.reject(`Failed to load ${this.url}`); } else { - this.completer.resolve(response); + this.resolve(response); } } - getPromise(): Promise { return this.completer.promise; } + getPromise(): Promise { return this.promise; } } class _Expectation { diff --git a/modules/@angular/core/src/application_ref.ts b/modules/@angular/core/src/application_ref.ts index 605f86fb1d..3db09c8523 100644 --- a/modules/@angular/core/src/application_ref.ts +++ b/modules/@angular/core/src/application_ref.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import {ObservableWrapper, PromiseCompleter, PromiseWrapper} from '../src/facade/async'; import {ListWrapper} from '../src/facade/collection'; import {BaseException, ExceptionHandler, unimplemented} from '../src/facade/exceptions'; import {ConcreteType, Type, isBlank, isPresent, isPromise, stringify} from '../src/facade/lang'; @@ -356,8 +355,8 @@ export class PlatformRef_ extends PlatformRef { throw new Error('No ExceptionHandler. Is platform module (BrowserModule) included?'); } moduleRef.onDestroy(() => ListWrapper.remove(this._modules, moduleRef)); - ObservableWrapper.subscribe(ngZone.onError, (error: NgZoneError) => { - exceptionHandler.call(error.error, error.stackTrace); + ngZone.onError.subscribe({ + next: (error: NgZoneError) => { exceptionHandler.call(error.error, error.stackTrace); } }); return _callAndReportToExceptionHandler(exceptionHandler, () => { const initStatus: ApplicationInitStatus = moduleRef.injector.get(ApplicationInitStatus); @@ -519,8 +518,9 @@ export class ApplicationRef_ extends ApplicationRef { @Optional() private _testability: Testability) { super(); this._enforceNoNewChanges = isDevMode(); - ObservableWrapper.subscribe( - this._zone.onMicrotaskEmpty, (_) => { this._zone.run(() => { this.tick(); }); }); + + this._zone.onMicrotaskEmpty.subscribe( + {next: () => { this._zone.run(() => { this.tick(); }); }}); } /** diff --git a/modules/@angular/core/src/di/reflective_provider.ts b/modules/@angular/core/src/di/reflective_provider.ts index 0bef6e6c57..a89c8271f8 100644 --- a/modules/@angular/core/src/di/reflective_provider.ts +++ b/modules/@angular/core/src/di/reflective_provider.ts @@ -6,15 +6,17 @@ * found in the LICENSE file at https://angular.io/license */ -import {Type, isBlank, isPresent, isArray,} from '../facade/lang'; -import {MapWrapper, ListWrapper} from '../facade/collection'; +import {ListWrapper, MapWrapper} from '../facade/collection'; +import {Type, isArray, isBlank, isPresent} from '../facade/lang'; import {reflector} from '../reflection/reflection'; -import {ReflectiveKey} from './reflective_key'; -import {InjectMetadata, OptionalMetadata, SelfMetadata, HostMetadata, SkipSelfMetadata, DependencyMetadata} from './metadata'; -import {NoAnnotationError, MixingMultiProvidersWithRegularProvidersError, InvalidProviderError} from './reflective_exceptions'; + import {resolveForwardRef} from './forward_ref'; +import {DependencyMetadata, HostMetadata, InjectMetadata, OptionalMetadata, SelfMetadata, SkipSelfMetadata} from './metadata'; import {Provider, ProviderBuilder, provide} from './provider'; -import {isProviderLiteral, createProvider} from './provider_util'; +import {createProvider, isProviderLiteral} from './provider_util'; +import {InvalidProviderError, MixingMultiProvidersWithRegularProvidersError, NoAnnotationError} from './reflective_exceptions'; +import {ReflectiveKey} from './reflective_key'; + /** * `Dependency` is used by the framework to extend DI. diff --git a/modules/@angular/core/src/linker/view.ts b/modules/@angular/core/src/linker/view.ts index 4f353d59c2..9f2574e656 100644 --- a/modules/@angular/core/src/linker/view.ts +++ b/modules/@angular/core/src/linker/view.ts @@ -6,23 +6,23 @@ * found in the LICENSE file at https://angular.io/license */ -import {ObservableWrapper} from '../facade/async'; +import {AnimationGroupPlayer} from '../animation/animation_group_player'; +import {AnimationPlayer} from '../animation/animation_player'; +import {ViewAnimationMap} from '../animation/view_animation_map'; +import {ChangeDetectorRef, ChangeDetectorStatus} from '../change_detection/change_detection'; +import {Injector} from '../di/injector'; import {ListWrapper} from '../facade/collection'; import {isPresent} from '../facade/lang'; +import {WtfScopeFn, wtfCreateScope, wtfLeave} from '../profile/profile'; import {RenderComponentType, RenderDebugInfo, Renderer} from '../render/api'; + +import {DebugContext, StaticNodeDebugInfo} from './debug_context'; import {AppElement} from './element'; +import {ElementInjector} from './element_injector'; +import {ExpressionChangedAfterItHasBeenCheckedException, ViewDestroyedException, ViewWrappedException} from './exceptions'; import {ViewRef_} from './view_ref'; import {ViewType} from './view_type'; import {ViewUtils, ensureSlotCount, flattenNestedViewRenderNodes} from './view_utils'; -import {ChangeDetectorRef, ChangeDetectorStatus,} from '../change_detection/change_detection'; -import {wtfCreateScope, wtfLeave, WtfScopeFn} from '../profile/profile'; -import {ExpressionChangedAfterItHasBeenCheckedException, ViewDestroyedException, ViewWrappedException} from './exceptions'; -import {StaticNodeDebugInfo, DebugContext} from './debug_context'; -import {ElementInjector} from './element_injector'; -import {Injector} from '../di/injector'; -import {AnimationPlayer} from '../animation/animation_player'; -import {AnimationGroupPlayer} from '../animation/animation_group_player'; -import {ViewAnimationMap} from '../animation/view_animation_map'; var _scope_check: WtfScopeFn = wtfCreateScope(`AppView#check(ascii id)`); @@ -196,7 +196,7 @@ export abstract class AppView { this.disposables[i](); } for (var i = 0; i < this.subscriptions.length; i++) { - ObservableWrapper.dispose(this.subscriptions[i]); + this.subscriptions[i].unsubscribe(); } this.destroyInternal(); this.dirtyParentQueriesInternal(); diff --git a/modules/@angular/core/src/metadata.ts b/modules/@angular/core/src/metadata.ts index d8c053e3aa..8694cb60c8 100644 --- a/modules/@angular/core/src/metadata.ts +++ b/modules/@angular/core/src/metadata.ts @@ -12,12 +12,14 @@ */ import {ChangeDetectionStrategy} from '../src/change_detection/change_detection'; +import {Type} from '../src/facade/lang'; import {AnimationEntryMetadata} from './animation/metadata'; import {AttributeMetadata, ContentChildMetadata, ContentChildrenMetadata, QueryMetadata, ViewChildMetadata, ViewChildrenMetadata, ViewQueryMetadata} from './metadata/di'; import {ComponentMetadata, ComponentMetadataType, DirectiveMetadata, DirectiveMetadataType, HostBindingMetadata, HostListenerMetadata, InputMetadata, OutputMetadata, PipeMetadata, PipeMetadataType} from './metadata/directives'; import {ModuleWithProviders, NgModuleMetadata, NgModuleMetadataType, SchemaMetadata} from './metadata/ng_module'; import {ViewEncapsulation} from './metadata/view'; +import {TypeDecorator, makeDecorator, makeParamDecorator, makePropDecorator} from './util/decorators'; export {ANALYZE_FOR_ENTRY_COMPONENTS, AttributeMetadata, ContentChildMetadata, ContentChildrenMetadata, QueryMetadata, ViewChildMetadata, ViewChildrenMetadata, ViewQueryMetadata} from './metadata/di'; export {ComponentMetadata, ComponentMetadataType, DirectiveMetadata, DirectiveMetadataType, HostBindingMetadata, HostListenerMetadata, InputMetadata, OutputMetadata, PipeMetadata, PipeMetadataType} from './metadata/directives'; @@ -25,8 +27,6 @@ export {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, export {CUSTOM_ELEMENTS_SCHEMA, ModuleWithProviders, NgModuleMetadata, NgModuleMetadataType, SchemaMetadata} from './metadata/ng_module'; export {ViewEncapsulation, ViewMetadata} from './metadata/view'; -import {makeDecorator, makeParamDecorator, makePropDecorator, TypeDecorator,} from './util/decorators'; -import {Type} from '../src/facade/lang'; /** * Interface for the {@link DirectiveMetadata} decorator function. diff --git a/modules/@angular/core/src/testability/testability.ts b/modules/@angular/core/src/testability/testability.ts index 44035e6724..c21c0570b3 100644 --- a/modules/@angular/core/src/testability/testability.ts +++ b/modules/@angular/core/src/testability/testability.ts @@ -7,7 +7,6 @@ */ import {Injectable} from '../di/decorators'; -import {ObservableWrapper} from '../facade/async'; import {Map, MapWrapper} from '../facade/collection'; import {BaseException} from '../facade/exceptions'; import {scheduleMicroTask} from '../facade/lang'; @@ -40,18 +39,22 @@ export class Testability { /** @internal */ _watchAngularEvents(): void { - ObservableWrapper.subscribe(this._ngZone.onUnstable, (_) => { - this._didWork = true; - this._isZoneStable = false; + this._ngZone.onUnstable.subscribe({ + next: () => { + this._didWork = true; + this._isZoneStable = false; + } }); this._ngZone.runOutsideAngular(() => { - ObservableWrapper.subscribe(this._ngZone.onStable, (_) => { - NgZone.assertNotInAngularZone(); - scheduleMicroTask(() => { - this._isZoneStable = true; - this._runCallbacksIfReady(); - }); + this._ngZone.onStable.subscribe({ + next: () => { + NgZone.assertNotInAngularZone(); + scheduleMicroTask(() => { + this._isZoneStable = true; + this._runCallbacksIfReady(); + }); + } }); }); } diff --git a/modules/@angular/core/test/application_init_spec.ts b/modules/@angular/core/test/application_init_spec.ts index 7f5e615741..d60c4db087 100644 --- a/modules/@angular/core/test/application_init_spec.ts +++ b/modules/@angular/core/test/application_init_spec.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ import {APP_INITIALIZER, ApplicationInitStatus} from '../src/application_init'; -import {PromiseCompleter, PromiseWrapper} from '../src/facade/async'; import {TestBed, async, inject, withModule} from '../testing'; export function main() { @@ -25,12 +24,12 @@ export function main() { }); describe('with async initializers', () => { - let completer: PromiseCompleter; + let resolve: (result: any) => void; + let promise: Promise; beforeEach(() => { - completer = PromiseWrapper.completer(); - TestBed.configureTestingModule({ - providers: [{provide: APP_INITIALIZER, multi: true, useValue: () => completer.promise}] - }); + promise = new Promise((res) => { resolve = res; }); + TestBed.configureTestingModule( + {providers: [{provide: APP_INITIALIZER, multi: true, useValue: () => promise}]}); }); it('should updat the status once all async initializers are done', @@ -38,7 +37,7 @@ export function main() { let completerResolver = false; setTimeout(() => { completerResolver = true; - completer.resolve(); + resolve(null); }); expect(status.done).toBe(false); @@ -49,4 +48,4 @@ export function main() { }))); }); }); -} \ No newline at end of file +} diff --git a/modules/@angular/core/test/application_ref_spec.ts b/modules/@angular/core/test/application_ref_spec.ts index 6b888bc043..d498269358 100644 --- a/modules/@angular/core/test/application_ref_spec.ts +++ b/modules/@angular/core/test/application_ref_spec.ts @@ -15,7 +15,6 @@ import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens'; import {expect} from '@angular/platform-browser/testing/matchers'; -import {PromiseCompleter, PromiseWrapper} from '../src/facade/async'; import {ExceptionHandler} from '../src/facade/exception_handler'; import {BaseException} from '../src/facade/exceptions'; import {ConcreteType} from '../src/facade/lang'; @@ -143,11 +142,9 @@ export function main() { it('should throw if an APP_INITIIALIZER is not yet resolved', withModule( { - providers: [{ - provide: APP_INITIALIZER, - useValue: () => PromiseWrapper.completer().promise, - multi: true - }] + providers: [ + {provide: APP_INITIALIZER, useValue: () => new Promise(() => {}), multi: true} + ] }, inject([ApplicationRef], (ref: ApplicationRef_) => { expect(() => ref.bootstrap(SomeComponent)) @@ -164,16 +161,17 @@ export function main() { inject([PlatformRef], (_platform: PlatformRef) => { defaultPlatform = _platform; })); it('should wait for asynchronous app initializers', async(() => { - let completer: PromiseCompleter = PromiseWrapper.completer(); + let resolve: (result: any) => void; + let promise: Promise = new Promise((res) => { resolve = res; }); var initializerDone = false; setTimeout(() => { - completer.resolve(true); + resolve(true); initializerDone = true; }, 1); defaultPlatform - .bootstrapModule(createModule( - [{provide: APP_INITIALIZER, useValue: () => completer.promise, multi: true}])) + .bootstrapModule( + createModule([{provide: APP_INITIALIZER, useValue: () => promise, multi: true}])) .then(_ => { expect(initializerDone).toBe(true); }); })); @@ -250,17 +248,18 @@ export function main() { beforeEach( inject([PlatformRef], (_platform: PlatformRef) => { defaultPlatform = _platform; })); it('should wait for asynchronous app initializers', async(() => { - let completer: PromiseCompleter = PromiseWrapper.completer(); + let resolve: (result: any) => void; + let promise: Promise = new Promise((res) => { resolve = res; }); var initializerDone = false; setTimeout(() => { - completer.resolve(true); + resolve(true); initializerDone = true; }, 1); const compilerFactory: CompilerFactory = defaultPlatform.injector.get(CompilerFactory, null); - const moduleFactory = compilerFactory.createCompiler().compileModuleSync(createModule( - [{provide: APP_INITIALIZER, useValue: () => completer.promise, multi: true}])); + const moduleFactory = compilerFactory.createCompiler().compileModuleSync( + createModule([{provide: APP_INITIALIZER, useValue: () => promise, multi: true}])); defaultPlatform.bootstrapModuleFactory(moduleFactory).then(_ => { expect(initializerDone).toBe(true); }); diff --git a/modules/@angular/core/test/debug/debug_node_spec.ts b/modules/@angular/core/test/debug/debug_node_spec.ts index 1b6570258e..db78fbcafa 100644 --- a/modules/@angular/core/test/debug/debug_node_spec.ts +++ b/modules/@angular/core/test/debug/debug_node_spec.ts @@ -6,20 +6,17 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; +import {NgFor, NgIf} from '@angular/common'; +import {Injectable} from '@angular/core'; +import {Component, Directive, Input} from '@angular/core/src/metadata'; import {TestComponentBuilder} from '@angular/core/testing'; - +import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; +import {By} from '@angular/platform-browser/src/dom/debug/by'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; +import {expect} from '@angular/platform-browser/testing/matchers'; import {EventEmitter} from '../../src/facade/async'; -import {Injectable} from '@angular/core'; -import {NgFor, NgIf} from '@angular/common'; -import {By} from '@angular/platform-browser/src/dom/debug/by'; - -import {Directive, Component, Input} from '@angular/core/src/metadata'; - @Injectable() class Logger { logs: string[]; diff --git a/modules/@angular/core/test/di/binding_spec.ts b/modules/@angular/core/test/di/binding_spec.ts index a4fac918a0..c999855916 100644 --- a/modules/@angular/core/test/di/binding_spec.ts +++ b/modules/@angular/core/test/di/binding_spec.ts @@ -6,9 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ -import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; - import {bind, provide} from '@angular/core'; +import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; export function main() { describe('provider', () => { diff --git a/modules/@angular/core/test/di/forward_ref_spec.ts b/modules/@angular/core/test/di/forward_ref_spec.ts index 2e1b42641f..f135c5517f 100644 --- a/modules/@angular/core/test/di/forward_ref_spec.ts +++ b/modules/@angular/core/test/di/forward_ref_spec.ts @@ -6,8 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; import {forwardRef, resolveForwardRef} from '@angular/core/src/di'; +import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; + import {Type} from '../../src/facade/lang'; export function main() { diff --git a/modules/@angular/core/test/di/reflective_injector_spec.ts b/modules/@angular/core/test/di/reflective_injector_spec.ts index 899e118e99..8f60096815 100644 --- a/modules/@angular/core/test/di/reflective_injector_spec.ts +++ b/modules/@angular/core/test/di/reflective_injector_spec.ts @@ -6,16 +6,15 @@ * found in the LICENSE file at https://angular.io/license */ +import {Inject, InjectMetadata, Injectable, Injector, Optional, ReflectiveInjector, ReflectiveKey, SelfMetadata, forwardRef} from '@angular/core'; +import {DependencyMetadata} from '@angular/core/src/di/metadata'; +import {ReflectiveInjectorDynamicStrategy, ReflectiveInjectorInlineStrategy, ReflectiveInjector_, ReflectiveProtoInjector} from '@angular/core/src/di/reflective_injector'; +import {ResolvedReflectiveProvider_} from '@angular/core/src/di/reflective_provider'; import {expect} from '@angular/platform-browser/testing/matchers'; import {BaseException} from '../../src/facade/exceptions'; import {isBlank, isPresent, stringify} from '../../src/facade/lang'; -import {ReflectiveKey, ReflectiveInjector, Injector, forwardRef, Injectable, InjectMetadata, SelfMetadata, Optional, Inject,} from '@angular/core'; -import {ReflectiveInjector_, ReflectiveInjectorInlineStrategy, ReflectiveInjectorDynamicStrategy, ReflectiveProtoInjector} from '@angular/core/src/di/reflective_injector'; -import {DependencyMetadata} from '@angular/core/src/di/metadata'; -import {ResolvedReflectiveProvider_} from '@angular/core/src/di/reflective_provider'; - class CustomDependencyMetadata extends DependencyMetadata {} class Engine {} diff --git a/modules/@angular/core/test/dom/dom_adapter_spec.ts b/modules/@angular/core/test/dom/dom_adapter_spec.ts index 646712fb7f..8e3390cd92 100644 --- a/modules/@angular/core/test/dom/dom_adapter_spec.ts +++ b/modules/@angular/core/test/dom/dom_adapter_spec.ts @@ -6,8 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit, beforeEachProviders,} from '@angular/core/testing/testing_internal'; - +import {beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {el, stringifyElement} from '@angular/platform-browser/testing/browser_util'; diff --git a/modules/@angular/core/test/fake_async_spec.ts b/modules/@angular/core/test/fake_async_spec.ts index ff78486433..296b60b7aa 100644 --- a/modules/@angular/core/test/fake_async_spec.ts +++ b/modules/@angular/core/test/fake_async_spec.ts @@ -6,12 +6,14 @@ * found in the LICENSE file at https://angular.io/license */ +import {discardPeriodicTasks, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing'; import {Log, beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; import {expect} from '@angular/platform-browser/testing/matchers'; -import {fakeAsync, flushMicrotasks, tick, discardPeriodicTasks,} from '@angular/core/testing'; -import {TimerWrapper, PromiseWrapper} from '../../router-deprecated/src/facade/async'; -import {BaseException} from '../../router-deprecated/src/facade/exceptions'; + import {Parser} from '../../compiler/src/expression_parser/parser'; +import {BaseException} from '../../router-deprecated/src/facade/exceptions'; + +const resolvedPromise = Promise.resolve(null); export function main() { describe('fake async', () => { @@ -42,7 +44,7 @@ export function main() { it('should flush microtasks before returning', () => { var thenRan = false; - fakeAsync(() => { PromiseWrapper.resolve(null).then(_ => { thenRan = true; }); })(); + fakeAsync(() => { resolvedPromise.then(_ => { thenRan = true; }); })(); expect(thenRan).toEqual(true); }); @@ -54,7 +56,7 @@ export function main() { describe('Promise', () => { it('should run asynchronous code', fakeAsync(() => { var thenRan = false; - PromiseWrapper.resolve(null).then((_) => { thenRan = true; }); + resolvedPromise.then((_) => { thenRan = true; }); expect(thenRan).toEqual(false); @@ -65,7 +67,7 @@ export function main() { it('should run chained thens', fakeAsync(() => { var log = new Log(); - PromiseWrapper.resolve(null).then((_) => log.add(1)).then((_) => log.add(2)); + resolvedPromise.then((_) => log.add(1)).then((_) => log.add(2)); expect(log.result()).toEqual(''); @@ -76,9 +78,9 @@ export function main() { it('should run Promise created in Promise', fakeAsync(() => { var log = new Log(); - PromiseWrapper.resolve(null).then((_) => { + resolvedPromise.then((_) => { log.add(1); - PromiseWrapper.resolve(null).then((_) => log.add(2)); + resolvedPromise.then((_) => log.add(2)); }); expect(log.result()).toEqual(''); @@ -90,7 +92,7 @@ export function main() { it('should complain if the test throws an exception during async calls', () => { expect(() => { fakeAsync(() => { - PromiseWrapper.resolve(null).then((_) => { throw new BaseException('async'); }); + resolvedPromise.then((_) => { throw new BaseException('async'); }); flushMicrotasks(); })(); }).toThrowError('Uncaught (in promise): async'); @@ -107,7 +109,7 @@ export function main() { describe('timers', () => { it('should run queued zero duration timer on zero tick', fakeAsync(() => { var ran = false; - TimerWrapper.setTimeout(() => { ran = true; }, 0); + setTimeout(() => { ran = true; }, 0); expect(ran).toEqual(false); @@ -118,7 +120,7 @@ export function main() { it('should run queued timer after sufficient clock ticks', fakeAsync(() => { var ran = false; - TimerWrapper.setTimeout(() => { ran = true; }, 10); + setTimeout(() => { ran = true; }, 10); tick(6); expect(ran).toEqual(false); @@ -129,7 +131,7 @@ export function main() { it('should run queued timer only once', fakeAsync(() => { var cycles = 0; - TimerWrapper.setTimeout(() => { cycles++; }, 10); + setTimeout(() => { cycles++; }, 10); tick(10); expect(cycles).toEqual(1); @@ -143,8 +145,8 @@ export function main() { it('should not run cancelled timer', fakeAsync(() => { var ran = false; - var id = TimerWrapper.setTimeout(() => { ran = true; }, 10); - TimerWrapper.clearTimeout(id); + var id = setTimeout(() => { ran = true; }, 10); + clearTimeout(id); tick(10); expect(ran).toEqual(false); @@ -152,19 +154,19 @@ export function main() { it('should throw an error on dangling timers', () => { expect(() => { - fakeAsync(() => { TimerWrapper.setTimeout(() => {}, 10); })(); + fakeAsync(() => { setTimeout(() => {}, 10); })(); }).toThrowError('1 timer(s) still in the queue.'); }); it('should throw an error on dangling periodic timers', () => { expect(() => { - fakeAsync(() => { TimerWrapper.setInterval(() => {}, 10); })(); + fakeAsync(() => { setInterval(() => {}, 10); })(); }).toThrowError('1 periodic timer(s) still in the queue.'); }); it('should run periodic timers', fakeAsync(() => { var cycles = 0; - var id = TimerWrapper.setInterval(() => { cycles++; }, 10); + var id = setInterval(() => { cycles++; }, 10); tick(10); expect(cycles).toEqual(1); @@ -174,14 +176,13 @@ export function main() { tick(10); expect(cycles).toEqual(3); - - TimerWrapper.clearInterval(id); + clearInterval(id); })); it('should not run cancelled periodic timer', fakeAsync(() => { var ran = false; - var id = TimerWrapper.setInterval(() => { ran = true; }, 10); - TimerWrapper.clearInterval(id); + var id = setInterval(() => { ran = true; }, 10); + clearInterval(id); tick(10); expect(ran).toEqual(false); @@ -191,9 +192,9 @@ export function main() { var cycles = 0; var id: any /** TODO #9100 */; - id = TimerWrapper.setInterval(() => { + id = setInterval(() => { cycles++; - TimerWrapper.clearInterval(id); + clearInterval(id); }, 10); tick(10); @@ -205,7 +206,7 @@ export function main() { it('should clear periodic timers', fakeAsync(() => { var cycles = 0; - var id = TimerWrapper.setInterval(() => { cycles++; }, 10); + var id = setInterval(() => { cycles++; }, 10); tick(10); expect(cycles).toEqual(1); @@ -224,33 +225,32 @@ export function main() { it('should process microtasks before timers', fakeAsync(() => { var log = new Log(); - PromiseWrapper.resolve(null).then((_) => log.add('microtask')); + resolvedPromise.then((_) => log.add('microtask')); - TimerWrapper.setTimeout(() => log.add('timer'), 9); + setTimeout(() => log.add('timer'), 9); - var id = TimerWrapper.setInterval(() => log.add('periodic timer'), 10); + var id = setInterval(() => log.add('periodic timer'), 10); expect(log.result()).toEqual(''); tick(10); expect(log.result()).toEqual('microtask; timer; periodic timer'); - - TimerWrapper.clearInterval(id); + clearInterval(id); })); it('should process micro-tasks created in timers before next timers', fakeAsync(() => { var log = new Log(); - PromiseWrapper.resolve(null).then((_) => log.add('microtask')); + resolvedPromise.then((_) => log.add('microtask')); - TimerWrapper.setTimeout(() => { + setTimeout(() => { log.add('timer'); - PromiseWrapper.resolve(null).then((_) => log.add('t microtask')); + resolvedPromise.then((_) => log.add('t microtask')); }, 9); - var id = TimerWrapper.setInterval(() => { + var id = setInterval(() => { log.add('periodic timer'); - PromiseWrapper.resolve(null).then((_) => log.add('pt microtask')); + resolvedPromise.then((_) => log.add('pt microtask')); }, 10); tick(10); @@ -261,8 +261,7 @@ export function main() { expect(log.result()) .toEqual( 'microtask; timer; t microtask; periodic timer; pt microtask; periodic timer; pt microtask'); - - TimerWrapper.clearInterval(id); + clearInterval(id); })); }); diff --git a/modules/@angular/core/test/linker/dynamic_component_loader_spec.ts b/modules/@angular/core/test/linker/dynamic_component_loader_spec.ts index 153a43402a..b12fdce23b 100644 --- a/modules/@angular/core/test/linker/dynamic_component_loader_spec.ts +++ b/modules/@angular/core/test/linker/dynamic_component_loader_spec.ts @@ -6,19 +6,19 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {ComponentFixture, TestComponentBuilder} from '@angular/core/testing'; -import {Predicate} from '../../src/facade/collection'; -import {Injector, DebugElement, Type, ViewContainerRef, ViewChild} from '@angular/core'; -import {Component} from '@angular/core/src/metadata'; +import {DebugElement, Injector, Type, ViewChild, ViewContainerRef} from '@angular/core'; import {DynamicComponentLoader} from '@angular/core/src/linker/dynamic_component_loader'; import {ElementRef} from '@angular/core/src/linker/element_ref'; -import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens'; +import {Component} from '@angular/core/src/metadata'; +import {ComponentFixture, TestComponentBuilder} from '@angular/core/testing'; +import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; -import {BaseException} from '../../src/facade/exceptions'; -import {PromiseWrapper} from '../../src/facade/promise'; +import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens'; import {el} from '@angular/platform-browser/testing/browser_util'; +import {expect} from '@angular/platform-browser/testing/matchers'; + +import {Predicate} from '../../src/facade/collection'; +import {BaseException} from '../../src/facade/exceptions'; export function main() { describe('DynamicComponentLoader', function() { @@ -98,10 +98,11 @@ export function main() { async: AsyncTestCompleter) => { tcb.createAsync(MyComp3).then((tc: ComponentFixture) => { tc.detectChanges(); - PromiseWrapper.catchError( - loader.loadNextToLocation( - DynamicallyLoadedThrows, tc.componentInstance.viewContainerRef), - (error) => { + + loader + .loadNextToLocation( + DynamicallyLoadedThrows, tc.componentInstance.viewContainerRef) + .catch((error) => { expect(error.message).toContain('ThrownInConstructor'); expect(() => tc.detectChanges()).not.toThrow(); async.done(); diff --git a/modules/@angular/core/test/linker/entry_components_integration_spec.ts b/modules/@angular/core/test/linker/entry_components_integration_spec.ts index b0d44b8e69..d9b6cb38c9 100644 --- a/modules/@angular/core/test/linker/entry_components_integration_spec.ts +++ b/modules/@angular/core/test/linker/entry_components_integration_spec.ts @@ -6,11 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal'; -import {TestComponentBuilder, TestBed} from '@angular/core/testing'; -import {Component, ComponentFactoryResolver, NoComponentFactoryError, forwardRef, ANALYZE_FOR_ENTRY_COMPONENTS, ViewMetadata} from '@angular/core'; -import {stringify} from '../../src/facade/lang'; +import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, ComponentFactoryResolver, NoComponentFactoryError, ViewMetadata, forwardRef} from '@angular/core'; +import {TestBed, TestComponentBuilder} from '@angular/core/testing'; +import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; + import {Console} from '../../src/console'; +import {stringify} from '../../src/facade/lang'; export function main() { describe('jit', () => { declareTests({useJit: true}); }); diff --git a/modules/@angular/core/test/linker/integration_spec.ts b/modules/@angular/core/test/linker/integration_spec.ts index 2a2a2d76c3..f871a91502 100644 --- a/modules/@angular/core/test/linker/integration_spec.ts +++ b/modules/@angular/core/test/linker/integration_spec.ts @@ -6,35 +6,27 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {fakeAsync, tick, ComponentFixture, TestBed, TestComponentBuilder} from '@angular/core/testing'; -import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; -import {isPresent, stringify, isBlank,} from '../../src/facade/lang'; -import {BaseException} from '../../src/facade/exceptions'; -import {PromiseWrapper, EventEmitter, ObservableWrapper, PromiseCompleter,} from '../../src/facade/async'; - -import {Injector, Injectable, forwardRef, OpaqueToken, Inject, Host, SkipSelf, SkipSelfMetadata, OnDestroy, ReflectiveInjector, Compiler} from '@angular/core'; - -import {NgIf, NgFor, AsyncPipe} from '@angular/common'; - -import {PipeTransform, ChangeDetectorRef, ChangeDetectionStrategy} from '@angular/core/src/change_detection/change_detection'; - +import {AsyncPipe, NgFor, NgIf} from '@angular/common'; import {CompilerConfig} from '@angular/compiler'; - -import {Directive, Component, ViewMetadata, Attribute, Query, Pipe, Input, Output, HostBinding, HostListener} from '@angular/core/src/metadata'; - -import {QueryList} from '@angular/core/src/linker/query_list'; - -import {ViewContainerRef} from '@angular/core/src/linker/view_container_ref'; -import {EmbeddedViewRef} from '@angular/core/src/linker/view_ref'; - +import {Compiler, Host, Inject, Injectable, Injector, OnDestroy, OpaqueToken, ReflectiveInjector, SkipSelf, SkipSelfMetadata, forwardRef} from '@angular/core'; +import {ChangeDetectionStrategy, ChangeDetectorRef, PipeTransform} from '@angular/core/src/change_detection/change_detection'; import {ComponentResolver} from '@angular/core/src/linker/component_resolver'; import {ElementRef} from '@angular/core/src/linker/element_ref'; +import {QueryList} from '@angular/core/src/linker/query_list'; import {TemplateRef, TemplateRef_} from '@angular/core/src/linker/template_ref'; - +import {ViewContainerRef} from '@angular/core/src/linker/view_container_ref'; +import {EmbeddedViewRef} from '@angular/core/src/linker/view_ref'; +import {Attribute, Component, Directive, HostBinding, HostListener, Input, Output, Pipe, Query, ViewMetadata} from '@angular/core/src/metadata'; import {Renderer} from '@angular/core/src/render'; -import {el, dispatchEvent} from '@angular/platform-browser/testing/browser_util'; +import {ComponentFixture, TestBed, TestComponentBuilder, fakeAsync, tick} from '@angular/core/testing'; +import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; +import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; +import {dispatchEvent, el} from '@angular/platform-browser/testing/browser_util'; +import {expect} from '@angular/platform-browser/testing/matchers'; + +import {EventEmitter} from '../../src/facade/async'; +import {BaseException} from '../../src/facade/exceptions'; +import {isBlank, isPresent, stringify} from '../../src/facade/lang'; const ANCHOR_ELEMENT = new OpaqueToken('AnchorElement'); @@ -991,15 +983,17 @@ function declareTests({useJit}: {useJit: boolean}) { expect(listener.msg).toEqual(''); var eventCount = 0; - ObservableWrapper.subscribe(emitter.event, (_) => { - eventCount++; - if (eventCount === 1) { - expect(listener.msg).toEqual('fired !'); - fixture.destroy(); - emitter.fireEvent('fired again !'); - } else { - expect(listener.msg).toEqual('fired !'); - async.done(); + emitter.event.subscribe({ + next: () => { + eventCount++; + if (eventCount === 1) { + expect(listener.msg).toEqual('fired !'); + fixture.destroy(); + emitter.fireEvent('fired again !'); + } else { + expect(listener.msg).toEqual('fired !'); + async.done(); + } } }); @@ -1029,10 +1023,12 @@ function declareTests({useJit}: {useJit: boolean}) { myComp.ctxProp = ''; expect(listener.msg).toEqual(''); - ObservableWrapper.subscribe(emitter.event, (_) => { - expect(listener.msg).toEqual('fired !'); - expect(myComp.ctxProp).toEqual('fired !'); - async.done(); + emitter.event.subscribe({ + next: () => { + expect(listener.msg).toEqual('fired !'); + expect(myComp.ctxProp).toEqual('fired !'); + async.done(); + } }); emitter.fireEvent('fired !'); @@ -1057,9 +1053,11 @@ function declareTests({useJit}: {useJit: boolean}) { expect(dir.control).toEqual('one'); - ObservableWrapper.subscribe(dir.controlChange, (_) => { - expect(fixture.debugElement.componentInstance.ctxProp).toEqual('two'); - async.done(); + dir.controlChange.subscribe({ + next: () => { + expect(fixture.debugElement.componentInstance.ctxProp).toEqual('two'); + async.done(); + } }); dir.triggerChange('two'); @@ -1551,7 +1549,7 @@ function declareTests({useJit}: {useJit: boolean}) { template: `` })); - PromiseWrapper.catchError(tcb.createAsync(MyComp), (e) => { + tcb.createAsync(MyComp).catch((e) => { var c = e.context; expect(getDOM().nodeName(c.componentRenderElement).toUpperCase()).toEqual('DIV'); expect((c.injector).get).toBeTruthy(); @@ -1741,7 +1739,7 @@ function declareTests({useJit}: {useJit: boolean}) { tcb = tcb.overrideView( MyComp, new ViewMetadata({template: '
'})); - PromiseWrapper.catchError(tcb.createAsync(MyComp), (e) => { + tcb.createAsync(MyComp).catch((e) => { expect(e.message).toEqual( `Template parse errors:\nCan't bind to 'unknown' since it isn't a known property of 'div'. ("
]unknown="{{ctxProp}}">
"): MyComp@0:5`); async.done(); @@ -2211,20 +2209,17 @@ class PushCmpWithHostEvent { }) class PushCmpWithAsyncPipe { numberOfChecks: number = 0; + resolve: (result: any) => void; promise: Promise; - completer: PromiseCompleter; constructor() { - this.completer = PromiseWrapper.completer(); - this.promise = this.completer.promise; + this.promise = new Promise((resolve) => { this.resolve = resolve; }); } get field() { this.numberOfChecks++; return this.promise; } - - resolve(value: any) { this.completer.resolve(value); } } @Component({selector: 'my-comp', directives: []}) @@ -2324,7 +2319,7 @@ class DirectiveEmittingEvent { this.event = new EventEmitter(); } - fireEvent(msg: string) { ObservableWrapper.callEmit(this.event, msg); } + fireEvent(msg: string) { this.event.emit(msg); } } @Directive({selector: '[update-host-attributes]', host: {'role': 'button'}}) @@ -2466,7 +2461,7 @@ class DirectiveWithTwoWayBinding { controlChange = new EventEmitter(); control: any = null; - triggerChange(value: any) { ObservableWrapper.callEmit(this.controlChange, value); } + triggerChange(value: any) { this.controlChange.emit(value); } } @Injectable() @@ -2661,7 +2656,7 @@ class DirectiveWithPropDecorators { @HostListener('click', ['$event.target']) onClick(target: any) { this.target = target; } - fireEvent(msg: any) { ObservableWrapper.callEmit(this.event, msg); } + fireEvent(msg: any) { this.event.emit(msg); } } @Component({selector: 'some-cmp'}) diff --git a/modules/@angular/core/test/linker/ng_container_integration_spec.ts b/modules/@angular/core/test/linker/ng_container_integration_spec.ts index b4c0dec2f5..45ab12e091 100644 --- a/modules/@angular/core/test/linker/ng_container_integration_spec.ts +++ b/modules/@angular/core/test/linker/ng_container_integration_spec.ts @@ -6,12 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {TestBed, TestComponentBuilder} from '@angular/core/testing'; -import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; -import {Component, Directive, AfterContentInit, AfterViewInit, QueryList, ContentChildren, ViewChildren, Input} from '@angular/core'; import {NgIf} from '@angular/common'; +import {AfterContentInit, AfterViewInit, Component, ContentChildren, Directive, Input, QueryList, ViewChildren} from '@angular/core'; +import {TestBed, TestComponentBuilder} from '@angular/core/testing'; +import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; +import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; +import {expect} from '@angular/platform-browser/testing/matchers'; export function main() { describe('jit', () => { declareTests({useJit: true}); }); diff --git a/modules/@angular/core/test/linker/projection_integration_spec.ts b/modules/@angular/core/test/linker/projection_integration_spec.ts index c4766f1ae1..6c9e6c2aae 100644 --- a/modules/@angular/core/test/linker/projection_integration_spec.ts +++ b/modules/@angular/core/test/linker/projection_integration_spec.ts @@ -6,15 +6,13 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {ComponentFixture, TestComponentBuilder} from '@angular/core/testing'; - -import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; - -import {forwardRef, Component, Directive, ElementRef, TemplateRef, ViewContainerRef, ViewEncapsulation, ViewMetadata} from '@angular/core'; -import {By,} from '@angular/platform-browser/src/dom/debug/by'; +import {Component, Directive, ElementRef, TemplateRef, ViewContainerRef, ViewEncapsulation, ViewMetadata, forwardRef} from '@angular/core'; import {getAllDebugNodes} from '@angular/core/src/debug/debug_node'; +import {ComponentFixture, TestComponentBuilder} from '@angular/core/testing'; +import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; +import {By} from '@angular/platform-browser/src/dom/debug/by'; +import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; +import {expect} from '@angular/platform-browser/testing/matchers'; export function main() { describe('projection', () => { diff --git a/modules/@angular/core/test/linker/query_integration_spec.ts b/modules/@angular/core/test/linker/query_integration_spec.ts index 1492407242..4b2bb4e5d7 100644 --- a/modules/@angular/core/test/linker/query_integration_spec.ts +++ b/modules/@angular/core/test/linker/query_integration_spec.ts @@ -6,15 +6,13 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, ddescribe, describe, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; +import {NgFor, NgIf} from '@angular/common'; +import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, Component, ContentChild, ContentChildren, Directive, Query, QueryList, TemplateRef, ViewChild, ViewChildren, ViewContainerRef, ViewQuery, asNativeElements} from '@angular/core'; import {TestComponentBuilder} from '@angular/core/testing'; +import {AsyncTestCompleter, beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; +import {expect} from '@angular/platform-browser/testing/matchers'; import {isPresent, stringify} from '../../src/facade/lang'; -import {ObservableWrapper} from '../../src/facade/async'; - -import {asNativeElements, ViewContainerRef, Component, Directive, TemplateRef, Query, QueryList, ViewQuery, ContentChildren, ViewChildren, ContentChild, ViewChild, AfterContentInit, AfterViewInit, AfterContentChecked, AfterViewChecked} from '@angular/core'; -import {NgIf, NgFor} from '@angular/common'; export function main() { describe('Query API', () => { @@ -418,10 +416,12 @@ export function main() { var q = view.debugElement.children[0].references['q']; view.detectChanges(); - ObservableWrapper.subscribe(q.query.changes, (_) => { - expect(q.query.first.text).toEqual('1'); - expect(q.query.last.text).toEqual('2'); - async.done(); + q.query.changes.subscribe({ + next: () => { + expect(q.query.first.text).toEqual('1'); + expect(q.query.last.text).toEqual('2'); + async.done(); + } }); view.debugElement.componentInstance.shouldShow = true; @@ -445,10 +445,12 @@ export function main() { var firedQ2 = false; - ObservableWrapper.subscribe(q2.query.changes, (_) => { firedQ2 = true; }); - ObservableWrapper.subscribe(q1.query.changes, (_) => { - expect(firedQ2).toBe(true); - async.done(); + q2.query.changes.subscribe({next: () => { firedQ2 = true; }}); + q1.query.changes.subscribe({ + next: () => { + expect(firedQ2).toBe(true); + async.done(); + } }); view.detectChanges(); diff --git a/modules/@angular/core/test/linker/query_list_spec.ts b/modules/@angular/core/test/linker/query_list_spec.ts index 2a4689801f..667a5d2cce 100644 --- a/modules/@angular/core/test/linker/query_list_spec.ts +++ b/modules/@angular/core/test/linker/query_list_spec.ts @@ -6,13 +6,13 @@ * found in the LICENSE file at https://angular.io/license */ -import {describe, it, expect, beforeEach, ddescribe, iit, xit,} from '@angular/core/testing/testing_internal'; -import {fakeAsync, tick,} from '@angular/core/testing'; +import {QueryList} from '@angular/core/src/linker/query_list'; +import {fakeAsync, tick} from '@angular/core/testing'; +import {beforeEach, ddescribe, describe, expect, iit, it, xit} from '@angular/core/testing/testing_internal'; +import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; + import {iterateListLike} from '../../src/facade/collection'; import {StringWrapper} from '../../src/facade/lang'; -import {ObservableWrapper} from '../../src/facade/async'; -import {QueryList} from '@angular/core/src/linker/query_list'; -import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; interface _JsQueryList { filter(c: any): any; @@ -124,7 +124,7 @@ export function main() { describe('simple observable interface', () => { it('should fire callbacks on change', fakeAsync(() => { var fires = 0; - ObservableWrapper.subscribe(queryList.changes, (_) => { fires += 1; }); + queryList.changes.subscribe({next: (_) => { fires += 1; }}); queryList.notifyOnChanges(); tick(); @@ -139,7 +139,7 @@ export function main() { it('should provides query list as an argument', fakeAsync(() => { var recorded: any /** TODO #9100 */; - ObservableWrapper.subscribe(queryList.changes, (v: any) => { recorded = v; }); + queryList.changes.subscribe({next: (v: any) => { recorded = v; }}); queryList.reset(['one']); queryList.notifyOnChanges(); diff --git a/modules/@angular/core/test/linker/regression_integration_spec.ts b/modules/@angular/core/test/linker/regression_integration_spec.ts index fcdc48c892..379c8d66f3 100644 --- a/modules/@angular/core/test/linker/regression_integration_spec.ts +++ b/modules/@angular/core/test/linker/regression_integration_spec.ts @@ -6,12 +6,11 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; +import {NgClass, NgIf} from '@angular/common'; +import {Component, Injector, OpaqueToken, Pipe, PipeTransform, ViewMetadata, forwardRef} from '@angular/core'; import {TestBed, TestComponentBuilder} from '@angular/core/testing'; - -import {Component, Pipe, PipeTransform, ViewMetadata, OpaqueToken, Injector, forwardRef} from '@angular/core'; -import {NgIf, NgClass} from '@angular/common'; +import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; +import {expect} from '@angular/platform-browser/testing/matchers'; export function main() { describe('jit', () => { declareTests({useJit: true}); }); diff --git a/modules/@angular/core/test/linker/security_integration_spec.ts b/modules/@angular/core/test/linker/security_integration_spec.ts index 8fb7395b11..974e2c6455 100644 --- a/modules/@angular/core/test/linker/security_integration_spec.ts +++ b/modules/@angular/core/test/linker/security_integration_spec.ts @@ -6,10 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, ddescribe, describe, expect, inject, beforeEachProviders, beforeEach, afterEach, it,} from '@angular/core/testing/testing_internal'; -import {TestBed, TestComponentBuilder} from '@angular/core/testing'; -import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {Component} from '@angular/core/src/metadata'; +import {TestBed, TestComponentBuilder} from '@angular/core/testing'; +import {AsyncTestCompleter, afterEach, beforeEach, beforeEachProviders, ddescribe, describe, expect, inject, it} from '@angular/core/testing/testing_internal'; +import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {DomSanitizationService} from '@angular/platform-browser/src/security/dom_sanitization_service'; diff --git a/modules/@angular/core/test/linker/view_injector_integration_spec.ts b/modules/@angular/core/test/linker/view_injector_integration_spec.ts index 073a2c5bfb..dbfce762bd 100644 --- a/modules/@angular/core/test/linker/view_injector_integration_spec.ts +++ b/modules/@angular/core/test/linker/view_injector_integration_spec.ts @@ -6,13 +6,14 @@ * found in the LICENSE file at https://angular.io/license */ -import {describe, ddescribe, it, iit, xit, xdescribe, beforeEach, beforeEachProviders, inject,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {fakeAsync, flushMicrotasks, tick, ComponentFixture, TestComponentBuilder} from '@angular/core/testing'; -import {isBlank, ConcreteType} from '../../src/facade/lang'; -import {Type, ViewContainerRef, TemplateRef, ElementRef, ChangeDetectorRef, ChangeDetectionStrategy, Directive, Component, DebugElement, forwardRef, Input, PipeTransform, Attribute, ViewMetadata, provide, Optional, Inject, Self, InjectMetadata, Pipe, Host, SkipSelfMetadata} from '@angular/core'; -import {NgIf, NgFor} from '@angular/common'; +import {NgFor, NgIf} from '@angular/common'; +import {Attribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, DebugElement, Directive, ElementRef, Host, Inject, InjectMetadata, Input, Optional, Pipe, PipeTransform, Self, SkipSelfMetadata, TemplateRef, Type, ViewContainerRef, ViewMetadata, forwardRef, provide} from '@angular/core'; +import {ComponentFixture, TestComponentBuilder, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing'; +import {beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; +import {expect} from '@angular/platform-browser/testing/matchers'; + +import {ConcreteType, isBlank} from '../../src/facade/lang'; const ALL_DIRECTIVES = [ forwardRef(() => SimpleDirective), diff --git a/modules/@angular/core/test/metadata/decorators_spec.ts b/modules/@angular/core/test/metadata/decorators_spec.ts index da377c179b..6231e6f71d 100644 --- a/modules/@angular/core/test/metadata/decorators_spec.ts +++ b/modules/@angular/core/test/metadata/decorators_spec.ts @@ -6,10 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; - import {Component, Directive} from '@angular/core'; import {reflector} from '@angular/core/src/reflection/reflection'; +import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; export function main() { describe('es5 decorators', () => { diff --git a/modules/@angular/core/test/metadata/di_spec.ts b/modules/@angular/core/test/metadata/di_spec.ts index 621df667cb..6623fb5500 100644 --- a/modules/@angular/core/test/metadata/di_spec.ts +++ b/modules/@angular/core/test/metadata/di_spec.ts @@ -6,10 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; +import {Component, Directive, ElementRef, Input, QueryList, ViewChild, ViewChildren, ViewMetadata} from '@angular/core'; import {TestComponentBuilder} from '@angular/core/testing'; - -import {Component, ViewMetadata, Input, Directive, ViewChild, ViewChildren, QueryList, ElementRef} from '@angular/core'; +import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; export function main() { describe('ViewChild', () => { diff --git a/modules/@angular/core/test/reflection/reflector_spec.ts b/modules/@angular/core/test/reflection/reflector_spec.ts index 7e60a999b8..43ba3a73b5 100644 --- a/modules/@angular/core/test/reflection/reflector_spec.ts +++ b/modules/@angular/core/test/reflection/reflector_spec.ts @@ -6,13 +6,14 @@ * found in the LICENSE file at https://angular.io/license */ -import {describe, it, iit, ddescribe, expect, beforeEach,} from '@angular/core/testing/testing_internal'; import {OnInit} from '@angular/core'; -import {Reflector, ReflectionInfo} from '@angular/core/src/reflection/reflection'; +import {ReflectionInfo, Reflector} from '@angular/core/src/reflection/reflection'; import {ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities'; -import {ClassDecorator, ParamDecorator, PropDecorator, classDecorator, paramDecorator, propDecorator, HasGetterAndSetterDecorators} from './reflector_common'; +import {beforeEach, ddescribe, describe, expect, iit, it} from '@angular/core/testing/testing_internal'; import {browserDetection} from '@angular/platform-browser/testing/browser_util'; +import {ClassDecorator, HasGetterAndSetterDecorators, ParamDecorator, PropDecorator, classDecorator, paramDecorator, propDecorator} from './reflector_common'; + class AType { value: any /** TODO #9100 */; diff --git a/modules/@angular/core/test/testability/testability_spec.ts b/modules/@angular/core/test/testability/testability_spec.ts index d304050d2f..7b57a7cac0 100644 --- a/modules/@angular/core/test/testability/testability_spec.ts +++ b/modules/@angular/core/test/testability/testability_spec.ts @@ -7,11 +7,13 @@ */ import {Injectable} from '@angular/core/src/di'; -import {AsyncTestCompleter, SpyObject, inject, describe, ddescribe, it, iit, xit, xdescribe, expect, beforeEach,} from '@angular/core/testing/testing_internal'; import {Testability} from '@angular/core/src/testability/testability'; import {NgZone} from '@angular/core/src/zone/ng_zone'; +import {AsyncTestCompleter, SpyObject, beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; + +import {EventEmitter} from '../../src/facade/async'; import {normalizeBlank, scheduleMicroTask} from '../../src/facade/lang'; -import {PromiseWrapper, EventEmitter, ObservableWrapper} from '../../src/facade/async'; + // Schedules a microtasks (using a resolved promise .then()) function microTask(fn: Function): void { @@ -38,9 +40,9 @@ class MockNgZone extends NgZone { this._onStableStream = new EventEmitter(false); } - unstable(): void { ObservableWrapper.callEmit(this._onUnstableStream, null); } + unstable(): void { this._onUnstableStream.emit(null); } - stable(): void { ObservableWrapper.callEmit(this._onStableStream, null); } + stable(): void { this._onStableStream.emit(null); } } export function main() { diff --git a/modules/@angular/core/test/util/decorators_spec.ts b/modules/@angular/core/test/util/decorators_spec.ts index 93b0d22c3a..5300a0d59a 100644 --- a/modules/@angular/core/test/util/decorators_spec.ts +++ b/modules/@angular/core/test/util/decorators_spec.ts @@ -6,12 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ -import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; - -import {makeDecorator, makeParamDecorator, Class} from '@angular/core/src/util/decorators'; -import {global} from '../../src/facade/lang'; import {Inject} from '@angular/core'; import {reflector} from '@angular/core/src/reflection/reflection'; +import {Class, makeDecorator, makeParamDecorator} from '@angular/core/src/util/decorators'; +import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; + +import {global} from '../../src/facade/lang'; class TestAnnotation { constructor(public arg: any) {} diff --git a/modules/@angular/core/test/zone/ng_zone_spec.ts b/modules/@angular/core/test/zone/ng_zone_spec.ts index 82629bb27c..81e7acb6b6 100644 --- a/modules/@angular/core/test/zone/ng_zone_spec.ts +++ b/modules/@angular/core/test/zone/ng_zone_spec.ts @@ -6,12 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, Log, beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit,} from '@angular/core/testing/testing_internal'; - import {NgZone, NgZoneError} from '@angular/core/src/zone/ng_zone'; +import {AsyncTestCompleter, Log, beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; import {browserDetection} from '@angular/platform-browser/testing/browser_util'; -import {ObservableWrapper, PromiseCompleter, PromiseWrapper, TimerWrapper} from '../../src/facade/async'; import {BaseException} from '../../src/facade/exceptions'; import {isPresent, scheduleMicroTask} from '../../src/facade/lang'; @@ -21,7 +19,7 @@ var testTimeout = browserDetection.isEdge ? 1200 : 500; // Schedules a macrotask (using a timer) function macroTask(fn: (...args: any[]) => void, timer = 1): void { // adds longer timers for passing tests in IE and Edge - TimerWrapper.setTimeout(fn, needsLongerTimers ? timer : 1); + setTimeout(fn, needsLongerTimers ? timer : 1); } var _log: Log; @@ -29,23 +27,27 @@ var _errors: any[]; var _traces: any[]; var _zone: NgZone; +const resolvedPromise = Promise.resolve(null); + function logOnError() { - ObservableWrapper.subscribe(_zone.onError, (ngErr: NgZoneError) => { - _errors.push(ngErr.error); - _traces.push(ngErr.stackTrace); + _zone.onError.subscribe({ + next: (ngErr: NgZoneError) => { + _errors.push(ngErr.error); + _traces.push(ngErr.stackTrace); + } }); } function logOnUnstable() { - ObservableWrapper.subscribe(_zone.onUnstable, _log.fn('onUnstable')); + _zone.onUnstable.subscribe({next: _log.fn('onUnstable')}); } function logOnMicrotaskEmpty() { - ObservableWrapper.subscribe(_zone.onMicrotaskEmpty, _log.fn('onMicrotaskEmpty')); + _zone.onMicrotaskEmpty.subscribe({next: _log.fn('onMicrotaskEmpty')}); } function logOnStable() { - ObservableWrapper.subscribe(_zone.onStable, _log.fn('onStable')); + _zone.onStable.subscribe({next: _log.fn('onStable')}); } function runNgZoneNoLog(fn: () => any) { @@ -85,18 +87,19 @@ export function main() { it('should produce long stack traces', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { macroTask(() => { - var c: PromiseCompleter = PromiseWrapper.completer(); + let resolve: (result: any) => void; + let promise: Promise = new Promise((res) => { resolve = res; }); _zone.run(() => { - TimerWrapper.setTimeout(() => { - TimerWrapper.setTimeout(() => { - c.resolve(null); + setTimeout(() => { + setTimeout(() => { + resolve(null); throw new BaseException('ccc'); }, 0); }, 0); }); - c.promise.then((_) => { + promise.then((_) => { expect(_traces.length).toBe(1); expect(_traces[0].length).toBeGreaterThan(1); async.done(); @@ -107,18 +110,19 @@ export function main() { it('should produce long stack traces (when using microtasks)', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { macroTask(() => { - var c: PromiseCompleter = PromiseWrapper.completer(); + let resolve: (result: any) => void; + let promise: Promise = new Promise((res) => { resolve = res; }); _zone.run(() => { scheduleMicroTask(() => { scheduleMicroTask(() => { - c.resolve(null); + resolve(null); throw new BaseException('ddd'); }); }); }); - c.promise.then((_) => { + promise.then((_) => { expect(_traces.length).toBe(1); expect(_traces[0].length).toBeGreaterThan(1); async.done(); @@ -141,18 +145,19 @@ export function main() { it('should disable long stack traces', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { macroTask(() => { - var c: PromiseCompleter = PromiseWrapper.completer(); + let resolve: (result: any) => void; + let promise: Promise = new Promise((res) => { resolve = res; }); _zone.run(() => { - TimerWrapper.setTimeout(() => { - TimerWrapper.setTimeout(() => { - c.resolve(null); + setTimeout(() => { + setTimeout(() => { + resolve(null); throw new BaseException('ccc'); }, 0); }, 0); }); - c.promise.then((_) => { + promise.then((_) => { expect(_traces.length).toBe(1); if (isPresent(_traces[0])) { // some browsers don't have stack traces. @@ -180,7 +185,7 @@ function commonTests() { it('should be false', () => { expect(_zone.hasPendingMacrotasks).toBe(false); }); it('should be true', () => { - runNgZoneNoLog(() => { TimerWrapper.setTimeout(() => {}, 0); }); + runNgZoneNoLog(() => { setTimeout(() => {}, 0); }); expect(_zone.hasPendingMacrotasks).toBe(true); }); }); @@ -194,7 +199,7 @@ function commonTests() { }); it('should be true when timer is scheduled', () => { - runNgZoneNoLog(() => { TimerWrapper.setTimeout(() => {}, 0); }); + runNgZoneNoLog(() => { setTimeout(() => {}, 0); }); expect(_zone.hasPendingMacrotasks).toBe(true); }); }); @@ -231,12 +236,14 @@ function commonTests() { runNgZoneNoLog(() => macroTask(_log.fn('run'))); var times = 0; - ObservableWrapper.subscribe(_zone.onMicrotaskEmpty, (_) => { - times++; - _log.add(`onMicrotaskEmpty ${times}`); - if (times < 2) { - // Scheduling a microtask causes a second digest - runNgZoneNoLog(() => { scheduleMicroTask(() => {}); }); + _zone.onMicrotaskEmpty.subscribe({ + next: () => { + times++; + _log.add(`onMicrotaskEmpty ${times}`); + if (times < 2) { + // Scheduling a microtask causes a second digest + runNgZoneNoLog(() => { scheduleMicroTask(() => {}); }); + } } }); @@ -265,27 +272,33 @@ function commonTests() { // then verifies that those microtasks do not cause additional digests. var turnStart = false; - ObservableWrapper.subscribe(_zone.onUnstable, (_) => { - if (turnStart) throw 'Should not call this more than once'; - _log.add('onUnstable'); - scheduleMicroTask(() => {}); - turnStart = true; + _zone.onUnstable.subscribe({ + next: () => { + if (turnStart) throw 'Should not call this more than once'; + _log.add('onUnstable'); + scheduleMicroTask(() => {}); + turnStart = true; + } }); var turnDone = false; - ObservableWrapper.subscribe(_zone.onMicrotaskEmpty, (_) => { - if (turnDone) throw 'Should not call this more than once'; - _log.add('onMicrotaskEmpty'); - scheduleMicroTask(() => {}); - turnDone = true; + _zone.onMicrotaskEmpty.subscribe({ + next: () => { + if (turnDone) throw 'Should not call this more than once'; + _log.add('onMicrotaskEmpty'); + scheduleMicroTask(() => {}); + turnDone = true; + } }); var eventDone = false; - ObservableWrapper.subscribe(_zone.onStable, (_) => { - if (eventDone) throw 'Should not call this more than once'; - _log.add('onStable'); - scheduleMicroTask(() => {}); - eventDone = true; + _zone.onStable.subscribe({ + next: () => { + if (eventDone) throw 'Should not call this more than once'; + _log.add('onStable'); + scheduleMicroTask(() => {}); + eventDone = true; + } }); macroTask(() => { _zone.run(_log.fn('run')); }); @@ -303,11 +316,13 @@ function commonTests() { // the only practical use-case to run a callback inside the zone is // change detection after "onMicrotaskEmpty". That's the only case tested. var turnDone = false; - ObservableWrapper.subscribe(_zone.onMicrotaskEmpty, (_) => { - _log.add('onMyMicrotaskEmpty'); - if (turnDone) return; - _zone.run(() => { scheduleMicroTask(() => {}); }); - turnDone = true; + _zone.onMicrotaskEmpty.subscribe({ + next: () => { + _log.add('onMyMicrotaskEmpty'); + if (turnDone) return; + _zone.run(() => { scheduleMicroTask(() => {}); }); + turnDone = true; + } }); macroTask(() => { @@ -323,9 +338,11 @@ function commonTests() { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { runNgZoneNoLog(() => macroTask(_log.fn('run'))); - ObservableWrapper.subscribe(_zone.onStable, (_) => { - NgZone.assertNotInAngularZone(); - _log.add('onMyTaskDone'); + _zone.onStable.subscribe({ + next: () => { + NgZone.assertNotInAngularZone(); + _log.add('onMyTaskDone'); + } }); macroTask(() => { @@ -378,10 +395,12 @@ function commonTests() { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { runNgZoneNoLog(() => macroTask(_log.fn('start run'))); - ObservableWrapper.subscribe(_zone.onMicrotaskEmpty, (_) => { - _log.add('onMicrotaskEmpty:started'); - _zone.run(() => _log.add('nested run')); - _log.add('onMicrotaskEmpty:finished'); + _zone.onMicrotaskEmpty.subscribe({ + next: () => { + _log.add('onMicrotaskEmpty:started'); + _zone.run(() => _log.add('nested run')); + _log.add('onMicrotaskEmpty:finished'); + } }); macroTask(() => { @@ -407,24 +426,26 @@ function commonTests() { it('should call onUnstable and onMicrotaskEmpty before and after each turn', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - var a: PromiseCompleter; - var b: PromiseCompleter; + var aResolve: (result: string) => void; + var aPromise: Promise; + var bResolve: (result: string) => void; + var bPromise: Promise; runNgZoneNoLog(() => { macroTask(() => { - a = PromiseWrapper.completer(); - b = PromiseWrapper.completer(); + aPromise = new Promise(res => { aResolve = res; }); + bPromise = new Promise(res => { bResolve = res; }); _log.add('run start'); - a.promise.then(_log.fn('a then')); - b.promise.then(_log.fn('b then')); + aPromise.then(_log.fn('a then')); + bPromise.then(_log.fn('b then')); }); }); runNgZoneNoLog(() => { macroTask(() => { - a.resolve('a'); - b.resolve('b'); + aResolve('a'); + bResolve('b'); }); }); @@ -448,24 +469,25 @@ function commonTests() { it('should call onUnstable and onMicrotaskEmpty when an inner microtask is scheduled from outside angular', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - var completer: PromiseCompleter; + var resolve: (result: string) => void; + var promise: Promise; macroTask(() => { NgZone.assertNotInAngularZone(); - completer = PromiseWrapper.completer(); + promise = new Promise(res => { resolve = res; }); }); runNgZoneNoLog(() => { macroTask(() => { NgZone.assertInAngularZone(); - completer.promise.then(_log.fn('executedMicrotask')); + promise.then(_log.fn('executedMicrotask')); }); }); macroTask(() => { NgZone.assertNotInAngularZone(); _log.add('scheduling a microtask'); - completer.resolve(null); + resolve(null); }); macroTask(() => { @@ -488,19 +510,21 @@ function commonTests() { runNgZoneNoLog(() => macroTask(_log.fn('run'))); var ran = false; - ObservableWrapper.subscribe(_zone.onMicrotaskEmpty, (_) => { - _log.add('onMicrotaskEmpty(begin)'); + _zone.onMicrotaskEmpty.subscribe({ + next: () => { + _log.add('onMicrotaskEmpty(begin)'); - if (!ran) { - _zone.run(() => { - scheduleMicroTask(() => { - ran = true; - _log.add('executedMicrotask'); + if (!ran) { + _zone.run(() => { + scheduleMicroTask(() => { + ran = true; + _log.add('executedMicrotask'); + }); }); - }); - } + } - _log.add('onMicrotaskEmpty(end)'); + _log.add('onMicrotaskEmpty(end)'); + } }); macroTask(() => { @@ -525,18 +549,20 @@ function commonTests() { }); var ran = false; - ObservableWrapper.subscribe(_zone.onMicrotaskEmpty, (_) => { - _log.add('onMicrotaskEmpty(begin)'); - if (!ran) { - _log.add('onMicrotaskEmpty(scheduleMicroTask)'); - _zone.run(() => { - scheduleMicroTask(() => { - ran = true; - _log.add('onMicrotaskEmpty(executeMicrotask)'); + _zone.onMicrotaskEmpty.subscribe({ + next: () => { + _log.add('onMicrotaskEmpty(begin)'); + if (!ran) { + _log.add('onMicrotaskEmpty(scheduleMicroTask)'); + _zone.run(() => { + scheduleMicroTask(() => { + ran = true; + _log.add('onMicrotaskEmpty(executeMicrotask)'); + }); }); - }); + } + _log.add('onMicrotaskEmpty(end)'); } - _log.add('onMicrotaskEmpty(end)'); }); macroTask(() => { @@ -555,11 +581,11 @@ function commonTests() { runNgZoneNoLog(() => { macroTask(() => { _log.add('run start'); - PromiseWrapper.resolve(null) + resolvedPromise .then((_) => { _log.add('promise then'); - PromiseWrapper.resolve(null).then(_log.fn('promise foo')); - return PromiseWrapper.resolve(null); + resolvedPromise.then(_log.fn('promise foo')); + return Promise.resolve(null); }) .then(_log.fn('promise bar')); _log.add('run end'); @@ -569,24 +595,28 @@ function commonTests() { var donePromiseRan = false; var startPromiseRan = false; - ObservableWrapper.subscribe(_zone.onUnstable, (_) => { - _log.add('onUnstable(begin)'); - if (!startPromiseRan) { - _log.add('onUnstable(schedulePromise)'); - _zone.run(() => { scheduleMicroTask(_log.fn('onUnstable(executePromise)')); }); - startPromiseRan = true; + _zone.onUnstable.subscribe({ + next: () => { + _log.add('onUnstable(begin)'); + if (!startPromiseRan) { + _log.add('onUnstable(schedulePromise)'); + _zone.run(() => { scheduleMicroTask(_log.fn('onUnstable(executePromise)')); }); + startPromiseRan = true; + } + _log.add('onUnstable(end)'); } - _log.add('onUnstable(end)'); }); - ObservableWrapper.subscribe(_zone.onMicrotaskEmpty, (_) => { - _log.add('onMicrotaskEmpty(begin)'); - if (!donePromiseRan) { - _log.add('onMicrotaskEmpty(schedulePromise)'); - _zone.run(() => { scheduleMicroTask(_log.fn('onMicrotaskEmpty(executePromise)')); }); - donePromiseRan = true; + _zone.onMicrotaskEmpty.subscribe({ + next: () => { + _log.add('onMicrotaskEmpty(begin)'); + if (!donePromiseRan) { + _log.add('onMicrotaskEmpty(schedulePromise)'); + _zone.run(() => { scheduleMicroTask(_log.fn('onMicrotaskEmpty(executePromise)')); }); + donePromiseRan = true; + } + _log.add('onMicrotaskEmpty(end)'); } - _log.add('onMicrotaskEmpty(end)'); }); macroTask(() => { @@ -608,22 +638,24 @@ function commonTests() { it('should call onUnstable and onMicrotaskEmpty before and after each turn, respectively', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - var completerA: PromiseCompleter; - var completerB: PromiseCompleter; + var aResolve: (result: string) => void; + var aPromise: Promise; + var bResolve: (result: string) => void; + var bPromise: Promise; runNgZoneNoLog(() => { macroTask(() => { - completerA = PromiseWrapper.completer(); - completerB = PromiseWrapper.completer(); - completerA.promise.then(_log.fn('a then')); - completerB.promise.then(_log.fn('b then')); + aPromise = new Promise(res => { aResolve = res; }); + bPromise = new Promise(res => { bResolve = res; }); + aPromise.then(_log.fn('a then')); + bPromise.then(_log.fn('b then')); _log.add('run start'); }); }); - runNgZoneNoLog(() => { macroTask(() => { completerA.resolve(null); }, 10); }); + runNgZoneNoLog(() => { macroTask(() => { aResolve(null); }, 10); }); - runNgZoneNoLog(() => { macroTask(() => { completerB.resolve(null); }, 20); }); + runNgZoneNoLog(() => { macroTask(() => { bResolve(null); }, 20); }); macroTask(() => { expect(_log.result()) @@ -665,9 +697,8 @@ function commonTests() { runNgZoneNoLog(() => { macroTask(() => { - _zone.runOutsideAngular(() => { - promise = PromiseWrapper.resolve(4).then((x) => PromiseWrapper.resolve(x)); - }); + _zone.runOutsideAngular( + () => { promise = Promise.resolve(4).then((x) => Promise.resolve(x)); }); promise.then(_log.fn('promise then')); _log.add('zone run'); diff --git a/modules/@angular/core/testing/async_test_completer.ts b/modules/@angular/core/testing/async_test_completer.ts index 88dc953f09..767017bfa8 100644 --- a/modules/@angular/core/testing/async_test_completer.ts +++ b/modules/@angular/core/testing/async_test_completer.ts @@ -6,16 +6,19 @@ * found in the LICENSE file at https://angular.io/license */ -import {PromiseCompleter} from '../src/facade/promise'; - /** * Injectable completer that allows signaling completion of an asynchronous test. Used internally. */ export class AsyncTestCompleter { - private _completer = new PromiseCompleter(); - done(value?: any) { this._completer.resolve(value); } + private _resolve: (result: any) => void; + private _reject: (err: any) => void; + private _promise: Promise = new Promise((res, rej) => { + this._resolve = res; + this._reject = rej; + }); + done(value?: any) { this._resolve(value); } - fail(error?: any, stackTrace?: string) { this._completer.reject(error, stackTrace); } + fail(error?: any, stackTrace?: string) { this._reject(error); } - get promise(): Promise { return this._completer.promise; } + get promise(): Promise { return this._promise; } } diff --git a/modules/@angular/core/testing/component_fixture.ts b/modules/@angular/core/testing/component_fixture.ts index 4cb90592f8..9741e46718 100644 --- a/modules/@angular/core/testing/component_fixture.ts +++ b/modules/@angular/core/testing/component_fixture.ts @@ -7,7 +7,6 @@ */ import {AnimationEntryMetadata, ChangeDetectorRef, ComponentFactory, ComponentRef, ComponentResolver, DebugElement, ElementRef, Injectable, Injector, NgZone, NgZoneError, OpaqueToken, ViewMetadata, getDebugNode} from '../index'; -import {ObservableWrapper, PromiseCompleter, PromiseWrapper} from '../src/facade/async'; import {BaseException} from '../src/facade/exceptions'; import {scheduleMicroTask} from '../src/facade/lang'; @@ -58,7 +57,8 @@ export class ComponentFixture { private _autoDetect: boolean; private _isStable: boolean = true; - private _completer: PromiseCompleter = null; + private _resolve: (result: any) => void; + private _promise: Promise = null; private _onUnstableSubscription: any /** TODO #9100 */ = null; private _onStableSubscription: any /** TODO #9100 */ = null; private _onMicrotaskEmptySubscription: any /** TODO #9100 */ = null; @@ -76,35 +76,39 @@ export class ComponentFixture { if (ngZone != null) { this._onUnstableSubscription = - ObservableWrapper.subscribe(ngZone.onUnstable, (_) => { this._isStable = false; }); - this._onMicrotaskEmptySubscription = - ObservableWrapper.subscribe(ngZone.onMicrotaskEmpty, (_) => { - if (this._autoDetect) { - // Do a change detection run with checkNoChanges set to true to check - // there are no changes on the second run. - this.detectChanges(true); - } - }); - this._onStableSubscription = ObservableWrapper.subscribe(ngZone.onStable, (_) => { - this._isStable = true; - // Check whether there is a pending whenStable() completer to resolve. - if (this._completer !== null) { - // If so check whether there are no pending macrotasks before resolving. - // Do this check in the next tick so that ngZone gets a chance to update the state of - // pending macrotasks. - scheduleMicroTask(() => { - if (!this.ngZone.hasPendingMacrotasks) { - if (this._completer !== null) { - this._completer.resolve(true); - this._completer = null; + ngZone.onUnstable.subscribe({next: () => { this._isStable = false; }}); + this._onMicrotaskEmptySubscription = ngZone.onMicrotaskEmpty.subscribe({ + next: () => { + if (this._autoDetect) { + // Do a change detection run with checkNoChanges set to true to check + // there are no changes on the second run. + this.detectChanges(true); + } + } + }); + this._onStableSubscription = ngZone.onStable.subscribe({ + next: () => { + this._isStable = true; + // Check whether there is a pending whenStable() completer to resolve. + if (this._promise !== null) { + // If so check whether there are no pending macrotasks before resolving. + // Do this check in the next tick so that ngZone gets a chance to update the state of + // pending macrotasks. + scheduleMicroTask(() => { + if (!this.ngZone.hasPendingMacrotasks) { + if (this._promise !== null) { + this._resolve(true); + this._resolve = null; + this._promise = null; + } } - } - }); + }); + } } }); - this._onErrorSubscription = ObservableWrapper.subscribe( - ngZone.onError, (error: NgZoneError) => { throw error.error; }); + this._onErrorSubscription = + ngZone.onError.subscribe({next: (error: NgZoneError) => { throw error.error; }}); } } @@ -161,12 +165,12 @@ export class ComponentFixture { */ whenStable(): Promise { if (this.isStable()) { - return PromiseWrapper.resolve(false); - } else if (this._completer !== null) { - return this._completer.promise; + return Promise.resolve(false); + } else if (this._promise !== null) { + return this._promise; } else { - this._completer = new PromiseCompleter(); - return this._completer.promise; + this._promise = new Promise(res => { this._resolve = res; }); + return this._promise; } } @@ -176,19 +180,19 @@ export class ComponentFixture { destroy(): void { this.componentRef.destroy(); if (this._onUnstableSubscription != null) { - ObservableWrapper.dispose(this._onUnstableSubscription); + this._onUnstableSubscription.unsubscribe(); this._onUnstableSubscription = null; } if (this._onStableSubscription != null) { - ObservableWrapper.dispose(this._onStableSubscription); + this._onStableSubscription.unsubscribe(); this._onStableSubscription = null; } if (this._onMicrotaskEmptySubscription != null) { - ObservableWrapper.dispose(this._onMicrotaskEmptySubscription); + this._onMicrotaskEmptySubscription.unsubscribe(); this._onMicrotaskEmptySubscription = null; } if (this._onErrorSubscription != null) { - ObservableWrapper.dispose(this._onErrorSubscription); + this._onErrorSubscription.unsubscribe(); this._onErrorSubscription = null; } } diff --git a/modules/@angular/core/testing/ng_zone_mock.ts b/modules/@angular/core/testing/ng_zone_mock.ts index 02315d2ba3..7bf82c60d4 100644 --- a/modules/@angular/core/testing/ng_zone_mock.ts +++ b/modules/@angular/core/testing/ng_zone_mock.ts @@ -7,7 +7,7 @@ */ import {Injectable, NgZone} from '../index'; -import {EventEmitter, ObservableWrapper} from '../src/facade/async'; +import {EventEmitter} from '../src/facade/async'; /** * A mock implementation of {@link NgZone}. @@ -24,5 +24,5 @@ export class MockNgZone extends NgZone { runOutsideAngular(fn: Function): any { return fn(); } - simulateZoneExit(): void { ObservableWrapper.callNext(this.onStable, null); } + simulateZoneExit(): void { this.onStable.emit(null); } } diff --git a/modules/@angular/core/testing/test_component_builder.ts b/modules/@angular/core/testing/test_component_builder.ts index b3fe7c89e6..47e95a1c96 100644 --- a/modules/@angular/core/testing/test_component_builder.ts +++ b/modules/@angular/core/testing/test_component_builder.ts @@ -7,7 +7,6 @@ */ import {AnimationEntryMetadata, Compiler, ComponentFactory, Injectable, Injector, NgZone, OpaqueToken, ViewMetadata} from '../index'; -import {PromiseWrapper} from '../src/facade/async'; import {ConcreteType, Type, isPresent} from '../src/facade/lang'; import {ComponentFixture} from './component_fixture'; @@ -119,9 +118,9 @@ export class TestComponentBuilder { createFakeAsync(rootComponentType: ConcreteType): ComponentFixture { let result: any /** TODO #9100 */; let error: any /** TODO #9100 */; - PromiseWrapper.then( - this.createAsync(rootComponentType), (_result) => { result = _result; }, - (_error) => { error = _error; }); + + this.createAsync(rootComponentType) + .then((_result) => { result = _result; }, (_error) => { error = _error; }); tick(); if (isPresent(error)) { throw error; diff --git a/modules/@angular/facade/src/async.ts b/modules/@angular/facade/src/async.ts index 7909d20010..04f2272a6a 100644 --- a/modules/@angular/facade/src/async.ts +++ b/modules/@angular/facade/src/async.ts @@ -6,65 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ -import {Observable} from 'rxjs/Observable'; import {Subject} from 'rxjs/Subject'; -import {PromiseObservable} from 'rxjs/observable/PromiseObservable'; -import {toPromise} from 'rxjs/operator/toPromise'; import {global, noop} from './lang'; export {Observable} from 'rxjs/Observable'; export {Subject} from 'rxjs/Subject'; -export {PromiseCompleter, PromiseWrapper} from './promise'; - -export class TimerWrapper { - static setTimeout(fn: (...args: any[]) => void, millis: number): number { - return global.setTimeout(fn, millis); - } - static clearTimeout(id: number): void { global.clearTimeout(id); } - - static setInterval(fn: (...args: any[]) => void, millis: number): number { - return global.setInterval(fn, millis); - } - static clearInterval(id: number): void { global.clearInterval(id); } -} - -export class ObservableWrapper { - // TODO(vsavkin): when we use rxnext, try inferring the generic type from the first arg - static subscribe( - emitter: any, onNext: (value: T) => void, onError?: (exception: any) => void, - onComplete: () => void = () => {}): Object { - onError = (typeof onError === 'function') && onError || noop; - onComplete = (typeof onComplete === 'function') && onComplete || noop; - return emitter.subscribe({next: onNext, error: onError, complete: onComplete}); - } - - static isObservable(obs: any): boolean { return !!obs.subscribe; } - - /** - * Returns whether `obs` has any subscribers listening to events. - */ - static hasSubscribers(obs: EventEmitter): boolean { return obs.observers.length > 0; } - - static dispose(subscription: any) { subscription.unsubscribe(); } - - /** - * @deprecated - use callEmit() instead - */ - static callNext(emitter: EventEmitter, value: any) { emitter.emit(value); } - - static callEmit(emitter: EventEmitter, value: any) { emitter.emit(value); } - - static callError(emitter: EventEmitter, error: any) { emitter.error(error); } - - static callComplete(emitter: EventEmitter) { emitter.complete(); } - - static fromPromise(promise: Promise): Observable { - return PromiseObservable.create(promise); - } - - static toPromise(obj: Observable): Promise { return toPromise.call(obj); } -} /** * Use by directives and components to emit custom Events. diff --git a/modules/@angular/facade/src/promise.ts b/modules/@angular/facade/src/promise.ts deleted file mode 100644 index 04300155fc..0000000000 --- a/modules/@angular/facade/src/promise.ts +++ /dev/null @@ -1,61 +0,0 @@ -/** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - - -export class PromiseCompleter { - promise: Promise; - resolve: (value?: R|PromiseLike) => void; - reject: (error?: any, stackTrace?: string) => void; - - constructor() { - this.promise = new Promise((res, rej) => { - this.resolve = res; - this.reject = rej; - }); - } -} - -export class PromiseWrapper { - static resolve(obj: T): Promise { return Promise.resolve(obj); } - - static reject(obj: any, _: any): Promise { return Promise.reject(obj); } - - // Note: We can't rename this method into `catch`, as this is not a valid - // method name in Dart. - static catchError(promise: Promise, onError: (error: any) => T | PromiseLike): - Promise { - return promise.catch(onError); - } - - static all(promises: (T|Promise)[]): Promise { - if (promises.length == 0) return Promise.resolve([]); - return Promise.all(promises); - } - - static then( - promise: Promise, success: (value: T) => U | PromiseLike, - rejection?: (error: any, stack?: any) => U | PromiseLike): Promise { - return promise.then(success, rejection); - } - - static wrap(computation: () => T): Promise { - return new Promise((res, rej) => { - try { - res(computation()); - } catch (e) { - rej(e); - } - }); - } - - static scheduleMicrotask(computation: () => any): void { - PromiseWrapper.then(PromiseWrapper.resolve(null), computation, (_) => {}); - } - - static completer(): PromiseCompleter { return new PromiseCompleter(); } -} diff --git a/modules/@angular/facade/test/async_spec.ts b/modules/@angular/facade/test/async_spec.ts index 5bf968c26d..09b4cac2f1 100644 --- a/modules/@angular/facade/test/async_spec.ts +++ b/modules/@angular/facade/test/async_spec.ts @@ -6,9 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, describe, it, expect, beforeEach, ddescribe, iit, xit, inject,} from '@angular/core/testing/testing_internal'; +import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; import {browserDetection} from '@angular/platform-browser/testing/browser_util'; -import {ObservableWrapper, Observable, Subject, EventEmitter, PromiseWrapper} from '../src/async'; +import {EventEmitter, Observable, Subject} from '../src/async'; export function main() { describe('EventEmitter', () => { @@ -18,82 +18,88 @@ export function main() { it('should call the next callback', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - ObservableWrapper.subscribe(emitter, (value) => { - expect(value).toEqual(99); - async.done(); + emitter.subscribe({ + next: (value: any) => { + expect(value).toEqual(99); + async.done(); + } }); - - ObservableWrapper.callEmit(emitter, 99); + emitter.emit(99); })); it('should call the throw callback', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - ObservableWrapper.subscribe(emitter, (_) => {}, (error) => { - expect(error).toEqual('Boom'); - async.done(); + emitter.subscribe({ + next: () => {}, + error: (error: any) => { + expect(error).toEqual('Boom'); + async.done(); + } }); - ObservableWrapper.callError(emitter, 'Boom'); + emitter.error('Boom'); })); it('should work when no throw callback is provided', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - ObservableWrapper.subscribe(emitter, (_) => {}, (_) => { async.done(); }); - ObservableWrapper.callError(emitter, 'Boom'); + emitter.subscribe({next: () => {}, error: (_: any) => { async.done(); }}); + emitter.error('Boom'); })); it('should call the return callback', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - ObservableWrapper.subscribe(emitter, (_) => {}, (_) => {}, () => { async.done(); }); - - ObservableWrapper.callComplete(emitter); + emitter.subscribe( + {next: () => {}, error: (_: any) => {}, complete: () => { async.done(); }}); + emitter.complete(); })); it('should subscribe to the wrapper synchronously', () => { var called = false; - ObservableWrapper.subscribe(emitter, (value) => { called = true; }); + emitter.subscribe({next: (value: any) => { called = true; }}); + emitter.emit(99); - ObservableWrapper.callEmit(emitter, 99); expect(called).toBe(true); }); it('delivers next and error events synchronously', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { let log: any[] /** TODO #9100 */ = []; - ObservableWrapper.subscribe( - emitter, - (x) => { - log.push(x); - expect(log).toEqual([1, 2]); - }, - (err) => { - log.push(err); - expect(log).toEqual([1, 2, 3, 4]); - async.done(); - }); + + emitter.subscribe({ + next: (x: any) => { + log.push(x); + expect(log).toEqual([1, 2]); + }, + error: (err: any) => { + log.push(err); + expect(log).toEqual([1, 2, 3, 4]); + async.done(); + } + }); log.push(1); - ObservableWrapper.callEmit(emitter, 2); + emitter.emit(2); log.push(3); - ObservableWrapper.callError(emitter, 4); + emitter.error(4); log.push(5); })); it('delivers next and complete events synchronously', () => { let log: any[] /** TODO #9100 */ = []; - ObservableWrapper.subscribe( - emitter, - (x) => { - log.push(x); - expect(log).toEqual([1, 2]); - }, - null, - () => { - log.push(4); - expect(log).toEqual([1, 2, 3, 4]); - }); + + emitter.subscribe({ + next: (x: any) => { + log.push(x); + expect(log).toEqual([1, 2]); + }, + error: null, + complete: () => { + log.push(4); + expect(log).toEqual([1, 2, 3, 4]); + } + }); log.push(1); - ObservableWrapper.callEmit(emitter, 2); + emitter.emit(2); log.push(3); - ObservableWrapper.callComplete(emitter); + emitter.complete(); log.push(5); expect(log).toEqual([1, 2, 3, 4, 5]); }); @@ -102,22 +108,22 @@ export function main() { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { var e = new EventEmitter(true); var log: any[] /** TODO #9100 */ = []; - ObservableWrapper.subscribe(e, (x) => { + e.subscribe((x: any) => { log.push(x); expect(log).toEqual([1, 3, 2]); async.done(); }); log.push(1); - ObservableWrapper.callEmit(e, 2); + e.emit(2); log.push(3); })); it('reports whether it has subscribers', () => { var e = new EventEmitter(false); - expect(ObservableWrapper.hasSubscribers(e)).toBe(false); - ObservableWrapper.subscribe(e, (_) => {}); - expect(ObservableWrapper.hasSubscribers(e)).toBe(true); + expect(e.observers.length > 0).toBe(false); + e.subscribe({next: () => {}}); + expect(e.observers.length > 0).toBe(true); }); // TODO: vsavkin: add tests cases @@ -125,71 +131,4 @@ export function main() { // should call dispose on the subscription on throw // should call dispose on the subscription on return }); - - describe('ObservableWrapper', () => { - - it('should correctly check isObservable for EventEmitter', () => { - var e = new EventEmitter(false); - expect(ObservableWrapper.isObservable(e)).toBe(true); - }); - - it('should correctly check isObservable for Subject', () => { - var e = new Subject(); - expect(ObservableWrapper.isObservable(e)).toBe(true); - }); - - it('should subscribe to EventEmitters', () => { - let e = new EventEmitter(false); - - ObservableWrapper.subscribe(e, (val) => {}); - - ObservableWrapper.callEmit(e, 1); - ObservableWrapper.callComplete(e); - }); - - }); - - // See ECMAScript 6 Spec 25.4.4.1 - describe('PromiseWrapper', () => { - describe('#all', () => { - it('should combine lists of Promises', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - var one = PromiseWrapper.completer(); - var two = PromiseWrapper.completer(); - - var all = PromiseWrapper.all([one.promise, two.promise]); - var allCalled = false; - - PromiseWrapper.then(one.promise, (_) => { - expect(allCalled).toBe(false); - two.resolve('two'); - return null; - }); - - PromiseWrapper.then(all, (_) => { - allCalled = true; - async.done(); - return null; - }); - - one.resolve('one'); - })); - - [null, true, false, 10, 'thing', {}, []].forEach(abruptCompletion => { - it(`should treat "${abruptCompletion}" as an "abrupt completion"`, - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - var one = PromiseWrapper.completer(); - - var all = PromiseWrapper.all([one.promise, abruptCompletion]); - - PromiseWrapper.then(all, (val) => { - expect(val[1]).toEqual(abruptCompletion); - async.done(); - }); - - one.resolve('one'); - })); - }); - }); - }); } diff --git a/modules/@angular/forms/src/directives/ng_form.ts b/modules/@angular/forms/src/directives/ng_form.ts index 058d64fd81..99ff59147a 100644 --- a/modules/@angular/forms/src/directives/ng_form.ts +++ b/modules/@angular/forms/src/directives/ng_form.ts @@ -8,7 +8,7 @@ import {Directive, Inject, Optional, Self, forwardRef} from '@angular/core'; -import {EventEmitter, ObservableWrapper, PromiseWrapper} from '../facade/async'; +import {EventEmitter} from '../facade/async'; import {ListWrapper} from '../facade/collection'; import {isPresent} from '../facade/lang'; import {AbstractControl, FormControl, FormGroup} from '../model'; @@ -26,6 +26,8 @@ export const formDirectiveProvider: any = { useExisting: forwardRef(() => NgForm) }; +const resolvedPromise = Promise.resolve(null); + /** * If `NgForm` is bound in a component, `` elements in that component will be * upgraded to use the Angular form system. @@ -117,7 +119,7 @@ export class NgForm extends ControlContainer implements Form { get controls(): {[key: string]: AbstractControl} { return this.form.controls; } addControl(dir: NgModel): void { - PromiseWrapper.scheduleMicrotask(() => { + resolvedPromise.then(() => { const container = this._findContainer(dir.path); dir._control = container.registerControl(dir.name, dir.control); setUpControl(dir.control, dir); @@ -128,7 +130,7 @@ export class NgForm extends ControlContainer implements Form { getControl(dir: NgModel): FormControl { return this.form.find(dir.path); } removeControl(dir: NgModel): void { - PromiseWrapper.scheduleMicrotask(() => { + resolvedPromise.then(() => { var container = this._findContainer(dir.path); if (isPresent(container)) { container.removeControl(dir.name); @@ -137,7 +139,7 @@ export class NgForm extends ControlContainer implements Form { } addFormGroup(dir: NgModelGroup): void { - PromiseWrapper.scheduleMicrotask(() => { + resolvedPromise.then(() => { var container = this._findContainer(dir.path); var group = new FormGroup({}); setUpFormContainer(group, dir); @@ -147,7 +149,7 @@ export class NgForm extends ControlContainer implements Form { } removeFormGroup(dir: NgModelGroup): void { - PromiseWrapper.scheduleMicrotask(() => { + resolvedPromise.then(() => { var container = this._findContainer(dir.path); if (isPresent(container)) { container.removeControl(dir.name); @@ -158,7 +160,7 @@ export class NgForm extends ControlContainer implements Form { getFormGroup(dir: NgModelGroup): FormGroup { return this.form.find(dir.path); } updateModel(dir: NgControl, value: any): void { - PromiseWrapper.scheduleMicrotask(() => { + resolvedPromise.then(() => { var ctrl = this.form.find(dir.path); ctrl.updateValue(value); }); @@ -168,7 +170,7 @@ export class NgForm extends ControlContainer implements Form { onSubmit(): boolean { this._submitted = true; - ObservableWrapper.callEmit(this.ngSubmit, null); + this.ngSubmit.emit(null); return false; } diff --git a/modules/@angular/forms/src/directives/ng_model.ts b/modules/@angular/forms/src/directives/ng_model.ts index e75042d8b0..1553158f1e 100644 --- a/modules/@angular/forms/src/directives/ng_model.ts +++ b/modules/@angular/forms/src/directives/ng_model.ts @@ -8,7 +8,7 @@ import {Directive, Host, Inject, Input, OnChanges, OnDestroy, Optional, Output, Self, SimpleChanges, forwardRef} from '@angular/core'; -import {EventEmitter, ObservableWrapper, PromiseWrapper} from '../facade/async'; +import {EventEmitter} from '../facade/async'; import {BaseException} from '../facade/exceptions'; import {FormControl} from '../model'; import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators'; @@ -28,6 +28,8 @@ export const formControlBinding: any = { useExisting: forwardRef(() => NgModel) }; +const resolvedPromise = Promise.resolve(null); + /** * Binds a domain model to a form control. * @@ -105,7 +107,7 @@ export class NgModel extends NgControl implements OnChanges, viewToModelUpdate(newValue: any): void { this.viewModel = newValue; - ObservableWrapper.callEmit(this.update, newValue); + this.update.emit(newValue); } private _setUpControl(): void { @@ -149,7 +151,7 @@ export class NgModel extends NgControl implements OnChanges, } private _updateValue(value: any): void { - PromiseWrapper.scheduleMicrotask( + resolvedPromise.then( () => { this.control.updateValue(value, {emitViewToModelChange: false}); }); } } diff --git a/modules/@angular/forms/src/directives/reactive_directives/form_control_directive.ts b/modules/@angular/forms/src/directives/reactive_directives/form_control_directive.ts index c8e174bc22..69fd52391e 100644 --- a/modules/@angular/forms/src/directives/reactive_directives/form_control_directive.ts +++ b/modules/@angular/forms/src/directives/reactive_directives/form_control_directive.ts @@ -8,7 +8,7 @@ import {Directive, Inject, Input, OnChanges, Optional, Output, Self, SimpleChanges, forwardRef} from '@angular/core'; -import {EventEmitter, ObservableWrapper} from '../../facade/async'; +import {EventEmitter} from '../../facade/async'; import {StringMapWrapper} from '../../facade/collection'; import {FormControl} from '../../model'; import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../../validators'; @@ -110,7 +110,7 @@ export class FormControlDirective extends NgControl implements OnChanges { viewToModelUpdate(newValue: any): void { this.viewModel = newValue; - ObservableWrapper.callEmit(this.update, newValue); + this.update.emit(newValue); } private _isControlChanged(changes: {[key: string]: any}): boolean { diff --git a/modules/@angular/forms/src/directives/reactive_directives/form_control_name.ts b/modules/@angular/forms/src/directives/reactive_directives/form_control_name.ts index e1a3786c2b..63079d87d1 100644 --- a/modules/@angular/forms/src/directives/reactive_directives/form_control_name.ts +++ b/modules/@angular/forms/src/directives/reactive_directives/form_control_name.ts @@ -8,7 +8,7 @@ import {Directive, Host, Inject, Input, OnChanges, OnDestroy, Optional, Output, Self, SimpleChanges, SkipSelf, forwardRef} from '@angular/core'; -import {EventEmitter, ObservableWrapper} from '../../facade/async'; +import {EventEmitter} from '../../facade/async'; import {FormControl} from '../../model'; import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../../validators'; import {AbstractFormGroupDirective} from '../abstract_form_group_directive'; @@ -134,7 +134,7 @@ export class FormControlName extends NgControl implements OnChanges, OnDestroy { viewToModelUpdate(newValue: any): void { this.viewModel = newValue; - ObservableWrapper.callEmit(this.update, newValue); + this.update.emit(newValue); } get path(): string[] { return controlPath(this.name, this._parent); } diff --git a/modules/@angular/forms/src/directives/reactive_directives/form_group_directive.ts b/modules/@angular/forms/src/directives/reactive_directives/form_group_directive.ts index 26281c7f04..c801ddba96 100644 --- a/modules/@angular/forms/src/directives/reactive_directives/form_group_directive.ts +++ b/modules/@angular/forms/src/directives/reactive_directives/form_group_directive.ts @@ -8,7 +8,7 @@ import {Directive, Inject, Input, OnChanges, Optional, Output, Self, SimpleChanges, forwardRef} from '@angular/core'; -import {EventEmitter, ObservableWrapper} from '../../facade/async'; +import {EventEmitter} from '../../facade/async'; import {ListWrapper, StringMapWrapper} from '../../facade/collection'; import {BaseException} from '../../facade/exceptions'; import {isBlank} from '../../facade/lang'; @@ -182,7 +182,7 @@ export class FormGroupDirective extends ControlContainer implements Form, onSubmit(): boolean { this._submitted = true; - ObservableWrapper.callEmit(this.ngSubmit, null); + this.ngSubmit.emit(null); return false; } diff --git a/modules/@angular/forms/src/model.ts b/modules/@angular/forms/src/model.ts index 939970c3ba..54413d5180 100644 --- a/modules/@angular/forms/src/model.ts +++ b/modules/@angular/forms/src/model.ts @@ -6,14 +6,17 @@ * found in the LICENSE file at https://angular.io/license */ +import {PromiseObservable} from 'rxjs/observable/PromiseObservable'; + import {composeAsyncValidators, composeValidators} from './directives/shared'; import {AsyncValidatorFn, ValidatorFn} from './directives/validators'; -import {EventEmitter, Observable, ObservableWrapper} from './facade/async'; +import {EventEmitter, Observable} from './facade/async'; import {ListWrapper, StringMapWrapper} from './facade/collection'; import {BaseException} from './facade/exceptions'; import {isBlank, isPresent, isPromise, normalizeBool} from './facade/lang'; + /** * Indicates that a FormControl is valid, i.e. that no errors exist in the input value. */ @@ -55,7 +58,7 @@ function _find(control: AbstractControl, path: Array| string, del } function toObservable(r: any): Observable { - return isPromise(r) ? ObservableWrapper.fromPromise(r) : r; + return isPromise(r) ? PromiseObservable.create(r) : r; } function coerceToValidator(validator: ValidatorFn | ValidatorFn[]): ValidatorFn { @@ -193,8 +196,8 @@ export abstract class AbstractControl { } if (emitEvent) { - ObservableWrapper.callEmit(this._valueChanges, this._value); - ObservableWrapper.callEmit(this._statusChanges, this._status); + this._valueChanges.emit(this._value); + this._statusChanges.emit(this._status); } if (isPresent(this._parent) && !onlySelf) { @@ -211,14 +214,14 @@ export abstract class AbstractControl { this._status = PENDING; this._cancelExistingSubscription(); var obs = toObservable(this.asyncValidator(this)); - this._asyncValidationSubscription = ObservableWrapper.subscribe( - obs, (res: {[key: string]: any}) => this.setErrors(res, {emitEvent: emitEvent})); + this._asyncValidationSubscription = obs.subscribe( + {next: (res: {[key: string]: any}) => this.setErrors(res, {emitEvent: emitEvent})}); } } private _cancelExistingSubscription(): void { if (isPresent(this._asyncValidationSubscription)) { - ObservableWrapper.dispose(this._asyncValidationSubscription); + this._asyncValidationSubscription.unsubscribe(); } } @@ -287,7 +290,7 @@ export abstract class AbstractControl { this._status = this._calculateStatus(); if (emitEvent) { - ObservableWrapper.callEmit(this._statusChanges, this._status); + this._statusChanges.emit(this._status); } if (isPresent(this._parent)) { diff --git a/modules/@angular/forms/src/validators.ts b/modules/@angular/forms/src/validators.ts index a6951fb6ff..8c0e32d3c1 100644 --- a/modules/@angular/forms/src/validators.ts +++ b/modules/@angular/forms/src/validators.ts @@ -7,13 +7,14 @@ */ import {OpaqueToken} from '@angular/core'; +import {toPromise} from 'rxjs/operator/toPromise'; + import {AsyncValidatorFn, ValidatorFn} from './directives/validators'; -import {ObservableWrapper} from './facade/async'; import {StringMapWrapper} from './facade/collection'; import {isBlank, isPresent, isPromise, isString} from './facade/lang'; -import {PromiseWrapper} from './facade/promise'; import {AbstractControl} from './model'; + /** * Providers for validators to be used for {@link FormControl}s in a form. * @@ -127,13 +128,13 @@ export class Validators { return function(control: AbstractControl) { let promises = _executeAsyncValidators(control, presentValidators).map(_convertToPromise); - return PromiseWrapper.all(promises).then(_mergeErrors); + return Promise.all(promises).then(_mergeErrors); }; } } function _convertToPromise(obj: any): Promise { - return isPromise(obj) ? obj : ObservableWrapper.toPromise(obj); + return isPromise(obj) ? obj : toPromise.call(obj); } function _executeValidators(control: AbstractControl, validators: ValidatorFn[]): any[] { diff --git a/modules/@angular/forms/test/directives_spec.ts b/modules/@angular/forms/test/directives_spec.ts index 5c7c6cfa87..e90cd9267a 100644 --- a/modules/@angular/forms/test/directives_spec.ts +++ b/modules/@angular/forms/test/directives_spec.ts @@ -6,19 +6,14 @@ * found in the LICENSE file at https://angular.io/license */ +import {SimpleChange} from '@angular/core/src/change_detection'; +import {fakeAsync, flushMicrotasks, tick} from '@angular/core/testing'; import {Log, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; - -import {fakeAsync, flushMicrotasks, tick,} from '@angular/core/testing'; +import {CheckboxControlValueAccessor, ControlValueAccessor, DefaultValueAccessor, FormArray, FormArrayName, FormControl, FormControlDirective, FormControlName, FormGroup, FormGroupDirective, FormGroupName, NgControl, NgForm, NgModel, NgModelGroup, SelectControlValueAccessor, SelectMultipleControlValueAccessor, Validator, Validators} from '@angular/forms'; +import {composeValidators, selectValueAccessor} from '@angular/forms/src/directives/shared'; import {SpyNgControl, SpyValueAccessor} from './spies'; -import {FormGroup, FormControl, FormArray, FormArrayName, FormControlName, FormGroupName, NgModelGroup, FormGroupDirective, ControlValueAccessor, Validators, NgForm, NgModel, FormControlDirective, NgControl, DefaultValueAccessor, CheckboxControlValueAccessor, SelectControlValueAccessor, SelectMultipleControlValueAccessor, Validator} from '@angular/forms'; - -import {selectValueAccessor, composeValidators} from '@angular/forms/src/directives/shared'; -import {TimerWrapper} from '../src/facade/async'; -import {PromiseWrapper} from '../src/facade/promise'; -import {SimpleChange} from '@angular/core/src/change_detection'; - class DummyControlValueAccessor implements ControlValueAccessor { writtenValue: any; @@ -34,14 +29,15 @@ class CustomValidatorDirective implements Validator { function asyncValidator(expected: any /** TODO #9100 */, timeout = 0) { return (c: any /** TODO #9100 */) => { - var completer = PromiseWrapper.completer(); + var resolve: (result: any) => void; + var promise = new Promise(res => { resolve = res; }); var res = c.value != expected ? {'async': true} : null; if (timeout == 0) { - completer.resolve(res); + resolve(res); } else { - TimerWrapper.setTimeout(() => { completer.resolve(res); }, timeout); + setTimeout(() => { resolve(res); }, timeout); } - return completer.promise; + return promise; }; } diff --git a/modules/@angular/forms/test/form_builder_spec.ts b/modules/@angular/forms/test/form_builder_spec.ts index bbc3e37d00..699771f4b8 100644 --- a/modules/@angular/forms/test/form_builder_spec.ts +++ b/modules/@angular/forms/test/form_builder_spec.ts @@ -9,11 +9,9 @@ import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from '@angular/core/testing/testing_internal'; import {FormBuilder, FormControl} from '@angular/forms'; -import {PromiseWrapper} from '../src/facade/promise'; - export function main() { function syncValidator(_: any /** TODO #9100 */): any /** TODO #9100 */ { return null; } - function asyncValidator(_: any /** TODO #9100 */) { return PromiseWrapper.resolve(null); } + function asyncValidator(_: any /** TODO #9100 */) { return Promise.resolve(null); } describe('Form Builder', () => { var b: any /** TODO #9100 */; diff --git a/modules/@angular/forms/test/model_spec.ts b/modules/@angular/forms/test/model_spec.ts index d463e34e9b..f82fb4d7b5 100644 --- a/modules/@angular/forms/test/model_spec.ts +++ b/modules/@angular/forms/test/model_spec.ts @@ -10,36 +10,36 @@ import {fakeAsync, flushMicrotasks, tick} from '@angular/core/testing'; import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; import {FormArray, FormControl, FormGroup, Validators} from '@angular/forms'; -import {EventEmitter, ObservableWrapper, TimerWrapper} from '../src/facade/async'; +import {EventEmitter} from '../src/facade/async'; import {isPresent} from '../src/facade/lang'; -import {PromiseWrapper} from '../src/facade/promise'; export function main() { function asyncValidator(expected: any /** TODO #9100 */, timeouts = {}) { return (c: any /** TODO #9100 */) => { - var completer = PromiseWrapper.completer(); + var resolve: (result: any) => void; + var promise = new Promise(res => { resolve = res; }); var t = isPresent((timeouts as any /** TODO #9100 */)[c.value]) ? (timeouts as any /** TODO #9100 */)[c.value] : 0; var res = c.value != expected ? {'async': true} : null; if (t == 0) { - completer.resolve(res); + resolve(res); } else { - TimerWrapper.setTimeout(() => { completer.resolve(res); }, t); + setTimeout(() => { resolve(res); }, t); } - return completer.promise; + return promise; }; } function asyncValidatorReturningObservable(c: FormControl) { var e = new EventEmitter(); - PromiseWrapper.scheduleMicrotask(() => ObservableWrapper.callEmit(e, {'async': true})); + Promise.resolve(null).then(() => { e.emit({'async': true}); }); return e; } - function otherAsyncValidator() { return PromiseWrapper.resolve({'other': true}); } + function otherAsyncValidator() { return Promise.resolve({'other': true}); } describe('Form Model', () => { describe('FormControl', () => { @@ -295,15 +295,16 @@ export function main() { }); it('should fire an event', fakeAsync(() => { - ObservableWrapper.subscribe( - c.valueChanges, (value) => { expect(value).toEqual('newValue'); }); + + c.valueChanges.subscribe( + {next: (value: any) => { expect(value).toEqual('newValue'); }}); c.updateValue('newValue'); tick(); })); it('should not fire an event when explicitly specified', fakeAsync(() => { - ObservableWrapper.subscribe(c.valueChanges, (value) => { throw 'Should not happen'; }); + c.valueChanges.subscribe({next: (value: any) => { throw 'Should not happen'; }}); c.updateValue('newValue', {emitEvent: false}); @@ -442,18 +443,22 @@ export function main() { it('should fire an event after the value has been updated', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - ObservableWrapper.subscribe(c.valueChanges, (value) => { - expect(c.value).toEqual('new'); - expect(value).toEqual('new'); - async.done(); + c.valueChanges.subscribe({ + next: (value: any) => { + expect(c.value).toEqual('new'); + expect(value).toEqual('new'); + async.done(); + } }); c.updateValue('new'); })); it('should fire an event after the status has been updated to invalid', fakeAsync(() => { - ObservableWrapper.subscribe(c.statusChanges, (status) => { - expect(c.status).toEqual('INVALID'); - expect(status).toEqual('INVALID'); + c.statusChanges.subscribe({ + next: (status: any) => { + expect(c.status).toEqual('INVALID'); + expect(status).toEqual('INVALID'); + } }); c.updateValue(''); @@ -464,9 +469,9 @@ export function main() { var c = new FormControl('old', Validators.required, asyncValidator('expected')); var log: any[] /** TODO #9100 */ = []; - ObservableWrapper.subscribe(c.valueChanges, (value) => log.push(`value: '${value}'`)); - ObservableWrapper.subscribe( - c.statusChanges, (status) => log.push(`status: '${status}'`)); + c.valueChanges.subscribe({next: (value: any) => log.push(`value: '${value}'`)}); + + c.statusChanges.subscribe({next: (status: any) => log.push(`status: '${status}'`)}); c.updateValue(''); tick(); @@ -504,9 +509,11 @@ export function main() { it('should return a cold observable', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { c.updateValue('will be ignored'); - ObservableWrapper.subscribe(c.valueChanges, (value) => { - expect(value).toEqual('new'); - async.done(); + c.valueChanges.subscribe({ + next: (value: any) => { + expect(value).toEqual('new'); + async.done(); + } }); c.updateValue('new'); })); @@ -999,10 +1006,12 @@ export function main() { it('should fire an event after the value has been updated', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - ObservableWrapper.subscribe(g.valueChanges, (value) => { - expect(g.value).toEqual({'one': 'new1', 'two': 'old2'}); - expect(value).toEqual({'one': 'new1', 'two': 'old2'}); - async.done(); + g.valueChanges.subscribe({ + next: (value: any) => { + expect(g.value).toEqual({'one': 'new1', 'two': 'old2'}); + expect(value).toEqual({'one': 'new1', 'two': 'old2'}); + async.done(); + } }); c1.updateValue('new1'); })); @@ -1011,12 +1020,14 @@ export function main() { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { var controlCallbackIsCalled = false; - ObservableWrapper.subscribe( - c1.valueChanges, (value) => { controlCallbackIsCalled = true; }); - ObservableWrapper.subscribe(g.valueChanges, (value) => { - expect(controlCallbackIsCalled).toBe(true); - async.done(); + c1.valueChanges.subscribe({next: (value: any) => { controlCallbackIsCalled = true; }}); + + g.valueChanges.subscribe({ + next: (value: any) => { + expect(controlCallbackIsCalled).toBe(true); + async.done(); + } }); c1.updateValue('new1'); @@ -1024,9 +1035,11 @@ export function main() { it('should fire an event when a control is excluded', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - ObservableWrapper.subscribe(g.valueChanges, (value) => { - expect(value).toEqual({'one': 'old1'}); - async.done(); + g.valueChanges.subscribe({ + next: (value: any) => { + expect(value).toEqual({'one': 'old1'}); + async.done(); + } }); g.exclude('two'); @@ -1036,9 +1049,11 @@ export function main() { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { g.exclude('two'); - ObservableWrapper.subscribe(g.valueChanges, (value) => { - expect(value).toEqual({'one': 'old1', 'two': 'old2'}); - async.done(); + g.valueChanges.subscribe({ + next: (value: any) => { + expect(value).toEqual({'one': 'old1', 'two': 'old2'}); + async.done(); + } }); g.include('two'); @@ -1048,14 +1063,16 @@ export function main() { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { var loggedValues: any[] /** TODO #9100 */ = []; - ObservableWrapper.subscribe(g.valueChanges, (value) => { - loggedValues.push(value); + g.valueChanges.subscribe({ + next: (value: any) => { + loggedValues.push(value); - if (loggedValues.length == 2) { - expect(loggedValues).toEqual([ - {'one': 'new1', 'two': 'old2'}, {'one': 'new1', 'two': 'new2'} - ]); - async.done(); + if (loggedValues.length == 2) { + expect(loggedValues).toEqual([ + {'one': 'new1', 'two': 'old2'}, {'one': 'new1', 'two': 'new2'} + ]); + async.done(); + } } }); @@ -1075,12 +1092,14 @@ export function main() { it('should fire a statusChange if child has async validation change', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { const loggedValues: string[] = []; - ObservableWrapper.subscribe(group.statusChanges, (status: string) => { - loggedValues.push(status); - if (loggedValues.length === 2) { - expect(loggedValues).toEqual(['PENDING', 'INVALID']); + group.statusChanges.subscribe({ + next: (status: string) => { + loggedValues.push(status); + if (loggedValues.length === 2) { + expect(loggedValues).toEqual(['PENDING', 'INVALID']); + } + async.done(); } - async.done(); }); control.updateValue(''); })); @@ -1545,10 +1564,12 @@ export function main() { it('should fire an event after the value has been updated', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - ObservableWrapper.subscribe(a.valueChanges, (value) => { - expect(a.value).toEqual(['new1', 'old2']); - expect(value).toEqual(['new1', 'old2']); - async.done(); + a.valueChanges.subscribe({ + next: (value: any) => { + expect(a.value).toEqual(['new1', 'old2']); + expect(value).toEqual(['new1', 'old2']); + async.done(); + } }); c1.updateValue('new1'); })); @@ -1557,12 +1578,14 @@ export function main() { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { var controlCallbackIsCalled = false; - ObservableWrapper.subscribe( - c1.valueChanges, (value) => { controlCallbackIsCalled = true; }); - ObservableWrapper.subscribe(a.valueChanges, (value) => { - expect(controlCallbackIsCalled).toBe(true); - async.done(); + c1.valueChanges.subscribe({next: (value: any) => { controlCallbackIsCalled = true; }}); + + a.valueChanges.subscribe({ + next: (value: any) => { + expect(controlCallbackIsCalled).toBe(true); + async.done(); + } }); c1.updateValue('new1'); @@ -1570,9 +1593,11 @@ export function main() { it('should fire an event when a control is removed', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - ObservableWrapper.subscribe(a.valueChanges, (value) => { - expect(value).toEqual(['old1']); - async.done(); + a.valueChanges.subscribe({ + next: (value: any) => { + expect(value).toEqual(['old1']); + async.done(); + } }); a.removeAt(1); @@ -1582,9 +1607,11 @@ export function main() { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { a.removeAt(1); - ObservableWrapper.subscribe(a.valueChanges, (value) => { - expect(value).toEqual(['old1', 'old2']); - async.done(); + a.valueChanges.subscribe({ + next: (value: any) => { + expect(value).toEqual(['old1', 'old2']); + async.done(); + } }); a.push(c2); diff --git a/modules/@angular/forms/test/reactive_integration_spec.ts b/modules/@angular/forms/test/reactive_integration_spec.ts index 4b63a473a6..fd11273f42 100644 --- a/modules/@angular/forms/test/reactive_integration_spec.ts +++ b/modules/@angular/forms/test/reactive_integration_spec.ts @@ -15,9 +15,7 @@ import {By} from '@angular/platform-browser/src/dom/debug/by'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {dispatchEvent} from '@angular/platform-browser/testing/browser_util'; -import {ObservableWrapper} from '../src/facade/async'; import {ListWrapper} from '../src/facade/collection'; -import {PromiseWrapper} from '../src/facade/promise'; export function main() { describe('reactive forms integration tests', () => { @@ -85,8 +83,8 @@ export function main() { input.nativeElement.value = 'updatedValue'; - ObservableWrapper.subscribe( - form.valueChanges, (value) => { throw 'Should not happen'; }); + + form.valueChanges.subscribe({next: (value) => { throw 'Should not happen'; }}); dispatchEvent(input.nativeElement, 'change'); async.done(); @@ -894,11 +892,13 @@ export function main() { expect(input.componentInstance.value).toEqual('!aa!'); input.componentInstance.value = '!bb!'; - ObservableWrapper.subscribe(input.componentInstance.onInput, (value) => { - expect(fixture.debugElement.componentInstance.form.value).toEqual({ - 'name': 'bb' - }); - async.done(); + input.componentInstance.onInput.subscribe({ + next: (value: any) => { + expect(fixture.debugElement.componentInstance.form.value).toEqual({ + 'name': 'bb' + }); + async.done(); + } }); input.componentInstance.dispatchChangeEvent(); }); @@ -1360,7 +1360,6 @@ export function main() { tcb.overrideTemplate(MyComp8, t).createAsync(MyComp8).then((fixture) => { fixture.debugElement.componentInstance.myGroup = new FormGroup({}); - ; expect(() => fixture.detectChanges()) .toThrowError(new RegExp( `ngModel cannot be used to register form controls with a parent formGroup directive.`)); @@ -1475,21 +1474,20 @@ class MyInput implements ControlValueAccessor { writeValue(value: any /** TODO #9100 */) { this.value = `!${value}!`; } - registerOnChange(fn: any /** TODO #9100 */) { ObservableWrapper.subscribe(this.onInput, fn); } + registerOnChange(fn: any /** TODO #9100 */) { this.onInput.subscribe({next: fn}); } registerOnTouched(fn: any /** TODO #9100 */) {} - dispatchChangeEvent() { - ObservableWrapper.callEmit(this.onInput, this.value.substring(1, this.value.length - 1)); - } + dispatchChangeEvent() { this.onInput.emit(this.value.substring(1, this.value.length - 1)); } } function uniqLoginAsyncValidator(expectedValue: string) { return (c: any /** TODO #9100 */) => { - var completer = PromiseWrapper.completer(); + var resolve: (result: any) => void; + var promise = new Promise(res => { resolve = res; }); var res = (c.value == expectedValue) ? null : {'uniqLogin': true}; - completer.resolve(res); - return completer.promise; + resolve(res); + return promise; }; } diff --git a/modules/@angular/forms/test/template_integration_spec.ts b/modules/@angular/forms/test/template_integration_spec.ts index a379cb6a2e..61be2b837e 100644 --- a/modules/@angular/forms/test/template_integration_spec.ts +++ b/modules/@angular/forms/test/template_integration_spec.ts @@ -14,8 +14,6 @@ import {FormsModule, NgForm} from '@angular/forms'; import {By} from '@angular/platform-browser/src/dom/debug/by'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {dispatchEvent} from '@angular/platform-browser/testing/browser_util'; - -import {ObservableWrapper} from '../src/facade/async'; import {ListWrapper} from '../src/facade/collection'; export function main() { @@ -170,10 +168,10 @@ export function main() { let formValidity: string; let formValue: Object; - ObservableWrapper.subscribe( - form.statusChanges, (status: string) => { formValidity = status; }); - ObservableWrapper.subscribe(form.valueChanges, (value: string) => { formValue = value; }); + form.statusChanges.subscribe({next: (status: string) => { formValidity = status; }}); + + form.valueChanges.subscribe({next: (value: string) => { formValue = value; }}); tick(); diff --git a/modules/@angular/forms/test/validators_spec.ts b/modules/@angular/forms/test/validators_spec.ts index e6c9953bf1..499e237f91 100644 --- a/modules/@angular/forms/test/validators_spec.ts +++ b/modules/@angular/forms/test/validators_spec.ts @@ -12,8 +12,7 @@ import {AbstractControl, FormControl, Validators} from '@angular/forms'; import {Observable} from 'rxjs/Observable'; import {normalizeAsyncValidator} from '../src/directives/normalize_validator'; -import {EventEmitter, ObservableWrapper, TimerWrapper} from '../src/facade/async'; -import {PromiseWrapper} from '../src/facade/promise'; +import {EventEmitter} from '../src/facade/async'; export function main() { function validator(key: string, error: any) { @@ -133,14 +132,14 @@ export function main() { return (c: any /** TODO #9100 */) => { var emitter = new EventEmitter(); var res = c.value != expected ? response : null; - - PromiseWrapper.scheduleMicrotask(() => { - ObservableWrapper.callEmit(emitter, res); + Promise.resolve(null).then(() => { + emitter.emit(res); // this is required because of a bug in ObservableWrapper // where callComplete can fire before callEmit // remove this one the bug is fixed - TimerWrapper.setTimeout(() => { ObservableWrapper.callComplete(emitter); }, 0); + setTimeout(() => { emitter.complete(); }, 0); }); + return emitter; }; } diff --git a/modules/@angular/http/src/headers.ts b/modules/@angular/http/src/headers.ts index bc243a6976..bd4beb150e 100644 --- a/modules/@angular/http/src/headers.ts +++ b/modules/@angular/http/src/headers.ts @@ -6,10 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ +import {ListWrapper, Map, MapWrapper, StringMapWrapper, isListLikeIterable, iterateListLike} from '../src/facade/collection'; import {BaseException} from '../src/facade/exceptions'; import {isBlank} from '../src/facade/lang'; -import {isListLikeIterable, iterateListLike, Map, MapWrapper, StringMapWrapper, ListWrapper,} from '../src/facade/collection'; /** * Polyfill for [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers/Headers), as diff --git a/modules/@angular/http/test/backends/jsonp_backend_spec.ts b/modules/@angular/http/test/backends/jsonp_backend_spec.ts index 33cfd22d11..87cc154583 100644 --- a/modules/@angular/http/test/backends/jsonp_backend_spec.ts +++ b/modules/@angular/http/test/backends/jsonp_backend_spec.ts @@ -6,19 +6,19 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, SpyObject, afterEach, beforeEach, ddescribe, describe, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {BrowserJsonp} from '../../src/backends/browser_jsonp'; -import {JSONPConnection, JSONPConnection_, JSONPBackend, JSONPBackend_} from '../../src/backends/jsonp_backend'; import {ReflectiveInjector} from '@angular/core'; -import {isPresent,} from '../../src/facade/lang'; -import {TimerWrapper} from '../../src/facade/async'; +import {AsyncTestCompleter, SpyObject, afterEach, beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; +import {expect} from '@angular/platform-browser/testing/matchers'; + +import {BrowserJsonp} from '../../src/backends/browser_jsonp'; +import {JSONPBackend, JSONPBackend_, JSONPConnection, JSONPConnection_} from '../../src/backends/jsonp_backend'; +import {BaseRequestOptions, RequestOptions} from '../../src/base_request_options'; +import {BaseResponseOptions, ResponseOptions} from '../../src/base_response_options'; +import {ReadyState, RequestMethod, ResponseType} from '../../src/enums'; +import {Map} from '../../src/facade/collection'; +import {isPresent} from '../../src/facade/lang'; import {Request} from '../../src/static_request'; import {Response} from '../../src/static_response'; -import {Map} from '../../src/facade/collection'; -import {RequestOptions, BaseRequestOptions} from '../../src/base_request_options'; -import {BaseResponseOptions, ResponseOptions} from '../../src/base_response_options'; -import {ResponseType, ReadyState, RequestMethod} from '../../src/enums'; var existingScripts: MockBrowserJsonp[] = []; var unused: Response; @@ -108,7 +108,7 @@ export function main() { connection.finished('Fake data'); existingScripts[0].dispatchEvent('load'); - TimerWrapper.setTimeout(() => { + setTimeout(() => { expect(connection.readyState).toBe(ReadyState.Cancelled); expect(loadSpy).not.toHaveBeenCalled(); expect(errorSpy).not.toHaveBeenCalled(); diff --git a/modules/@angular/http/test/backends/mock_backend_spec.ts b/modules/@angular/http/test/backends/mock_backend_spec.ts index 69680b058f..e799d52a30 100644 --- a/modules/@angular/http/test/backends/mock_backend_spec.ts +++ b/modules/@angular/http/test/backends/mock_backend_spec.ts @@ -6,15 +6,16 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {MockConnection, MockBackend} from '../../testing/mock_backend'; import {ReflectiveInjector} from '@angular/core'; +import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; +import {expect} from '@angular/platform-browser/testing/matchers'; +import {ReplaySubject} from 'rxjs/ReplaySubject'; + +import {BaseRequestOptions, RequestOptions} from '../../src/base_request_options'; +import {BaseResponseOptions, ResponseOptions} from '../../src/base_response_options'; import {Request} from '../../src/static_request'; import {Response} from '../../src/static_response'; -import {RequestOptions, BaseRequestOptions} from '../../src/base_request_options'; -import {BaseResponseOptions, ResponseOptions} from '../../src/base_response_options'; -import {ReplaySubject} from 'rxjs/ReplaySubject'; +import {MockBackend, MockConnection} from '../../testing/mock_backend'; export function main() { describe('MockBackend', () => { diff --git a/modules/@angular/http/test/backends/xhr_backend_spec.ts b/modules/@angular/http/test/backends/xhr_backend_spec.ts index 8f0e70ca5f..216ecda5d7 100644 --- a/modules/@angular/http/test/backends/xhr_backend_spec.ts +++ b/modules/@angular/http/test/backends/xhr_backend_spec.ts @@ -6,20 +6,21 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, SpyObject, afterEach, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; -import {BrowserXhr} from '../../src/backends/browser_xhr'; -import {Json} from '../../src/facade/lang'; -import {XSRFStrategy} from '../../src/interfaces'; -import {XHRConnection, XHRBackend, CookieXSRFStrategy} from '../../src/backends/xhr_backend'; -import {Injectable,} from '@angular/core'; +import {Injectable} from '@angular/core'; +import {AsyncTestCompleter, SpyObject, afterEach, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; import {__platform_browser_private__} from '@angular/platform-browser'; + +import {BrowserXhr} from '../../src/backends/browser_xhr'; +import {CookieXSRFStrategy, XHRBackend, XHRConnection} from '../../src/backends/xhr_backend'; +import {BaseRequestOptions, RequestOptions} from '../../src/base_request_options'; +import {BaseResponseOptions, ResponseOptions} from '../../src/base_response_options'; +import {ResponseContentType, ResponseType} from '../../src/enums'; +import {Map} from '../../src/facade/collection'; +import {Json} from '../../src/facade/lang'; +import {Headers} from '../../src/headers'; +import {XSRFStrategy} from '../../src/interfaces'; import {Request} from '../../src/static_request'; import {Response} from '../../src/static_response'; -import {Headers} from '../../src/headers'; -import {Map} from '../../src/facade/collection'; -import {RequestOptions, BaseRequestOptions} from '../../src/base_request_options'; -import {BaseResponseOptions, ResponseOptions} from '../../src/base_response_options'; -import {ResponseType, ResponseContentType} from '../../src/enums'; import {URLSearchParams} from '../../src/url_search_params'; var abortSpy: any; diff --git a/modules/@angular/http/test/static_response_spec.ts b/modules/@angular/http/test/static_response_spec.ts index 2a8cd9c051..5c6cf5163d 100644 --- a/modules/@angular/http/test/static_response_spec.ts +++ b/modules/@angular/http/test/static_response_spec.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {describe, expect, it,} from '@angular/core/testing/testing_internal'; +import {describe, expect, it} from '@angular/core/testing/testing_internal'; import {ResponseOptions} from '../src/base_response_options'; import {Response} from '../src/static_response'; diff --git a/modules/@angular/platform-browser-dynamic/index.ts b/modules/@angular/platform-browser-dynamic/index.ts index 721a9c85fc..c45cc88f92 100644 --- a/modules/@angular/platform-browser-dynamic/index.ts +++ b/modules/@angular/platform-browser-dynamic/index.ts @@ -11,7 +11,6 @@ import {ApplicationRef, COMPILER_OPTIONS, Compiler, CompilerFactory, CompilerOpt import {BROWSER_PLATFORM_PROVIDERS, BrowserModule, WORKER_APP_PLATFORM_PROVIDERS, WORKER_SCRIPT, WorkerAppModule, platformBrowser, platformWorkerApp, platformWorkerUi} from '@angular/platform-browser'; import {Console} from './core_private'; -import {PromiseWrapper} from './src/facade/async'; import {ConcreteType, isPresent, stringify} from './src/facade/lang'; import {INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS} from './src/platform_providers'; import {CachedXHR} from './src/xhr/xhr_cache'; diff --git a/modules/@angular/platform-browser-dynamic/src/xhr/xhr_cache.ts b/modules/@angular/platform-browser-dynamic/src/xhr/xhr_cache.ts index e6cdd3646b..020537e03c 100644 --- a/modules/@angular/platform-browser-dynamic/src/xhr/xhr_cache.ts +++ b/modules/@angular/platform-browser-dynamic/src/xhr/xhr_cache.ts @@ -9,7 +9,6 @@ import {XHR} from '@angular/compiler'; import {BaseException} from '../facade/exceptions'; import {global} from '../facade/lang'; -import {PromiseWrapper} from '../facade/promise'; /** * An implementation of XHR that uses a template cache to avoid doing an actual @@ -31,9 +30,9 @@ export class CachedXHR extends XHR { get(url: string): Promise { if (this._cache.hasOwnProperty(url)) { - return PromiseWrapper.resolve(this._cache[url]); + return Promise.resolve(this._cache[url]); } else { - return PromiseWrapper.reject('CachedXHR: Did not find cached template for ' + url, null); + return >Promise.reject('CachedXHR: Did not find cached template for ' + url); } } } diff --git a/modules/@angular/platform-browser-dynamic/src/xhr/xhr_impl.ts b/modules/@angular/platform-browser-dynamic/src/xhr/xhr_impl.ts index f46984300c..cd7f38c738 100644 --- a/modules/@angular/platform-browser-dynamic/src/xhr/xhr_impl.ts +++ b/modules/@angular/platform-browser-dynamic/src/xhr/xhr_impl.ts @@ -9,12 +9,16 @@ import {XHR} from '@angular/compiler'; import {Injectable} from '@angular/core'; import {isPresent} from '../facade/lang'; -import {PromiseCompleter, PromiseWrapper} from '../facade/promise'; @Injectable() export class XHRImpl extends XHR { get(url: string): Promise { - var completer: PromiseCompleter = PromiseWrapper.completer(); + var resolve: (result: any) => void; + var reject: (error: any) => void; + const promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'text'; @@ -35,15 +39,15 @@ export class XHRImpl extends XHR { } if (200 <= status && status <= 300) { - completer.resolve(response); + resolve(response); } else { - completer.reject(`Failed to load ${url}`, null); + reject(`Failed to load ${url}`); } }; - xhr.onerror = function() { completer.reject(`Failed to load ${url}`, null); }; + xhr.onerror = function() { reject(`Failed to load ${url}`); }; xhr.send(); - return completer.promise; + return promise; } } diff --git a/modules/@angular/platform-browser-dynamic/test/testing_public_browser_spec.ts b/modules/@angular/platform-browser-dynamic/test/testing_public_browser_spec.ts index fc2313306e..08c9836674 100644 --- a/modules/@angular/platform-browser-dynamic/test/testing_public_browser_spec.ts +++ b/modules/@angular/platform-browser-dynamic/test/testing_public_browser_spec.ts @@ -11,7 +11,6 @@ import {Component, bind} from '@angular/core'; import {TestComponentBuilder, addProviders, async, fakeAsync, flushMicrotasks, inject, tick} from '@angular/core/testing'; import {ROUTER_DIRECTIVES, Route} from '@angular/router-deprecated'; -import {PromiseWrapper} from '../src/facade/promise'; import {XHRImpl} from '../src/xhr/xhr_impl'; @@ -86,15 +85,20 @@ export function main() { var originalJasmineIt: any; var patchJasmineIt = () => { - var deferred = PromiseWrapper.completer(); + var resolve: (result: any) => void; + var reject: (error: any) => void; + const promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); originalJasmineIt = jasmine.getEnv().it; jasmine.getEnv().it = (description: string, fn: any /** TODO #9100 */) => { - var done = () => { deferred.resolve(); }; - (done).fail = (err: any /** TODO #9100 */) => { deferred.reject(err); }; + var done = () => { resolve(null); }; + (done).fail = (err: any /** TODO #9100 */) => { reject(err); }; fn(done); return null; }; - return deferred.promise; + return promise; }; var restoreJasmineIt = () => { jasmine.getEnv().it = originalJasmineIt; }; @@ -109,7 +113,7 @@ export function main() { itPromise.then( () => { done.fail('Expected test to fail, but it did not'); }, - (err) => { + (err: any) => { expect(err.message) .toEqual('Uncaught (in promise): Failed to load non-existant.html'); done(); diff --git a/modules/@angular/platform-browser-dynamic/test/xhr/xhr_impl_spec.ts b/modules/@angular/platform-browser-dynamic/test/xhr/xhr_impl_spec.ts index 0ad765db35..995beb9bab 100644 --- a/modules/@angular/platform-browser-dynamic/test/xhr/xhr_impl_spec.ts +++ b/modules/@angular/platform-browser-dynamic/test/xhr/xhr_impl_spec.ts @@ -7,8 +7,6 @@ */ import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; - -import {PromiseWrapper} from '../../src/facade/async'; import {XHRImpl} from '../../src/xhr/xhr_impl'; export function main() { @@ -36,7 +34,7 @@ export function main() { it('should reject the Promise on failure', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - PromiseWrapper.catchError(xhr.get(url404), (e) => { + xhr.get(url404).catch((e) => { expect(e).toEqual(`Failed to load ${url404}`); async.done(); return null; diff --git a/modules/@angular/platform-browser/src/dom/dom_renderer.ts b/modules/@angular/platform-browser/src/dom/dom_renderer.ts index 680ee1e113..a86bcbb185 100644 --- a/modules/@angular/platform-browser/src/dom/dom_renderer.ts +++ b/modules/@angular/platform-browser/src/dom/dom_renderer.ts @@ -8,18 +8,16 @@ import {Inject, Injectable, OpaqueToken, RenderComponentType, Renderer, RootRenderer, ViewEncapsulation} from '@angular/core'; +import {AnimationKeyframe, AnimationPlayer, AnimationStyles, RenderDebugInfo} from '../../core_private'; import {StringMapWrapper} from '../facade/collection'; import {BaseException} from '../facade/exceptions'; import {Json, StringWrapper, isArray, isBlank, isPresent, isString, stringify} from '../facade/lang'; -import {DomSharedStylesHost} from './shared_styles_host'; - -import {AnimationKeyframe, AnimationStyles, AnimationPlayer, RenderDebugInfo,} from '../../core_private'; - -import {EventManager} from './events/event_manager'; -import {DOCUMENT} from './dom_tokens'; -import {getDOM} from './dom_adapter'; import {AnimationDriver} from './animation_driver'; +import {getDOM} from './dom_adapter'; +import {DOCUMENT} from './dom_tokens'; +import {EventManager} from './events/event_manager'; +import {DomSharedStylesHost} from './shared_styles_host'; import {camelCaseToDashCase} from './util'; const NAMESPACE_URIS = { diff --git a/modules/@angular/platform-browser/src/dom/events/key_events.ts b/modules/@angular/platform-browser/src/dom/events/key_events.ts index 0351ed9f46..b83ef7813b 100644 --- a/modules/@angular/platform-browser/src/dom/events/key_events.ts +++ b/modules/@angular/platform-browser/src/dom/events/key_events.ts @@ -8,10 +8,10 @@ import {Injectable, NgZone} from '@angular/core'; -import {isPresent, StringWrapper,} from '../../facade/lang'; -import {StringMapWrapper, ListWrapper} from '../../facade/collection'; - +import {ListWrapper, StringMapWrapper} from '../../facade/collection'; +import {StringWrapper, isPresent} from '../../facade/lang'; import {getDOM} from '../dom_adapter'; + import {EventManagerPlugin} from './event_manager'; diff --git a/modules/@angular/platform-browser/src/web_workers/shared/client_message_broker.ts b/modules/@angular/platform-browser/src/web_workers/shared/client_message_broker.ts index c22e0683ec..06e266c756 100644 --- a/modules/@angular/platform-browser/src/web_workers/shared/client_message_broker.ts +++ b/modules/@angular/platform-browser/src/web_workers/shared/client_message_broker.ts @@ -8,7 +8,7 @@ import {Injectable, Type} from '@angular/core'; -import {EventEmitter, ObservableWrapper, PromiseCompleter, PromiseWrapper} from '../../facade/async'; +import {EventEmitter} from '../../facade/async'; import {StringMapWrapper} from '../../facade/collection'; import {DateWrapper, StringWrapper, isPresent, print, stringify} from '../../facade/lang'; @@ -50,8 +50,13 @@ export abstract class ClientMessageBroker { abstract runOnService(args: UiArguments, returnType: Type): Promise; } +interface PromiseCompleter { + resolve: (result: any) => void; + reject: (err: any) => void; +} + export class ClientMessageBroker_ extends ClientMessageBroker { - private _pending: Map> = new Map>(); + private _pending: Map = new Map(); private _sink: EventEmitter; /** @internal */ public _serializer: Serializer; @@ -62,8 +67,8 @@ export class ClientMessageBroker_ extends ClientMessageBroker { this._sink = messageBus.to(channel); this._serializer = _serializer; var source = messageBus.from(channel); - ObservableWrapper.subscribe( - source, (message: {[key: string]: any}) => this._handleMessage(message)); + + source.subscribe({next: (message: {[key: string]: any}) => this._handleMessage(message)}); } private _generateMessageId(name: string): string { @@ -92,15 +97,16 @@ export class ClientMessageBroker_ extends ClientMessageBroker { var promise: Promise; var id: string = null; if (returnType != null) { - var completer: PromiseCompleter = PromiseWrapper.completer(); + let completer: PromiseCompleter; + promise = new Promise((resolve, reject) => { completer = {resolve, reject}; }); id = this._generateMessageId(args.method); this._pending.set(id, completer); - PromiseWrapper.catchError(completer.promise, (err, stack?) => { + promise.catch((err) => { print(err); - completer.reject(err, stack); + completer.reject(err); }); - promise = PromiseWrapper.then(completer.promise, (value: any) => { + promise = promise.then((value: any) => { if (this._serializer == null) { return value; } else { @@ -116,7 +122,7 @@ export class ClientMessageBroker_ extends ClientMessageBroker { if (id != null) { (message as any /** TODO #9100 */)['id'] = id; } - ObservableWrapper.callEmit(this._sink, message); + this._sink.emit(message); return promise; } @@ -130,7 +136,7 @@ export class ClientMessageBroker_ extends ClientMessageBroker { if (StringWrapper.equals(data.type, 'result')) { this._pending.get(id).resolve(data.value); } else { - this._pending.get(id).reject(data.value, null); + this._pending.get(id).reject(data.value); } this._pending.delete(id); } diff --git a/modules/@angular/platform-browser/src/web_workers/shared/post_message_bus.ts b/modules/@angular/platform-browser/src/web_workers/shared/post_message_bus.ts index 587eba127f..055cab7d59 100644 --- a/modules/@angular/platform-browser/src/web_workers/shared/post_message_bus.ts +++ b/modules/@angular/platform-browser/src/web_workers/shared/post_message_bus.ts @@ -8,7 +8,7 @@ import {Injectable, NgZone} from '@angular/core'; -import {EventEmitter, ObservableWrapper} from '../../facade/async'; +import {EventEmitter} from '../../facade/async'; import {StringMapWrapper} from '../../facade/collection'; import {BaseException} from '../../facade/exceptions'; @@ -29,9 +29,8 @@ export class PostMessageBusSink implements MessageBusSink { attachToZone(zone: NgZone): void { this._zone = zone; - this._zone.runOutsideAngular(() => { - ObservableWrapper.subscribe(this._zone.onStable, (_) => { this._handleOnEventDone(); }); - }); + this._zone.runOutsideAngular( + () => { this._zone.onStable.subscribe({next: () => { this._handleOnEventDone(); }}); }); } initChannel(channel: string, runInZone: boolean = true): void { diff --git a/modules/@angular/platform-browser/src/web_workers/shared/service_message_broker.ts b/modules/@angular/platform-browser/src/web_workers/shared/service_message_broker.ts index 46d21bf9a2..4ea17146e7 100644 --- a/modules/@angular/platform-browser/src/web_workers/shared/service_message_broker.ts +++ b/modules/@angular/platform-browser/src/web_workers/shared/service_message_broker.ts @@ -8,7 +8,7 @@ import {Injectable} from '@angular/core'; -import {EventEmitter, ObservableWrapper, PromiseWrapper} from '../../facade/async'; +import {EventEmitter} from '../../facade/async'; import {ListWrapper, Map} from '../../facade/collection'; import {FunctionWrapper, Type, isPresent} from '../../facade/lang'; import {MessageBus} from '../shared/message_bus'; @@ -63,7 +63,7 @@ export class ServiceMessageBroker_ extends ServiceMessageBroker { super(); this._sink = messageBus.to(channel); var source = messageBus.from(channel); - ObservableWrapper.subscribe(source, (message) => this._handleMessage(message)); + source.subscribe({next: (message: any) => this._handleMessage(message)}); } registerMethod( @@ -93,9 +93,8 @@ export class ServiceMessageBroker_ extends ServiceMessageBroker { } private _wrapWebWorkerPromise(id: string, promise: Promise, type: Type): void { - PromiseWrapper.then(promise, (result: any) => { - ObservableWrapper.callEmit( - this._sink, + promise.then((result: any) => { + this._sink.emit( {'type': 'result', 'value': this._serializer.serialize(result, type), 'id': id}); }); } diff --git a/modules/@angular/platform-browser/src/web_workers/ui/event_dispatcher.ts b/modules/@angular/platform-browser/src/web_workers/ui/event_dispatcher.ts index 49d3637bdb..9fb8280880 100644 --- a/modules/@angular/platform-browser/src/web_workers/ui/event_dispatcher.ts +++ b/modules/@angular/platform-browser/src/web_workers/ui/event_dispatcher.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {EventEmitter, ObservableWrapper} from '../../facade/async'; +import {EventEmitter} from '../../facade/async'; import {BaseException} from '../../facade/exceptions'; import {RenderStoreObject, Serializer} from '../shared/serializer'; @@ -98,7 +98,7 @@ export class EventDispatcher { default: throw new BaseException(eventName + ' not supported on WebWorkers'); } - ObservableWrapper.callEmit(this._sink, { + this._sink.emit({ 'element': this._serializer.serialize(element, RenderStoreObject), 'eventName': eventName, 'eventTarget': eventTarget, diff --git a/modules/@angular/platform-browser/src/web_workers/ui/platform_location.ts b/modules/@angular/platform-browser/src/web_workers/ui/platform_location.ts index 924c9955a0..9c39603099 100644 --- a/modules/@angular/platform-browser/src/web_workers/ui/platform_location.ts +++ b/modules/@angular/platform-browser/src/web_workers/ui/platform_location.ts @@ -10,7 +10,7 @@ import {UrlChangeListener} from '@angular/common'; import {Injectable} from '@angular/core'; import {BrowserPlatformLocation} from '../../browser/location/browser_platform_location'; -import {EventEmitter, ObservableWrapper, PromiseWrapper} from '../../facade/async'; +import {EventEmitter} from '../../facade/async'; import {FunctionWrapper} from '../../facade/lang'; import {MessageBus} from '../shared/message_bus'; import {ROUTER_CHANNEL} from '../shared/messaging_api'; @@ -54,14 +54,14 @@ export class MessageBasedPlatformLocation { } private _getLocation(): Promise { - return PromiseWrapper.resolve(this._platformLocation.location); + return Promise.resolve(this._platformLocation.location); } private _sendUrlChangeEvent(e: Event): void { let loc = this._serializer.serialize(this._platformLocation.location, LocationType); let serializedEvent = {'type': e.type}; - ObservableWrapper.callEmit(this._channelSink, {'event': serializedEvent, 'location': loc}); + this._channelSink.emit({'event': serializedEvent, 'location': loc}); } private _setPathname(pathname: string): void { this._platformLocation.pathname = pathname; } diff --git a/modules/@angular/platform-browser/src/web_workers/worker/platform_location.ts b/modules/@angular/platform-browser/src/web_workers/worker/platform_location.ts index 4a0f653a16..53ff729579 100644 --- a/modules/@angular/platform-browser/src/web_workers/worker/platform_location.ts +++ b/modules/@angular/platform-browser/src/web_workers/worker/platform_location.ts @@ -9,7 +9,7 @@ import {PlatformLocation, UrlChangeListener} from '@angular/common'; import {Injectable} from '@angular/core'; -import {EventEmitter, ObservableWrapper, PromiseWrapper} from '../../facade/async'; +import {EventEmitter} from '../../facade/async'; import {StringMapWrapper} from '../../facade/collection'; import {BaseException} from '../../facade/exceptions'; import {StringWrapper} from '../../facade/lang'; @@ -35,21 +35,23 @@ export class WebWorkerPlatformLocation extends PlatformLocation { this._broker = brokerFactory.createMessageBroker(ROUTER_CHANNEL); this._channelSource = bus.from(ROUTER_CHANNEL); - ObservableWrapper.subscribe(this._channelSource, (msg: {[key: string]: any}) => { - var listeners: Array = null; - if (StringMapWrapper.contains(msg, 'event')) { - let type: string = msg['event']['type']; - if (StringWrapper.equals(type, 'popstate')) { - listeners = this._popStateListeners; - } else if (StringWrapper.equals(type, 'hashchange')) { - listeners = this._hashChangeListeners; - } + this._channelSource.subscribe({ + next: (msg: {[key: string]: any}) => { + var listeners: Array = null; + if (StringMapWrapper.contains(msg, 'event')) { + let type: string = msg['event']['type']; + if (StringWrapper.equals(type, 'popstate')) { + listeners = this._popStateListeners; + } else if (StringWrapper.equals(type, 'hashchange')) { + listeners = this._hashChangeListeners; + } - if (listeners !== null) { - let e = deserializeGenericEvent(msg['event']); - // There was a popState or hashChange event, so the location object thas been updated - this._location = this._serializer.deserialize(msg['location'], LocationType); - listeners.forEach((fn: Function) => fn(e)); + if (listeners !== null) { + let e = deserializeGenericEvent(msg['event']); + // There was a popState or hashChange event, so the location object thas been updated + this._location = this._serializer.deserialize(msg['location'], LocationType); + listeners.forEach((fn: Function) => fn(e)); + } } } }); @@ -60,12 +62,12 @@ export class WebWorkerPlatformLocation extends PlatformLocation { var args: UiArguments = new UiArguments('getLocation'); var locationPromise: Promise = this._broker.runOnService(args, LocationType); - return PromiseWrapper.then( - locationPromise, (val: LocationType): - boolean => { - this._location = val; - return true; - }, + return locationPromise.then( + (val: LocationType): + boolean => { + this._location = val; + return true; + }, (err): boolean => { throw new BaseException(err); }); } diff --git a/modules/@angular/platform-browser/src/web_workers/worker/renderer.ts b/modules/@angular/platform-browser/src/web_workers/worker/renderer.ts index 90253174b2..2889d3293b 100644 --- a/modules/@angular/platform-browser/src/web_workers/worker/renderer.ts +++ b/modules/@angular/platform-browser/src/web_workers/worker/renderer.ts @@ -9,7 +9,6 @@ import {Injectable, RenderComponentType, Renderer, RootRenderer, ViewEncapsulation} from '@angular/core'; import {AnimationKeyframe, AnimationPlayer, AnimationStyles, RenderDebugInfo} from '../../../core_private'; -import {ObservableWrapper} from '../../facade/async'; import {ListWrapper} from '../../facade/collection'; import {isBlank, isPresent} from '../../facade/lang'; import {ClientMessageBrokerFactory, FnArg, UiArguments} from '../shared/client_message_broker'; @@ -33,7 +32,7 @@ export class WebWorkerRootRenderer implements RootRenderer { this._messageBroker = messageBrokerFactory.createMessageBroker(RENDERER_CHANNEL); bus.initChannel(EVENT_CHANNEL); var source = bus.from(EVENT_CHANNEL); - ObservableWrapper.subscribe(source, (message) => this._dispatchEvent(message)); + source.subscribe({next: (message: any) => this._dispatchEvent(message)}); } private _dispatchEvent(message: {[key: string]: any}): void { diff --git a/modules/@angular/platform-browser/test/browser/bootstrap_spec.ts b/modules/@angular/platform-browser/test/browser/bootstrap_spec.ts index bb6471d01a..293f25d946 100644 --- a/modules/@angular/platform-browser/test/browser/bootstrap_spec.ts +++ b/modules/@angular/platform-browser/test/browser/bootstrap_spec.ts @@ -19,8 +19,6 @@ import {bootstrap, platformBrowserDynamic} from '@angular/platform-browser-dynam import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens'; import {expect} from '@angular/platform-browser/testing/matchers'; - -import {PromiseWrapper} from '../../src/facade/async'; import {stringify} from '../../src/facade/lang'; @Component({selector: 'hello-app', template: '{{greeting}} world!'}) @@ -153,7 +151,7 @@ export function main() { var refPromise = bootstrap(HelloRootCmp, [{provide: ExceptionHandler, useValue: exceptionHandler}]); - PromiseWrapper.then(refPromise, null, (reason) => { + refPromise.then(null, (reason) => { expect(reason.message).toContain('The selector "hello-app" did not match any elements'); async.done(); return null; @@ -168,7 +166,7 @@ export function main() { var refPromise = bootstrap(HelloRootCmp, [{provide: ExceptionHandler, useValue: exceptionHandler}]); - PromiseWrapper.then(refPromise, null, (reason: any) => { + refPromise.then(null, (reason: any) => { expect(reason.message) .toContain('The selector "hello-app" did not match any elements'); async.done(); @@ -182,7 +180,7 @@ export function main() { var refPromise = bootstrap(HelloRootCmp, [{provide: ExceptionHandler, useValue: exceptionHandler}]); - PromiseWrapper.then(refPromise, null, (reason) => { + refPromise.then(null, (reason) => { expect(logger.res.join('')) .toContain('The selector "hello-app" did not match any elements'); async.done(); @@ -208,7 +206,7 @@ export function main() { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { var refPromise1 = bootstrap(HelloRootCmp, testProviders); var refPromise2 = bootstrap(HelloRootCmp2, testProviders); - PromiseWrapper.all([refPromise1, refPromise2]).then((refs) => { + Promise.all([refPromise1, refPromise2]).then((refs) => { expect(el).toHaveText('hello world!'); expect(el2).toHaveText('hello world, again!'); async.done(); @@ -285,11 +283,11 @@ export function main() { var refPromise1: Promise> = bootstrap(HelloRootCmp, testProviders); var refPromise2: Promise> = bootstrap(HelloRootCmp2, testProviders); - PromiseWrapper.all([refPromise1, refPromise2]).then((refs: ComponentRef[]) => { + Promise.all([refPromise1, refPromise2]).then((refs: ComponentRef[]) => { var registry = refs[0].injector.get(TestabilityRegistry); var testabilities = [refs[0].injector.get(Testability), refs[1].injector.get(Testability)]; - PromiseWrapper.all(testabilities).then((testabilities: Testability[]) => { + Promise.all(testabilities).then((testabilities: Testability[]) => { expect(registry.findTestabilityInTree(el)).toEqual(testabilities[0]); expect(registry.findTestabilityInTree(el2)).toEqual(testabilities[1]); async.done(); diff --git a/modules/@angular/platform-browser/test/dom/dom_renderer_integration_spec.ts b/modules/@angular/platform-browser/test/dom/dom_renderer_integration_spec.ts index b3b177a193..b326f798be 100644 --- a/modules/@angular/platform-browser/test/dom/dom_renderer_integration_spec.ts +++ b/modules/@angular/platform-browser/test/dom/dom_renderer_integration_spec.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; +import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; // import {MapWrapper} from '../../src/facade/src/collection'; // import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; diff --git a/modules/@angular/platform-browser/test/dom/events/event_manager_spec.ts b/modules/@angular/platform-browser/test/dom/events/event_manager_spec.ts index 85f27b70d4..b16d7595af 100644 --- a/modules/@angular/platform-browser/test/dom/events/event_manager_spec.ts +++ b/modules/@angular/platform-browser/test/dom/events/event_manager_spec.ts @@ -6,12 +6,13 @@ * found in the LICENSE file at https://angular.io/license */ -import {describe, ddescribe, it, iit, xit, xdescribe, expect, beforeEach,} from '@angular/core/testing/testing_internal'; -import {DomEventsPlugin} from '@angular/platform-browser/src/dom/events/dom_events'; import {NgZone} from '@angular/core/src/zone/ng_zone'; -import {ListWrapper, Map} from '../../../src/facade/collection'; +import {beforeEach, ddescribe, describe, expect, iit, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; +import {DomEventsPlugin} from '@angular/platform-browser/src/dom/events/dom_events'; import {EventManager, EventManagerPlugin} from '@angular/platform-browser/src/dom/events/event_manager'; + +import {ListWrapper, Map} from '../../../src/facade/collection'; import {el} from '../../../testing/browser_util'; export function main() { diff --git a/modules/@angular/platform-browser/test/dom/events/key_events_spec.ts b/modules/@angular/platform-browser/test/dom/events/key_events_spec.ts index d930d6d98c..ecf3039acc 100644 --- a/modules/@angular/platform-browser/test/dom/events/key_events_spec.ts +++ b/modules/@angular/platform-browser/test/dom/events/key_events_spec.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {describe, ddescribe, it, iit, xit, xdescribe, expect, beforeEach,} from '@angular/core/testing/testing_internal'; +import {beforeEach, ddescribe, describe, expect, iit, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; import {KeyEventsPlugin} from '@angular/platform-browser/src/dom/events/key_events'; export function main() { diff --git a/modules/@angular/platform-browser/test/dom/shared_styles_host_spec.ts b/modules/@angular/platform-browser/test/dom/shared_styles_host_spec.ts index 1b89893018..7d9d9cc1bb 100644 --- a/modules/@angular/platform-browser/test/dom/shared_styles_host_spec.ts +++ b/modules/@angular/platform-browser/test/dom/shared_styles_host_spec.ts @@ -6,10 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -import {beforeEach, ddescribe, xdescribe, describe, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; +import {beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {DomSharedStylesHost} from '@angular/platform-browser/src/dom/shared_styles_host'; +import {expect} from '@angular/platform-browser/testing/matchers'; export function main() { describe('DomSharedStylesHost', () => { diff --git a/modules/@angular/platform-browser/test/testing_public_spec.ts b/modules/@angular/platform-browser/test/testing_public_spec.ts index 18c15279b0..d8db44f848 100644 --- a/modules/@angular/platform-browser/test/testing_public_spec.ts +++ b/modules/@angular/platform-browser/test/testing_public_spec.ts @@ -12,8 +12,7 @@ import {CUSTOM_ELEMENTS_SCHEMA, Component, ComponentFactoryResolver, ComponentMe import {TestBed, TestComponentBuilder, addProviders, async, fakeAsync, inject, tick, withModule, withProviders} from '@angular/core/testing'; import {expect} from '@angular/platform-browser/testing/matchers'; -import {stringify} from '../../http/src/facade/lang'; -import {PromiseWrapper} from '../../http/src/facade/promise'; +import {stringify} from '../src/facade/lang'; // Services, and components for the tests. @@ -422,29 +421,39 @@ export function main() { var originalJasmineBeforeEach: any; var patchJasmineIt = () => { - var deferred = PromiseWrapper.completer(); + var resolve: (result: any) => void; + var reject: (error: any) => void; + var promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); originalJasmineIt = jasmine.getEnv().it; jasmine.getEnv().it = (description: string, fn: any /** TODO #9100 */) => { - var done = () => { deferred.resolve(); }; - (done).fail = (err: any /** TODO #9100 */) => { deferred.reject(err); }; + var done = () => { resolve(null); }; + (done).fail = (err: any /** TODO #9100 */) => { reject(err); }; fn(done); return null; }; - return deferred.promise; + return promise; }; var restoreJasmineIt = () => { jasmine.getEnv().it = originalJasmineIt; }; var patchJasmineBeforeEach = () => { - var deferred = PromiseWrapper.completer(); + var resolve: (result: any) => void; + var reject: (error: any) => void; + var promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); originalJasmineBeforeEach = jasmine.getEnv().beforeEach; jasmine.getEnv().beforeEach = (fn: any) => { - var done = () => { deferred.resolve(); }; - (done).fail = (err: any /** TODO #9100 */) => { deferred.reject(err); }; + var done = () => { resolve(null); }; + (done).fail = (err: any /** TODO #9100 */) => { reject(err); }; fn(done); return null; }; - return deferred.promise; + return promise; }; var restoreJasmineBeforeEach = @@ -470,10 +479,11 @@ export function main() { var itPromise = patchJasmineIt(); it('should fail with an error from a promise', async(inject([], () => { - var deferred = PromiseWrapper.completer(); - var p = deferred.promise.then(() => { expect(1).toEqual(2); }); + var reject: (error: any) => void; + var promise = new Promise((_, rej) => { reject = rej; }); + var p = promise.then(() => { expect(1).toEqual(2); }); - deferred.reject('baz'); + reject('baz'); return p; }))); diff --git a/modules/@angular/platform-browser/test/web_workers/shared/message_bus_spec.ts b/modules/@angular/platform-browser/test/web_workers/shared/message_bus_spec.ts index 9fd7100db1..f158523dfd 100644 --- a/modules/@angular/platform-browser/test/web_workers/shared/message_bus_spec.ts +++ b/modules/@angular/platform-browser/test/web_workers/shared/message_bus_spec.ts @@ -11,8 +11,6 @@ import {withProviders} from '@angular/core/testing/test_bed'; import {AsyncTestCompleter, MockNgZone, beforeEach, beforeEachProviders, describe, expect, inject, it} from '@angular/core/testing/testing_internal'; import {MessageBus} from '@angular/platform-browser/src/web_workers/shared/message_bus'; -import {ObservableWrapper, TimerWrapper} from '../../../src/facade/async'; - import {createConnectedMessageBus} from './message_bus_util'; export function main() { @@ -31,12 +29,14 @@ export function main() { bus.initChannel(CHANNEL, false); var fromEmitter = bus.from(CHANNEL); - ObservableWrapper.subscribe(fromEmitter, (message: any) => { - expect(message).toEqual(MESSAGE); - async.done(); + fromEmitter.subscribe({ + next: (message: any) => { + expect(message).toEqual(MESSAGE); + async.done(); + } }); var toEmitter = bus.to(CHANNEL); - ObservableWrapper.callEmit(toEmitter, MESSAGE); + toEmitter.emit(MESSAGE); })); it('should broadcast', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { @@ -56,11 +56,11 @@ export function main() { for (var i = 0; i < NUM_LISTENERS; i++) { var emitter = bus.from(CHANNEL); - ObservableWrapper.subscribe(emitter, emitHandler); + emitter.subscribe({next: emitHandler}); } var toEmitter = bus.to(CHANNEL); - ObservableWrapper.callEmit(toEmitter, MESSAGE); + toEmitter.emit(MESSAGE); })); it('should keep channels independent', @@ -74,27 +74,31 @@ export function main() { bus.initChannel(CHANNEL_TWO, false); var firstFromEmitter = bus.from(CHANNEL_ONE); - ObservableWrapper.subscribe(firstFromEmitter, (message) => { - expect(message).toEqual(MESSAGE_ONE); - callCount++; - if (callCount == 2) { - async.done(); + firstFromEmitter.subscribe({ + next: (message: any) => { + expect(message).toEqual(MESSAGE_ONE); + callCount++; + if (callCount == 2) { + async.done(); + } } }); var secondFromEmitter = bus.from(CHANNEL_TWO); - ObservableWrapper.subscribe(secondFromEmitter, (message) => { - expect(message).toEqual(MESSAGE_TWO); - callCount++; - if (callCount == 2) { - async.done(); + secondFromEmitter.subscribe({ + next: (message: any) => { + expect(message).toEqual(MESSAGE_TWO); + callCount++; + if (callCount == 2) { + async.done(); + } } }); var firstToEmitter = bus.to(CHANNEL_ONE); - ObservableWrapper.callEmit(firstToEmitter, MESSAGE_ONE); + firstToEmitter.emit(MESSAGE_ONE); var secondToEmitter = bus.to(CHANNEL_TWO); - ObservableWrapper.callEmit(secondToEmitter, MESSAGE_TWO); + secondToEmitter.emit(MESSAGE_TWO); })); }); @@ -111,7 +115,7 @@ export function main() { * Flushes pending messages and then runs the given function. */ // TODO(mlaval): timeout is fragile, test to be rewritten - function flushMessages(fn: () => void) { TimerWrapper.setTimeout(fn, 50); } + function flushMessages(fn: () => void) { setTimeout(fn, 50); } it('should buffer messages and wait for the zone to exit before sending', withProviders(() => [{provide: NgZone, useClass: MockNgZone}]) @@ -122,8 +126,8 @@ export function main() { setup(true, zone); var wasCalled = false; - ObservableWrapper.subscribe(bus.from(CHANNEL), (message) => { wasCalled = true; }); - ObservableWrapper.callEmit(bus.to(CHANNEL), 'hi'); + bus.from(CHANNEL).subscribe({next: (message: any) => { wasCalled = true; }}); + bus.to(CHANNEL).emit('hi'); flushMessages(() => { @@ -144,8 +148,8 @@ export function main() { setup(false, zone); var wasCalled = false; - ObservableWrapper.subscribe(bus.from(CHANNEL), (message) => { wasCalled = true; }); - ObservableWrapper.callEmit(bus.to(CHANNEL), 'hi'); + bus.from(CHANNEL).subscribe({next: (message: any) => { wasCalled = true; }}); + bus.to(CHANNEL).emit('hi'); flushMessages(() => { expect(wasCalled).toBeTruthy(); diff --git a/modules/@angular/platform-browser/test/web_workers/shared/service_message_broker_spec.ts b/modules/@angular/platform-browser/test/web_workers/shared/service_message_broker_spec.ts index c349f86829..34fb8ddc92 100644 --- a/modules/@angular/platform-browser/test/web_workers/shared/service_message_broker_spec.ts +++ b/modules/@angular/platform-browser/test/web_workers/shared/service_message_broker_spec.ts @@ -6,15 +6,15 @@ * found in the LICENSE file at https://angular.io/license */ -import {inject, describe, it, iit, expect, beforeEach, beforeEachProviders,} from '@angular/core/testing/testing_internal'; -import {browserDetection} from '@angular/platform-browser/testing/browser_util'; -import {createPairedMessageBuses} from './web_worker_test_util'; -import {Serializer, PRIMITIVE} from '@angular/platform-browser/src/web_workers/shared/serializer'; -import {ServiceMessageBroker, ServiceMessageBroker_} from '@angular/platform-browser/src/web_workers/shared/service_message_broker'; -import {ObservableWrapper, PromiseWrapper} from '../../../src/facade/async'; import {provide} from '@angular/core'; +import {beforeEach, beforeEachProviders, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal'; import {ON_WEB_WORKER} from '@angular/platform-browser/src/web_workers/shared/api'; import {RenderStore} from '@angular/platform-browser/src/web_workers/shared/render_store'; +import {PRIMITIVE, Serializer} from '@angular/platform-browser/src/web_workers/shared/serializer'; +import {ServiceMessageBroker, ServiceMessageBroker_} from '@angular/platform-browser/src/web_workers/shared/service_message_broker'; +import {browserDetection} from '@angular/platform-browser/testing/browser_util'; + +import {createPairedMessageBuses} from './web_worker_test_util'; export function main() { const CHANNEL = 'UIMessageBroker Test Channel'; @@ -41,8 +41,7 @@ export function main() { expect(arg1).toEqual(PASSED_ARG_1); expect(arg2).toEqual(PASSED_ARG_2); }); - ObservableWrapper.callEmit( - messageBuses.worker.to(CHANNEL), + messageBuses.worker.to(CHANNEL).emit( {'method': TEST_METHOD, 'args': [PASSED_ARG_1, PASSED_ARG_2]}); })); @@ -50,15 +49,22 @@ export function main() { var broker = new ServiceMessageBroker_(messageBuses.ui, serializer, CHANNEL); broker.registerMethod(TEST_METHOD, [PRIMITIVE], (arg1) => { expect(arg1).toEqual(PASSED_ARG_1); - return PromiseWrapper.wrap(() => { return RESULT; }); + return new Promise((res, rej) => { + try { + res(RESULT); + } catch (e) { + rej(e); + } + }); }); - ObservableWrapper.callEmit( - messageBuses.worker.to(CHANNEL), + messageBuses.worker.to(CHANNEL).emit( {'method': TEST_METHOD, 'id': ID, 'args': [PASSED_ARG_1]}); - ObservableWrapper.subscribe(messageBuses.worker.from(CHANNEL), (data: any) => { - expect(data.type).toEqual('result'); - expect(data.id).toEqual(ID); - expect(data.value).toEqual(RESULT); + messageBuses.worker.from(CHANNEL).subscribe({ + next: (data: any) => { + expect(data.type).toEqual('result'); + expect(data.id).toEqual(ID); + expect(data.value).toEqual(RESULT); + }, }); })); }); diff --git a/modules/@angular/platform-browser/test/web_workers/shared/web_worker_test_util.ts b/modules/@angular/platform-browser/test/web_workers/shared/web_worker_test_util.ts index bc07c9312a..c83f662dbf 100644 --- a/modules/@angular/platform-browser/test/web_workers/shared/web_worker_test_util.ts +++ b/modules/@angular/platform-browser/test/web_workers/shared/web_worker_test_util.ts @@ -9,8 +9,6 @@ import {NgZone} from '@angular/core/src/zone/ng_zone'; import {ClientMessageBroker, ClientMessageBrokerFactory_, UiArguments} from '@angular/platform-browser/src/web_workers/shared/client_message_broker'; import {MessageBus, MessageBusSink, MessageBusSource} from '@angular/platform-browser/src/web_workers/shared/message_bus'; - -import {PromiseWrapper} from '../../../src/facade/async'; import {ListWrapper, StringMapWrapper} from '../../../src/facade/collection'; import {BaseException} from '../../../src/facade/exceptions'; import {Type, isPresent} from '../../../src/facade/lang'; @@ -63,7 +61,13 @@ export function expectBrokerCall( } } if (promise == null) { - promise = PromiseWrapper.wrap(() => {}); + promise = new Promise((res, rej) => { + try { + res(); + } catch (e) { + rej(e); + } + }); } return promise; }); diff --git a/modules/@angular/platform-browser/test/web_workers/worker/platform_location_spec.ts b/modules/@angular/platform-browser/test/web_workers/worker/platform_location_spec.ts index da7e907efc..540a8e7e6b 100644 --- a/modules/@angular/platform-browser/test/web_workers/worker/platform_location_spec.ts +++ b/modules/@angular/platform-browser/test/web_workers/worker/platform_location_spec.ts @@ -11,8 +11,6 @@ import {UiArguments} from '@angular/platform-browser/src/web_workers/shared/clie import {MessageBus} from '@angular/platform-browser/src/web_workers/shared/message_bus'; import {LocationType} from '@angular/platform-browser/src/web_workers/shared/serialized_types'; import {WebWorkerPlatformLocation} from '@angular/platform-browser/src/web_workers/worker/platform_location'; - -import {PromiseWrapper} from '../../../src/facade/async'; import {Type} from '../../../src/facade/lang'; import {MockMessageBrokerFactory, createPairedMessageBuses, expectBrokerCall} from '../shared/web_worker_test_util'; @@ -31,7 +29,7 @@ export function main() { function createWebWorkerPlatformLocation(loc: LocationType): WebWorkerPlatformLocation { broker.spy('runOnService').andCallFake((args: UiArguments, returnType: Type) => { if (args.method === 'getLocation') { - return PromiseWrapper.resolve(loc); + return Promise.resolve(loc); } }); var factory = new MockMessageBrokerFactory(broker); diff --git a/modules/@angular/platform-browser/test/web_workers/worker/renderer_integration_spec.ts b/modules/@angular/platform-browser/test/web_workers/worker/renderer_integration_spec.ts index 32d7396e46..02231b53dc 100644 --- a/modules/@angular/platform-browser/test/web_workers/worker/renderer_integration_spec.ts +++ b/modules/@angular/platform-browser/test/web_workers/worker/renderer_integration_spec.ts @@ -6,25 +6,26 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, inject, ddescribe, describe, it, iit, beforeEach, beforeEachProviders,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {TestBed, TestComponentBuilder} from '@angular/core/testing'; -import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; -import {Injector, ViewMetadata, Component, Injectable, ComponentRef, ReflectiveInjector, getPlatform} from '@angular/core'; import {NgIf} from '@angular/common'; -import {WebWorkerRootRenderer} from '@angular/platform-browser/src/web_workers/worker/renderer'; -import {ClientMessageBrokerFactory, ClientMessageBrokerFactory_} from '@angular/platform-browser/src/web_workers/shared/client_message_broker'; -import {Serializer} from '@angular/platform-browser/src/web_workers/shared/serializer'; -import {RootRenderer} from '@angular/core/src/render/api'; -import {DomRootRenderer, DomRootRenderer_} from '@angular/platform-browser/src/dom/dom_renderer'; +import {Component, ComponentRef, Injectable, Injector, ReflectiveInjector, ViewMetadata, getPlatform} from '@angular/core'; import {DebugDomRootRenderer} from '@angular/core/src/debug/debug_renderer'; -import {RenderStore} from '@angular/platform-browser/src/web_workers/shared/render_store'; -import {MessageBasedRenderer} from '@angular/platform-browser/src/web_workers/ui/renderer'; -import {createPairedMessageBuses, PairedMessageBuses} from '../shared/web_worker_test_util'; -import {ServiceMessageBrokerFactory_} from '@angular/platform-browser/src/web_workers/shared/service_message_broker'; -import {dispatchEvent} from '../../../../platform-browser/testing/browser_util'; -import {BrowserTestingModule} from '@angular/platform-browser/testing'; +import {RootRenderer} from '@angular/core/src/render/api'; +import {TestBed, TestComponentBuilder} from '@angular/core/testing'; +import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it} from '@angular/core/testing/testing_internal'; import {platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing'; +import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; +import {DomRootRenderer, DomRootRenderer_} from '@angular/platform-browser/src/dom/dom_renderer'; +import {ClientMessageBrokerFactory, ClientMessageBrokerFactory_} from '@angular/platform-browser/src/web_workers/shared/client_message_broker'; +import {RenderStore} from '@angular/platform-browser/src/web_workers/shared/render_store'; +import {Serializer} from '@angular/platform-browser/src/web_workers/shared/serializer'; +import {ServiceMessageBrokerFactory_} from '@angular/platform-browser/src/web_workers/shared/service_message_broker'; +import {MessageBasedRenderer} from '@angular/platform-browser/src/web_workers/ui/renderer'; +import {WebWorkerRootRenderer} from '@angular/platform-browser/src/web_workers/worker/renderer'; +import {BrowserTestingModule} from '@angular/platform-browser/testing'; +import {expect} from '@angular/platform-browser/testing/matchers'; + +import {dispatchEvent} from '../../../../platform-browser/testing/browser_util'; +import {PairedMessageBuses, createPairedMessageBuses} from '../shared/web_worker_test_util'; export function main() { function createWebWorkerBrokerFactory( diff --git a/modules/@angular/platform-server/core_private.ts b/modules/@angular/platform-server/core_private.ts index 98e8f67072..accc782e52 100644 --- a/modules/@angular/platform-server/core_private.ts +++ b/modules/@angular/platform-server/core_private.ts @@ -11,4 +11,4 @@ import {__core_private__ as r, __core_private_types__ as t} from '@angular/core' export var reflector: typeof t.reflector = r.reflector; export var ReflectionCapabilities: typeof t.ReflectionCapabilities = r.ReflectionCapabilities; export var wtfInit: typeof t.wtfInit = r.wtfInit; -export var Console: typeof t.Console = r.Console; \ No newline at end of file +export var Console: typeof t.Console = r.Console; diff --git a/modules/@angular/router-deprecated/src/directives/router_outlet.ts b/modules/@angular/router-deprecated/src/directives/router_outlet.ts index abe581be06..e32880873c 100644 --- a/modules/@angular/router-deprecated/src/directives/router_outlet.ts +++ b/modules/@angular/router-deprecated/src/directives/router_outlet.ts @@ -8,7 +8,7 @@ import {Attribute, ComponentRef, Directive, DynamicComponentLoader, OnDestroy, Output, ReflectiveInjector, ViewContainerRef, provide} from '@angular/core'; -import {EventEmitter, PromiseWrapper} from '../facade/async'; +import {EventEmitter} from '../facade/async'; import {StringMapWrapper} from '../facade/collection'; import {isBlank, isPresent} from '../facade/lang'; import {ComponentInstruction, RouteData, RouteParams} from '../instruction'; @@ -17,7 +17,7 @@ import * as hookMod from '../lifecycle/lifecycle_annotations'; import {hasLifecycleHook} from '../lifecycle/route_lifecycle_reflector'; import * as routerMod from '../router'; -let _resolveToTrue = PromiseWrapper.resolve(true); +let _resolveToTrue = Promise.resolve(true); /** * A router outlet is a placeholder that Angular dynamically fills based on the application's route. @@ -91,7 +91,7 @@ export class RouterOutlet implements OnDestroy { if (isBlank(this._componentRef)) { return this.activate(nextInstruction); } else { - return PromiseWrapper.resolve( + return Promise.resolve( hasLifecycleHook(hookMod.routerOnReuse, this._currentInstruction.componentType) ? this._componentRef.then( (ref: ComponentRef) => @@ -169,7 +169,7 @@ export class RouterOutlet implements OnDestroy { (isPresent(nextInstruction.params) && isPresent(this._currentInstruction.params) && StringMapWrapper.equals(nextInstruction.params, this._currentInstruction.params)); } - return >PromiseWrapper.resolve(result); + return >Promise.resolve(result); } ngOnDestroy(): void { this._parentRouter.unregisterPrimaryOutlet(this); } diff --git a/modules/@angular/router-deprecated/src/instruction.ts b/modules/@angular/router-deprecated/src/instruction.ts index 43784925e9..99cc76db2a 100644 --- a/modules/@angular/router-deprecated/src/instruction.ts +++ b/modules/@angular/router-deprecated/src/instruction.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import {PromiseWrapper} from '../src/facade/async'; import {StringMapWrapper} from '../src/facade/collection'; import {isBlank, isPresent, normalizeBlank} from '../src/facade/lang'; @@ -229,9 +228,7 @@ export class ResolvedInstruction extends Instruction { super(component, child, auxInstruction); } - resolveComponent(): Promise { - return PromiseWrapper.resolve(this.component); - } + resolveComponent(): Promise { return Promise.resolve(this.component); } } @@ -282,7 +279,7 @@ export class UnresolvedInstruction extends Instruction { resolveComponent(): Promise { if (isPresent(this.component)) { - return PromiseWrapper.resolve(this.component); + return Promise.resolve(this.component); } return this._resolver().then((instruction: Instruction) => { this.child = isPresent(instruction) ? instruction.child : null; diff --git a/modules/@angular/router-deprecated/src/route_registry.ts b/modules/@angular/router-deprecated/src/route_registry.ts index 8ae495442a..f4e536654b 100644 --- a/modules/@angular/router-deprecated/src/route_registry.ts +++ b/modules/@angular/router-deprecated/src/route_registry.ts @@ -6,22 +6,22 @@ * found in the LICENSE file at https://angular.io/license */ -import {PromiseWrapper} from '../src/facade/async'; -import {ListWrapper, Map, StringMapWrapper} from '../src/facade/collection'; +import {Inject, Injectable, OpaqueToken} from '@angular/core'; -import {isPresent, isArray, isBlank, isType, isString, isStringMap, Type, StringWrapper, Math, getTypeNameForDebugging,} from '../src/facade/lang'; -import {BaseException} from '../src/facade/exceptions'; -import {Injectable, Inject, OpaqueToken} from '@angular/core'; -import {RouteConfig, Route, AuxRoute, RouteDefinition} from './route_config/route_config_impl'; -import {PathMatch, RedirectMatch, RouteMatch} from './rules/rules'; -import {RuleSet} from './rules/rule_set'; -import {Instruction, ResolvedInstruction, RedirectInstruction, UnresolvedInstruction, DefaultInstruction} from './instruction'; -import {normalizeRouteConfig, assertComponentExists} from './route_config/route_config_normalizer'; -import {parser, Url, convertUrlParamsToArray} from './url_parser'; -import {GeneratedUrl} from './rules/route_paths/route_path'; import {reflector} from '../core_private'; +import {ListWrapper, Map, StringMapWrapper} from '../src/facade/collection'; +import {BaseException} from '../src/facade/exceptions'; +import {Math, StringWrapper, Type, getTypeNameForDebugging, isArray, isBlank, isPresent, isString, isStringMap, isType} from '../src/facade/lang'; -var _resolveToNull = PromiseWrapper.resolve(null); +import {DefaultInstruction, Instruction, RedirectInstruction, ResolvedInstruction, UnresolvedInstruction} from './instruction'; +import {AuxRoute, Route, RouteConfig, RouteDefinition} from './route_config/route_config_impl'; +import {assertComponentExists, normalizeRouteConfig} from './route_config/route_config_normalizer'; +import {GeneratedUrl} from './rules/route_paths/route_path'; +import {RuleSet} from './rules/rule_set'; +import {PathMatch, RedirectMatch, RouteMatch} from './rules/rules'; +import {Url, convertUrlParamsToArray, parser} from './url_parser'; + +var _resolveToNull = Promise.resolve(null); // A LinkItemArray is an array, which describes a set of routes // The items in the array are found in groups: @@ -200,10 +200,10 @@ export class RouteRegistry { })); if ((isBlank(parsedUrl) || parsedUrl.path == '') && possibleMatches.length == 0) { - return PromiseWrapper.resolve(this.generateDefault(parentComponent)); + return Promise.resolve(this.generateDefault(parentComponent)); } - return PromiseWrapper.all(matchPromises).then(mostSpecific); + return Promise.all(matchPromises).then(mostSpecific); } private _auxRoutesToUnresolved(auxRoutes: Url[], parentInstructions: Instruction[]): diff --git a/modules/@angular/router-deprecated/src/router.ts b/modules/@angular/router-deprecated/src/router.ts index 8c315574b4..6ac36cacce 100644 --- a/modules/@angular/router-deprecated/src/router.ts +++ b/modules/@angular/router-deprecated/src/router.ts @@ -9,7 +9,7 @@ import {Location} from '@angular/common'; import {Inject, Injectable} from '@angular/core'; -import {EventEmitter, ObservableWrapper, PromiseWrapper} from '../src/facade/async'; +import {EventEmitter} from '../src/facade/async'; import {Map, StringMapWrapper} from '../src/facade/collection'; import {BaseException} from '../src/facade/exceptions'; import {Type, isBlank, isPresent} from '../src/facade/lang'; @@ -20,8 +20,8 @@ import {getCanActivateHook} from './lifecycle/route_lifecycle_reflector'; import {RouteDefinition} from './route_config/route_config_impl'; import {ROUTER_PRIMARY_COMPONENT, RouteRegistry} from './route_registry'; -let _resolveToTrue = PromiseWrapper.resolve(true); -let _resolveToFalse = PromiseWrapper.resolve(false); +let _resolveToTrue = Promise.resolve(true); +let _resolveToFalse = Promise.resolve(false); /** * The `Router` is responsible for mapping URLs to components. @@ -271,7 +271,7 @@ export class Router { instruction.auxInstruction, (instruction: Instruction, _: any /** TODO #9100 */) => { unsettledInstructions.push(this._settleInstruction(instruction)); }); - return PromiseWrapper.all(unsettledInstructions); + return Promise.all(unsettledInstructions); }); } @@ -296,15 +296,13 @@ export class Router { } private _emitNavigationFinish(instruction: ComponentInstruction): void { - ObservableWrapper.callEmit(this._subject, {status: 'success', instruction}); + this._subject.emit({status: 'success', instruction}); } /** @internal */ - _emitNavigationFail(url: string): void { - ObservableWrapper.callEmit(this._subject, {status: 'fail', url}); - } + _emitNavigationFail(url: string): void { this._subject.emit({status: 'fail', url}); } private _afterPromiseFinishNavigating(promise: Promise): Promise { - return PromiseWrapper.catchError(promise.then((_) => this._finishNavigating()), (err) => { + return promise.then(() => this._finishNavigating()).catch((err) => { this._finishNavigating(); throw err; }); @@ -396,7 +394,7 @@ export class Router { } }); - return next.then((_) => PromiseWrapper.all(promises)); + return next.then((_) => Promise.all(promises)); } @@ -411,7 +409,7 @@ export class Router { * Subscribe to URL updates from the router */ subscribe(onNext: (value: any) => void, onError?: (value: any) => void): Object { - return ObservableWrapper.subscribe(this._subject, onNext, onError); + return this._subject.subscribe({next: onNext, error: onError}); } @@ -552,7 +550,7 @@ export class RootRouter extends Router { dispose(): void { if (isPresent(this._locationSub)) { - ObservableWrapper.dispose(this._locationSub); + (this._locationSub).unsubscribe(); this._locationSub = null; } } diff --git a/modules/@angular/router-deprecated/src/rules/route_handlers/sync_route_handler.ts b/modules/@angular/router-deprecated/src/rules/route_handlers/sync_route_handler.ts index 635c24fb9b..34490c63a2 100644 --- a/modules/@angular/router-deprecated/src/rules/route_handlers/sync_route_handler.ts +++ b/modules/@angular/router-deprecated/src/rules/route_handlers/sync_route_handler.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import {PromiseWrapper} from '../../facade/async'; import {Type, isPresent} from '../../facade/lang'; import {BLANK_ROUTE_DATA, RouteData} from '../../instruction'; @@ -20,7 +19,7 @@ export class SyncRouteHandler implements RouteHandler { _resolvedComponent: Promise = null; constructor(public componentType: Type, data?: {[key: string]: any}) { - this._resolvedComponent = PromiseWrapper.resolve(componentType); + this._resolvedComponent = Promise.resolve(componentType); this.data = isPresent(data) ? new RouteData(data) : BLANK_ROUTE_DATA; } diff --git a/modules/@angular/router-deprecated/src/rules/rule_set.ts b/modules/@angular/router-deprecated/src/rules/rule_set.ts index d850c65941..ff0e2eb3cc 100644 --- a/modules/@angular/router-deprecated/src/rules/rule_set.ts +++ b/modules/@angular/router-deprecated/src/rules/rule_set.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import {PromiseWrapper} from '../facade/async'; import {Map} from '../facade/collection'; import {BaseException} from '../facade/exceptions'; import {isBlank, isFunction, isPresent} from '../facade/lang'; @@ -120,7 +119,7 @@ export class RuleSet { // handle cases where we are routing just to an aux route if (solutions.length == 0 && isPresent(urlParse) && urlParse.auxiliary.length > 0) { - return [PromiseWrapper.resolve(new PathMatch(null, null, urlParse.auxiliary))]; + return [Promise.resolve(new PathMatch(null, null, urlParse.auxiliary))]; } return solutions; @@ -132,7 +131,7 @@ export class RuleSet { return [routeRecognizer.recognize(urlParse)]; } - return [PromiseWrapper.resolve(null)]; + return [Promise.resolve(null)]; } hasRoute(name: string): boolean { return this.rulesByName.has(name); } diff --git a/modules/@angular/router-deprecated/src/rules/rules.ts b/modules/@angular/router-deprecated/src/rules/rules.ts index fcf0c37350..80d8557a2d 100644 --- a/modules/@angular/router-deprecated/src/rules/rules.ts +++ b/modules/@angular/router-deprecated/src/rules/rules.ts @@ -9,7 +9,6 @@ import {Map} from '../facade/collection'; import {BaseException} from '../facade/exceptions'; import {isBlank, isPresent} from '../facade/lang'; -import {PromiseWrapper} from '../facade/promise'; import {ComponentInstruction} from '../instruction'; import {Url, convertUrlParamsToArray} from '../url_parser'; @@ -58,7 +57,7 @@ export class RedirectRule implements AbstractRule { if (isPresent(this._pathRecognizer.matchUrl(beginningSegment))) { match = new RedirectMatch(this.redirectTo, this._pathRecognizer.specificity); } - return PromiseWrapper.resolve(match); + return Promise.resolve(match); } generate(params: {[key: string]: any}): ComponentInstruction { diff --git a/modules/@angular/router-deprecated/test/directives/router_link_spec.ts b/modules/@angular/router-deprecated/test/directives/router_link_spec.ts index 2c2758469b..654e82cba8 100644 --- a/modules/@angular/router-deprecated/test/directives/router_link_spec.ts +++ b/modules/@angular/router-deprecated/test/directives/router_link_spec.ts @@ -6,16 +6,16 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal'; -import {TestComponentBuilder} from '@angular/core/testing'; - -import {SpyRouter, SpyLocation} from '../spies'; -import {Component} from '@angular/core'; import {Location} from '@angular/common'; -import {Router, RouteRegistry, RouterLink, RouterOutlet, Route, RouteParams, ComponentInstruction} from '@angular/router-deprecated'; -import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; -import {ResolvedInstruction} from '@angular/router-deprecated/src/instruction'; +import {Component} from '@angular/core'; +import {TestComponentBuilder} from '@angular/core/testing'; +import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; import {By} from '@angular/platform-browser/src/dom/debug/by'; +import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; +import {ComponentInstruction, Route, RouteParams, RouteRegistry, Router, RouterLink, RouterOutlet} from '@angular/router-deprecated'; +import {ResolvedInstruction} from '@angular/router-deprecated/src/instruction'; + +import {SpyLocation, SpyRouter} from '../spies'; let dummyInstruction = new ResolvedInstruction( new ComponentInstruction('detail', [], null, null, true, '0', null, 'Detail'), null, {}); diff --git a/modules/@angular/router-deprecated/test/integration/auxiliary_route_spec.ts b/modules/@angular/router-deprecated/test/integration/auxiliary_route_spec.ts index 64be8b52ee..6882c6133e 100644 --- a/modules/@angular/router-deprecated/test/integration/auxiliary_route_spec.ts +++ b/modules/@angular/router-deprecated/test/integration/auxiliary_route_spec.ts @@ -6,11 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -import {TEST_ROUTER_PROVIDERS, ddescribeRouter, describeRouter, describeWith, describeWithAndWithout, describeWithout, itShouldRoute} from './util'; - -import {beforeEachProviders, describe,} from '@angular/core/testing/testing_internal'; +import {beforeEachProviders, describe} from '@angular/core/testing/testing_internal'; import {registerSpecs} from './impl/aux_route_spec_impl'; +import {TEST_ROUTER_PROVIDERS, ddescribeRouter, describeRouter, describeWith, describeWithAndWithout, describeWithout, itShouldRoute} from './util'; export function main() { describe('auxiliary route spec', () => { diff --git a/modules/@angular/router-deprecated/test/integration/bootstrap_spec.ts b/modules/@angular/router-deprecated/test/integration/bootstrap_spec.ts index 2d254c2f7c..68b011bfdd 100644 --- a/modules/@angular/router-deprecated/test/integration/bootstrap_spec.ts +++ b/modules/@angular/router-deprecated/test/integration/bootstrap_spec.ts @@ -19,8 +19,6 @@ import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens'; import {expect} from '@angular/platform-browser/testing/matchers'; import {ROUTER_DIRECTIVES, ROUTER_PRIMARY_COMPONENT, ROUTER_PROVIDERS, RouteParams, Router} from '@angular/router-deprecated'; - -import {PromiseWrapper} from '../../src/facade/async'; import {BaseException} from '../../src/facade/exceptions'; import {AuxRoute, Route, RouteConfig} from '../../src/route_config/route_config_decorator'; @@ -74,7 +72,7 @@ export function main() { (async: AsyncTestCompleter, tcb: TestComponentBuilder) => { tcb.createAsync(AppCmp).then((fixture) => { var router = fixture.debugElement.componentInstance.router; - PromiseWrapper.catchError(router.navigateByUrl('/cause-error'), (error) => { + router.navigateByUrl('/cause-error').catch((error: any) => { expect(error).toContainError('oops!'); async.done(); }); diff --git a/modules/@angular/router-deprecated/test/integration/impl/async_route_spec_impl.ts b/modules/@angular/router-deprecated/test/integration/impl/async_route_spec_impl.ts index 70d0e1de29..4739987263 100644 --- a/modules/@angular/router-deprecated/test/integration/impl/async_route_spec_impl.ts +++ b/modules/@angular/router-deprecated/test/integration/impl/async_route_spec_impl.ts @@ -6,18 +6,16 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, beforeEachProviders, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {ComponentFixture, TestComponentBuilder} from '@angular/core/testing'; - import {Location} from '@angular/common'; +import {ComponentFixture, TestComponentBuilder} from '@angular/core/testing'; +import {AsyncTestCompleter, beforeEach, beforeEachProviders, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; +import {expect} from '@angular/platform-browser/testing/matchers'; +import {AsyncRoute, Route, Router} from '@angular/router-deprecated'; -import {specs, compile, TEST_ROUTER_PROVIDERS, clickOnElement, getHref} from '../util'; - -import {Router, AsyncRoute, Route} from '@angular/router-deprecated'; - -import {HelloCmp, helloCmpLoader, UserCmp, userCmpLoader, TeamCmp, asyncTeamLoader, ParentCmp, parentCmpLoader, asyncParentCmpLoader, asyncDefaultParentCmpLoader, ParentWithDefaultCmp, parentWithDefaultCmpLoader, asyncRouteDataCmp} from './fixture_components'; import {By} from '../../../../platform-browser/src/dom/debug/by'; +import {TEST_ROUTER_PROVIDERS, clickOnElement, compile, getHref, specs} from '../util'; + +import {HelloCmp, ParentCmp, ParentWithDefaultCmp, TeamCmp, UserCmp, asyncDefaultParentCmpLoader, asyncParentCmpLoader, asyncRouteDataCmp, asyncTeamLoader, helloCmpLoader, parentCmpLoader, parentWithDefaultCmpLoader, userCmpLoader} from './fixture_components'; function getLinkElement(rtc: ComponentFixture) { return rtc.debugElement.query(By.css('a')).nativeElement; diff --git a/modules/@angular/router-deprecated/test/integration/impl/fixture_components.ts b/modules/@angular/router-deprecated/test/integration/impl/fixture_components.ts index a897112d79..db85815172 100644 --- a/modules/@angular/router-deprecated/test/integration/impl/fixture_components.ts +++ b/modules/@angular/router-deprecated/test/integration/impl/fixture_components.ts @@ -9,8 +9,6 @@ import {Component, ComponentRef, ViewChild, ViewContainerRef} from '@angular/core'; import {DynamicComponentLoader} from '@angular/core/src/linker/dynamic_component_loader'; import {AsyncRoute, ROUTER_DIRECTIVES, Redirect, Route, RouteConfig, RouteData, RouteParams} from '@angular/router-deprecated'; - -import {PromiseWrapper} from '../../../src/facade/async'; import {isPresent} from '../../../src/facade/lang'; @Component({selector: 'goodbye-cmp', template: `{{farewell}}`}) @@ -26,7 +24,7 @@ export class HelloCmp { } export function helloCmpLoader() { - return PromiseWrapper.resolve(HelloCmp); + return Promise.resolve(HelloCmp); } @@ -37,7 +35,7 @@ export class UserCmp { } export function userCmpLoader() { - return PromiseWrapper.resolve(UserCmp); + return Promise.resolve(UserCmp); } @@ -51,7 +49,7 @@ export class ParentCmp { } export function parentCmpLoader() { - return PromiseWrapper.resolve(ParentCmp); + return Promise.resolve(ParentCmp); } @@ -65,7 +63,7 @@ export class AsyncParentCmp { } export function asyncParentCmpLoader() { - return PromiseWrapper.resolve(AsyncParentCmp); + return Promise.resolve(AsyncParentCmp); } @Component({ @@ -79,7 +77,7 @@ export class AsyncDefaultParentCmp { } export function asyncDefaultParentCmpLoader() { - return PromiseWrapper.resolve(AsyncDefaultParentCmp); + return Promise.resolve(AsyncDefaultParentCmp); } @@ -93,7 +91,7 @@ export class ParentWithDefaultCmp { } export function parentWithDefaultCmpLoader() { - return PromiseWrapper.resolve(ParentWithDefaultCmp); + return Promise.resolve(ParentWithDefaultCmp); } @@ -120,7 +118,7 @@ export class AsyncTeamCmp { } export function asyncTeamLoader() { - return PromiseWrapper.resolve(AsyncTeamCmp); + return Promise.resolve(AsyncTeamCmp); } @@ -131,7 +129,7 @@ export class RouteDataCmp { } export function asyncRouteDataCmp() { - return PromiseWrapper.resolve(RouteDataCmp); + return Promise.resolve(RouteDataCmp); } @Component({selector: 'redirect-to-parent-cmp', template: 'redirect-to-parent'}) diff --git a/modules/@angular/router-deprecated/test/integration/impl/sync_route_spec_impl.ts b/modules/@angular/router-deprecated/test/integration/impl/sync_route_spec_impl.ts index 59e2547b09..34aaab8510 100644 --- a/modules/@angular/router-deprecated/test/integration/impl/sync_route_spec_impl.ts +++ b/modules/@angular/router-deprecated/test/integration/impl/sync_route_spec_impl.ts @@ -6,16 +6,15 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, beforeEachProviders, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {ComponentFixture, TestComponentBuilder} from '@angular/core/testing'; - -import {specs, compile, TEST_ROUTER_PROVIDERS, clickOnElement, getHref} from '../util'; import {Location} from '@angular/common'; -import {Router, Route} from '@angular/router-deprecated'; -import {HelloCmp, UserCmp, TeamCmp, ParentCmp, ParentWithDefaultCmp, DynamicLoaderCmp} from './fixture_components'; -import {PromiseWrapper} from '../../../src/facade/async'; +import {ComponentFixture, TestComponentBuilder} from '@angular/core/testing'; +import {AsyncTestCompleter, beforeEach, beforeEachProviders, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; import {By} from '@angular/platform-browser/src/dom/debug/by'; +import {expect} from '@angular/platform-browser/testing/matchers'; +import {Route, Router} from '@angular/router-deprecated'; +import {TEST_ROUTER_PROVIDERS, clickOnElement, compile, getHref, specs} from '../util'; + +import {DynamicLoaderCmp, HelloCmp, ParentCmp, ParentWithDefaultCmp, TeamCmp, UserCmp} from './fixture_components'; function getLinkElement(rtc: ComponentFixture) { @@ -497,7 +496,7 @@ function syncRoutesWithDynamicComponents() { // something // similar basically the assertion needs to run when the world is // stable and we don't know when that is, only zones know. - PromiseWrapper.resolve(null).then((_) => { + Promise.resolve(null).then((_) => { fixture.detectChanges(); expect(fixture.debugElement.nativeElement).toHaveText('[ hello ]'); async.done(); diff --git a/modules/@angular/router-deprecated/test/integration/lifecycle_hook_spec.ts b/modules/@angular/router-deprecated/test/integration/lifecycle_hook_spec.ts index 852120f248..0fceb1754a 100644 --- a/modules/@angular/router-deprecated/test/integration/lifecycle_hook_spec.ts +++ b/modules/@angular/router-deprecated/test/integration/lifecycle_hook_spec.ts @@ -6,13 +6,13 @@ * found in the LICENSE file at https://angular.io/license */ -import {Component,} from '@angular/core'; +import {Component} from '@angular/core'; import {ComponentFixture, TestComponentBuilder} from '@angular/core/testing'; import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; import {expect} from '@angular/platform-browser/testing/matchers'; import {RouteParams, Router, RouterLink, RouterOutlet} from '@angular/router-deprecated'; -import {EventEmitter, ObservableWrapper, PromiseCompleter, PromiseWrapper} from '../../src/facade/async'; +import {EventEmitter} from '../../src/facade/async'; import {isPresent} from '../../src/facade/lang'; import {ComponentInstruction} from '../../src/instruction'; import {CanDeactivate, CanReuse, OnActivate, OnDeactivate, OnReuse} from '../../src/interfaces'; @@ -24,7 +24,9 @@ import {TEST_ROUTER_PROVIDERS, compile} from './util'; var cmpInstanceCount: any /** TODO #9100 */; var log: string[]; var eventBus: EventEmitter; -var completer: PromiseCompleter; +var resolve: (result: any) => void; +var reject: (error: any) => void; +var promise: Promise; export function main() { describe('Router lifecycle hooks', () => { @@ -64,9 +66,11 @@ export function main() { .then((rtc) => { fixture = rtc; }) .then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})])) .then((_) => { - ObservableWrapper.subscribe(eventBus, (ev) => { - if (ev.startsWith('parent activate')) { - completer.resolve(true); + eventBus.subscribe({ + next: (ev: any) => { + if (ev.startsWith('parent activate')) { + resolve(true); + } } }); rtr.navigateByUrl('/parent-activate/child-activate').then((_) => { @@ -102,11 +106,14 @@ export function main() { .then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})])) .then((_) => rtr.navigateByUrl('/parent-deactivate/child-deactivate')) .then((_) => { - ObservableWrapper.subscribe(eventBus, (ev) => { - if (ev.startsWith('deactivate')) { - completer.resolve(true); - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('parent [deactivate cmp]'); + eventBus.subscribe({ + next: (ev: any) => { + if (ev.startsWith('deactivate')) { + resolve(true); + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement) + .toHaveText('parent [deactivate cmp]'); + } } }); rtr.navigateByUrl('/a').then((_) => { @@ -173,9 +180,11 @@ export function main() { .then((rtc) => { fixture = rtc; }) .then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})])) .then((_) => { - ObservableWrapper.subscribe(eventBus, (ev) => { - if (ev.startsWith('routerCanActivate')) { - completer.resolve(true); + eventBus.subscribe({ + next: (ev: any) => { + if (ev.startsWith('routerCanActivate')) { + resolve(true); + } } }); rtr.navigateByUrl('/can-activate/a').then((_) => { @@ -193,9 +202,11 @@ export function main() { .then((rtc) => { fixture = rtc; }) .then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})])) .then((_) => { - ObservableWrapper.subscribe(eventBus, (ev) => { - if (ev.startsWith('routerCanActivate')) { - completer.resolve(false); + eventBus.subscribe({ + next: (ev: any) => { + if (ev.startsWith('routerCanActivate')) { + resolve(false); + } } }); rtr.navigateByUrl('/can-activate/a').then((_) => { @@ -218,9 +229,11 @@ export function main() { expect(fixture.debugElement.nativeElement).toHaveText('routerCanDeactivate [A]'); expect(log).toEqual([]); - ObservableWrapper.subscribe(eventBus, (ev) => { - if (ev.startsWith('routerCanDeactivate')) { - completer.resolve(true); + eventBus.subscribe({ + next: (ev: any) => { + if (ev.startsWith('routerCanDeactivate')) { + resolve(true); + } } }); @@ -244,9 +257,11 @@ export function main() { expect(fixture.debugElement.nativeElement).toHaveText('routerCanDeactivate [A]'); expect(log).toEqual([]); - ObservableWrapper.subscribe(eventBus, (ev) => { - if (ev.startsWith('routerCanDeactivate')) { - completer.resolve(false); + eventBus.subscribe({ + next: (ev: any) => { + if (ev.startsWith('routerCanDeactivate')) { + resolve(false); + } } }); @@ -300,9 +315,11 @@ export function main() { 'routerOnActivate: null -> /reuse-hooks/1' ]); - ObservableWrapper.subscribe(eventBus, (ev) => { - if (ev.startsWith('routerCanReuse')) { - completer.resolve(true); + eventBus.subscribe({ + next: (ev: any) => { + if (ev.startsWith('routerCanReuse')) { + resolve(true); + } } }); @@ -330,9 +347,11 @@ export function main() { 'routerOnActivate: null -> /reuse-hooks/1' ]); - ObservableWrapper.subscribe(eventBus, (ev) => { - if (ev.startsWith('routerCanReuse')) { - completer.resolve(false); + eventBus.subscribe({ + next: (ev: any) => { + if (ev.startsWith('routerCanReuse')) { + resolve(false); + } } }); @@ -368,7 +387,7 @@ function logHook(name: string, next: ComponentInstruction, prev: ComponentInstru var message = name + ': ' + (isPresent(prev) ? ('/' + prev.urlPath) : 'null') + ' -> ' + (isPresent(next) ? ('/' + next.urlPath) : 'null'); log.push(message); - ObservableWrapper.callEmit(eventBus, message); + eventBus.emit(message); } @Component({selector: 'activate-cmp', template: 'activate cmp'}) @@ -386,9 +405,12 @@ class ActivateCmp implements OnActivate { @RouteConfig([new Route({path: '/child-activate', component: ActivateCmp})]) class ParentActivateCmp implements OnActivate { routerOnActivate(next: ComponentInstruction, prev: ComponentInstruction): Promise { - completer = PromiseWrapper.completer(); + promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); logHook('parent activate', next, prev); - return completer.promise; + return promise; } } @@ -402,9 +424,12 @@ class DeactivateCmp implements OnDeactivate { @Component({selector: 'deactivate-cmp', template: 'deactivate cmp'}) class WaitDeactivateCmp implements OnDeactivate { routerOnDeactivate(next: ComponentInstruction, prev: ComponentInstruction): Promise { - completer = PromiseWrapper.completer(); + promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); logHook('deactivate', next, prev); - return completer.promise; + return promise; } } @@ -460,9 +485,12 @@ class NeverReuseCmp implements OnReuse, class CanActivateCmp { static routerCanActivate(next: ComponentInstruction, prev: ComponentInstruction): Promise { - completer = PromiseWrapper.completer(); + promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); logHook('routerCanActivate', next, prev); - return completer.promise; + return promise; } } @@ -474,9 +502,12 @@ class CanActivateCmp { @RouteConfig([new Route({path: '/a', component: A}), new Route({path: '/b', component: B})]) class CanDeactivateCmp implements CanDeactivate { routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction): Promise { - completer = PromiseWrapper.completer(); + promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); logHook('routerCanDeactivate', next, prev); - return completer.promise; + return promise; } } @@ -534,9 +565,12 @@ class AllHooksParentCmp implements CanDeactivate, @CanActivate(ReuseHooksCmp.routerCanActivate) class ReuseHooksCmp implements OnActivate, OnReuse, OnDeactivate, CanReuse, CanDeactivate { routerCanReuse(next: ComponentInstruction, prev: ComponentInstruction): Promise { - completer = PromiseWrapper.completer(); + promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); logHook('routerCanReuse', next, prev); - return completer.promise; + return promise; } routerOnReuse(next: ComponentInstruction, prev: ComponentInstruction) { diff --git a/modules/@angular/router-deprecated/test/integration/navigation_spec.ts b/modules/@angular/router-deprecated/test/integration/navigation_spec.ts index 35a2c7126c..7df7f08da7 100644 --- a/modules/@angular/router-deprecated/test/integration/navigation_spec.ts +++ b/modules/@angular/router-deprecated/test/integration/navigation_spec.ts @@ -13,7 +13,6 @@ import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe import {expect} from '@angular/platform-browser/testing/matchers'; import {RouteData, RouteParams, Router, RouterLink, RouterOutlet} from '@angular/router-deprecated'; -import {PromiseWrapper, TimerWrapper} from '../../src/facade/async'; import {AsyncRoute, AuxRoute, Redirect, Route, RouteConfig} from '../../src/route_config/route_config_decorator'; import {RootCmp, TEST_ROUTER_PROVIDERS, compile} from './util'; @@ -238,9 +237,7 @@ export function main() { .then((_) => rtr.navigateByUrl('/test')) .then((_) => { // Note: need a timeout so that all promises are flushed - var completer = PromiseWrapper.completer(); - TimerWrapper.setTimeout(() => { completer.resolve(null); }, 0); - return completer.promise; + return new Promise(resolve => { setTimeout(() => { resolve(null); }, 0); }); }) .then((_) => { expect(fixture.componentInstance.activatedCmp).toBeAnInstanceOf(HelloCmp); @@ -259,7 +256,7 @@ class HelloCmp { function asyncRouteDataCmp() { - return PromiseWrapper.resolve(RouteDataCmp); + return Promise.resolve(RouteDataCmp); } @Component({selector: 'data-cmp', template: `{{myData}}`}) @@ -279,7 +276,7 @@ class UserCmp { function parentLoader() { - return PromiseWrapper.resolve(ParentCmp); + return Promise.resolve(ParentCmp); } @Component({ diff --git a/modules/@angular/router-deprecated/test/integration/router_link_spec.ts b/modules/@angular/router-deprecated/test/integration/router_link_spec.ts index 3b7a6998eb..eb17437a9a 100644 --- a/modules/@angular/router-deprecated/test/integration/router_link_spec.ts +++ b/modules/@angular/router-deprecated/test/integration/router_link_spec.ts @@ -6,19 +6,18 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; -import {ComponentFixture, TestComponentBuilder} from '@angular/core/testing'; import {Location} from '@angular/common'; -import {NumberWrapper, escapeRegExp} from '../../src/facade/lang'; -import {PromiseWrapper} from '../../src/facade/async'; -import {ListWrapper} from '../../src/facade/collection'; -import {Component} from '@angular/core'; -import {Router, RouteRegistry, RouterLink, AsyncRoute, AuxRoute, Route, RouteParams, RouteConfig, ROUTER_DIRECTIVES, ROUTER_PRIMARY_COMPONENT} from '@angular/router-deprecated'; -import {RootRouter} from '@angular/router-deprecated/src/router'; -import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; -import {By} from '@angular/platform-browser/src/dom/debug/by'; import {SpyLocation} from '@angular/common/testing'; +import {Component} from '@angular/core'; +import {ComponentFixture, TestComponentBuilder} from '@angular/core/testing'; +import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; +import {By} from '@angular/platform-browser/src/dom/debug/by'; +import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; +import {expect} from '@angular/platform-browser/testing/matchers'; +import {AsyncRoute, AuxRoute, ROUTER_DIRECTIVES, ROUTER_PRIMARY_COMPONENT, Route, RouteConfig, RouteParams, RouteRegistry, Router, RouterLink} from '@angular/router-deprecated'; +import {RootRouter} from '@angular/router-deprecated/src/router'; +import {ListWrapper} from '../../src/facade/collection'; +import {NumberWrapper, escapeRegExp} from '../../src/facade/lang'; export function main() { describe('routerLink directive', function() { @@ -435,7 +434,7 @@ class Hello2Cmp { } function parentCmpLoader() { - return PromiseWrapper.resolve(ParentCmp); + return Promise.resolve(ParentCmp); } @Component({ diff --git a/modules/@angular/router-deprecated/test/location/hash_location_strategy_spec.ts b/modules/@angular/router-deprecated/test/location/hash_location_strategy_spec.ts index ee5994325e..45cb566864 100644 --- a/modules/@angular/router-deprecated/test/location/hash_location_strategy_spec.ts +++ b/modules/@angular/router-deprecated/test/location/hash_location_strategy_spec.ts @@ -6,11 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -import {describe, it, iit, ddescribe, expect, inject, beforeEach, beforeEachProviders,} from '@angular/core/testing/testing_internal'; - +import {APP_BASE_HREF, HashLocationStrategy, PlatformLocation} from '@angular/common'; import {Injector, provide} from '@angular/core'; +import {beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal'; -import {PlatformLocation, APP_BASE_HREF, HashLocationStrategy} from '@angular/common'; import {SpyPlatformLocation} from '../spies'; export function main() { diff --git a/modules/@angular/router-deprecated/test/location/location_spec.ts b/modules/@angular/router-deprecated/test/location/location_spec.ts index 64b1a73219..568bae4906 100644 --- a/modules/@angular/router-deprecated/test/location/location_spec.ts +++ b/modules/@angular/router-deprecated/test/location/location_spec.ts @@ -6,11 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, describe, it, iit, ddescribe, expect, inject, beforeEach, beforeEachProviders,} from '@angular/core/testing/testing_internal'; - -import {ReflectiveInjector} from '@angular/core'; import {Location, LocationStrategy} from '@angular/common'; import {MockLocationStrategy} from '@angular/common/testing/mock_location_strategy'; +import {ReflectiveInjector} from '@angular/core'; +import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal'; export function main() { describe('Location', () => { diff --git a/modules/@angular/router-deprecated/test/location/path_location_strategy_spec.ts b/modules/@angular/router-deprecated/test/location/path_location_strategy_spec.ts index 52daf5c152..3b6f62ce80 100644 --- a/modules/@angular/router-deprecated/test/location/path_location_strategy_spec.ts +++ b/modules/@angular/router-deprecated/test/location/path_location_strategy_spec.ts @@ -6,10 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -import {describe, it, iit, ddescribe, expect, inject, beforeEach, beforeEachProviders,} from '@angular/core/testing/testing_internal'; - +import {APP_BASE_HREF, LocationStrategy, PathLocationStrategy, PlatformLocation} from '@angular/common'; import {Injector, provide} from '@angular/core'; -import {PlatformLocation, LocationStrategy, PathLocationStrategy, APP_BASE_HREF} from '@angular/common'; +import {beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal'; + import {SpyPlatformLocation} from '../spies'; export function main() { diff --git a/modules/@angular/router-deprecated/test/route_config/route_config_spec.ts b/modules/@angular/router-deprecated/test/route_config/route_config_spec.ts index a3adf2a9bd..bab4b52c9e 100644 --- a/modules/@angular/router-deprecated/test/route_config/route_config_spec.ts +++ b/modules/@angular/router-deprecated/test/route_config/route_config_spec.ts @@ -6,18 +6,17 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, beforeEach, ddescribe, describe, iit, inject, it, xdescribe, xit,} from '@angular/core/testing/testing_internal'; -import {expect} from '@angular/platform-browser/testing/matchers'; - -import {bootstrap} from '@angular/platform-browser-dynamic'; import {LocationStrategy} from '@angular/common'; -import {Component, Directive} from '@angular/core/src/metadata'; -import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; -import {Console} from '@angular/core/src/console'; -import {ExceptionHandler, disposePlatform} from '@angular/core'; -import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens'; -import {ROUTER_PROVIDERS, Router, RouteConfig, ROUTER_DIRECTIVES} from '@angular/router-deprecated'; import {MockLocationStrategy} from '@angular/common/testing/mock_location_strategy'; +import {ExceptionHandler, disposePlatform} from '@angular/core'; +import {Console} from '@angular/core/src/console'; +import {Component, Directive} from '@angular/core/src/metadata'; +import {AsyncTestCompleter, beforeEach, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; +import {bootstrap} from '@angular/platform-browser-dynamic'; +import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; +import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens'; +import {expect} from '@angular/platform-browser/testing/matchers'; +import {ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig, Router} from '@angular/router-deprecated'; class _ArrayLogger { res: any[] = []; diff --git a/modules/@angular/router-deprecated/test/route_registry_spec.ts b/modules/@angular/router-deprecated/test/route_registry_spec.ts index 042487a0b5..cf02fe2ad1 100644 --- a/modules/@angular/router-deprecated/test/route_registry_spec.ts +++ b/modules/@angular/router-deprecated/test/route_registry_spec.ts @@ -6,13 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, describe, it, iit, ddescribe, expect, inject, beforeEach,} from '@angular/core/testing/testing_internal'; - -import {PromiseWrapper} from '../src/facade/async'; +import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal'; import {Type} from '../src/facade/lang'; - +import {AsyncRoute, AuxRoute, Redirect, Route, RouteConfig} from '../src/route_config/route_config_decorator'; import {RouteRegistry} from '../src/route_registry'; -import {RouteConfig, Route, Redirect, AuxRoute, AsyncRoute} from '../src/route_config/route_config_decorator'; export function main() { @@ -322,11 +319,11 @@ function stringifyInstruction(instruction: any /** TODO #9100 */): string { function asyncParentLoader() { - return PromiseWrapper.resolve(DummyParentCmp); + return Promise.resolve(DummyParentCmp); } function asyncChildLoader() { - return PromiseWrapper.resolve(DummyCmpB); + return Promise.resolve(DummyCmpB); } class RootHostCmp {} diff --git a/modules/@angular/router-deprecated/test/router_spec.ts b/modules/@angular/router-deprecated/test/router_spec.ts index 7124bd5f92..2a01749e98 100644 --- a/modules/@angular/router-deprecated/test/router_spec.ts +++ b/modules/@angular/router-deprecated/test/router_spec.ts @@ -12,7 +12,6 @@ import {provide} from '@angular/core'; import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; import {RouterOutlet} from '../src/directives/router_outlet'; -import {ObservableWrapper, PromiseWrapper} from '../src/facade/async'; import {ListWrapper} from '../src/facade/collection'; import {Type} from '../src/facade/lang'; import {AsyncRoute, Redirect, Route, RouteConfig} from '../src/route_config/route_config_decorator'; @@ -194,7 +193,7 @@ export function main() { it('should, when subscribed to, return a disposable subscription', () => { expect(() => { var subscription = router.subscribe((_) => {}); - ObservableWrapper.dispose(subscription); + (subscription).unsubscribe(); }).not.toThrow(); }); @@ -326,7 +325,7 @@ function stringifyInstruction(instruction: any /** TODO #9100 */): string { } function loader(): Promise { - return PromiseWrapper.resolve(DummyComponent); + return Promise.resolve(DummyComponent); } class DummyComponent {} @@ -337,12 +336,10 @@ class DummyParentComp { function makeDummyOutlet(): RouterOutlet { var ref = new SpyRouterOutlet(); - ref.spy('canActivate').andCallFake((_: any /** TODO #9100 */) => PromiseWrapper.resolve(true)); - ref.spy('routerCanReuse') - .andCallFake((_: any /** TODO #9100 */) => PromiseWrapper.resolve(false)); - ref.spy('routerCanDeactivate') - .andCallFake((_: any /** TODO #9100 */) => PromiseWrapper.resolve(true)); - ref.spy('activate').andCallFake((_: any /** TODO #9100 */) => PromiseWrapper.resolve(true)); + ref.spy('canActivate').andCallFake((_: any /** TODO #9100 */) => Promise.resolve(true)); + ref.spy('routerCanReuse').andCallFake((_: any /** TODO #9100 */) => Promise.resolve(false)); + ref.spy('routerCanDeactivate').andCallFake((_: any /** TODO #9100 */) => Promise.resolve(true)); + ref.spy('activate').andCallFake((_: any /** TODO #9100 */) => Promise.resolve(true)); return ref; } diff --git a/modules/@angular/router-deprecated/test/rules/route_paths/param_route_path_spec.ts b/modules/@angular/router-deprecated/test/rules/route_paths/param_route_path_spec.ts index abc0866aa2..e5e7298276 100644 --- a/modules/@angular/router-deprecated/test/rules/route_paths/param_route_path_spec.ts +++ b/modules/@angular/router-deprecated/test/rules/route_paths/param_route_path_spec.ts @@ -6,10 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -import {describe, it, iit, ddescribe, expect, inject, beforeEach,} from '@angular/core/testing/testing_internal'; +import {beforeEach, ddescribe, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal'; import {ParamRoutePath} from '../../../src/rules/route_paths/param_route_path'; -import {parser, Url} from '../../../src/url_parser'; +import {Url, parser} from '../../../src/url_parser'; export function main() { describe('PathRecognizer', () => { diff --git a/modules/@angular/router-deprecated/test/rules/route_paths/regex_route_param_spec.ts b/modules/@angular/router-deprecated/test/rules/route_paths/regex_route_param_spec.ts index 97ce7c2d91..816047c227 100644 --- a/modules/@angular/router-deprecated/test/rules/route_paths/regex_route_param_spec.ts +++ b/modules/@angular/router-deprecated/test/rules/route_paths/regex_route_param_spec.ts @@ -6,10 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -import {describe, it, iit, ddescribe, expect, inject, beforeEach,} from '@angular/core/testing/testing_internal'; +import {beforeEach, ddescribe, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal'; -import {GeneratedUrl} from '../../../src/rules/route_paths/route_path'; import {RegexRoutePath} from '../../../src/rules/route_paths/regex_route_path'; +import {GeneratedUrl} from '../../../src/rules/route_paths/route_path'; import {parser} from '../../../src/url_parser'; function emptySerializer(params: any /** TODO #9100 */) { diff --git a/modules/@angular/router-deprecated/test/rules/rule_set_spec.ts b/modules/@angular/router-deprecated/test/rules/rule_set_spec.ts index 745d353aef..da4a7b3248 100644 --- a/modules/@angular/router-deprecated/test/rules/rule_set_spec.ts +++ b/modules/@angular/router-deprecated/test/rules/rule_set_spec.ts @@ -6,14 +6,13 @@ * found in the LICENSE file at https://angular.io/license */ -import {AsyncTestCompleter, describe, it, iit, ddescribe, inject, beforeEach,} from '@angular/core/testing/testing_internal'; +import {AsyncTestCompleter, beforeEach, ddescribe, describe, iit, inject, it} from '@angular/core/testing/testing_internal'; import {expect} from '@angular/platform-browser/testing/matchers'; -import {RouteMatch, PathMatch, RedirectMatch} from '../../src/rules/rules'; -import {RuleSet} from '../../src/rules/rule_set'; +import {Redirect, Route} from '../../src/route_config/route_config_decorator'; import {GeneratedUrl} from '../../src/rules/route_paths/route_path'; -import {Route, Redirect} from '../../src/route_config/route_config_decorator'; +import {RuleSet} from '../../src/rules/rule_set'; +import {PathMatch, RedirectMatch, RouteMatch} from '../../src/rules/rules'; import {parser} from '../../src/url_parser'; -import {PromiseWrapper} from '../../src/facade/promise'; export function main() { @@ -248,7 +247,7 @@ export function main() { function recognize(recognizer: RuleSet, url: string): Promise { var parsedUrl = parser.parse(url); - return PromiseWrapper.all(recognizer.recognize(parsedUrl)); + return Promise.all(recognizer.recognize(parsedUrl)); } function getComponentType(routeMatch: RouteMatch): any { diff --git a/modules/@angular/router-deprecated/test/url_parser_spec.ts b/modules/@angular/router-deprecated/test/url_parser_spec.ts index e723483344..264122c834 100644 --- a/modules/@angular/router-deprecated/test/url_parser_spec.ts +++ b/modules/@angular/router-deprecated/test/url_parser_spec.ts @@ -6,9 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -import {describe, it, iit, ddescribe, expect, inject, beforeEach,} from '@angular/core/testing/testing_internal'; +import {beforeEach, ddescribe, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal'; -import {UrlParser, Url} from '../src/url_parser'; +import {Url, UrlParser} from '../src/url_parser'; export function main() { diff --git a/modules/@angular/upgrade/test/metadata_spec.ts b/modules/@angular/upgrade/test/metadata_spec.ts index 04dd812287..61d859ef1f 100644 --- a/modules/@angular/upgrade/test/metadata_spec.ts +++ b/modules/@angular/upgrade/test/metadata_spec.ts @@ -6,9 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ -import {beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit,} from '@angular/core/testing/testing_internal'; - import {Component, Type} from '@angular/core'; +import {beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; import {getComponentInfo, parseFields} from '@angular/upgrade/src/metadata'; export function main() { diff --git a/modules/benchmarks/e2e_test/largetable_perf.ts b/modules/benchmarks/e2e_test/largetable_perf.ts index ae66894705..5466e3d5dc 100644 --- a/modules/benchmarks/e2e_test/largetable_perf.ts +++ b/modules/benchmarks/e2e_test/largetable_perf.ts @@ -22,8 +22,7 @@ describe('ng2 largetable benchmark', function() { buttons: ['#ng2DestroyDom', '#ng2CreateDom'], id: 'ng2.largetable.' + benchmarkType, params: [ - {name: 'rows', value: 20, scale: 'sqrt'}, - {name: 'columns', value: 20, scale: 'sqrt'}, + {name: 'rows', value: 20, scale: 'sqrt'}, {name: 'columns', value: 20, scale: 'sqrt'}, {name: 'benchmarkType', value: benchmarkType} ] }).then(done, done.fail); @@ -36,12 +35,10 @@ describe('ng2 largetable benchmark', function() { buttons: ['#baselineDestroyDom', '#baselineCreateDom'], id: 'baseline.largetable', params: [ - {name: 'rows', value: 100, scale: 'sqrt'}, - {name: 'columns', value: 20, scale: 'sqrt'}, + {name: 'rows', value: 100, scale: 'sqrt'}, {name: 'columns', value: 20, scale: 'sqrt'}, {name: 'benchmarkType', value: 'baseline'} ] }).then(done, done.fail); - ; }); }); diff --git a/modules/benchpress/src/metric/multi_metric.ts b/modules/benchpress/src/metric/multi_metric.ts index cb1bef6612..caf206092a 100644 --- a/modules/benchpress/src/metric/multi_metric.ts +++ b/modules/benchpress/src/metric/multi_metric.ts @@ -7,7 +7,6 @@ */ import {Injector, OpaqueToken} from '@angular/core/src/di'; -import {PromiseWrapper} from '@angular/facade/src/async'; import {StringMapWrapper} from '@angular/facade/src/collection'; import {Metric} from '../metric'; @@ -30,7 +29,7 @@ export class MultiMetric extends Metric { * Starts measuring */ beginMeasure(): Promise { - return PromiseWrapper.all(this._metrics.map(metric => metric.beginMeasure())); + return Promise.all(this._metrics.map(metric => metric.beginMeasure())); } /** @@ -39,8 +38,8 @@ export class MultiMetric extends Metric { * @param restart: Whether to restart right after this. */ endMeasure(restart: boolean): Promise<{[key: string]: any}> { - return PromiseWrapper.all(this._metrics.map(metric => metric.endMeasure(restart))) - .then(values => mergeStringMaps(values)); + return Promise.all(this._metrics.map(metric => metric.endMeasure(restart))) + .then(values => mergeStringMaps(values)); } /** @@ -52,7 +51,7 @@ export class MultiMetric extends Metric { } } -function mergeStringMaps(maps: {[key: string]: string}[]): Object { +function mergeStringMaps(maps: {[key: string]: string}[]): {[key: string]: string} { var result = {}; maps.forEach( map => { StringMapWrapper.forEach(map, (value, prop) => { result[prop] = value; }); }); diff --git a/modules/benchpress/src/metric/perflog_metric.ts b/modules/benchpress/src/metric/perflog_metric.ts index 9e5c1cd5ec..acda4e42f1 100644 --- a/modules/benchpress/src/metric/perflog_metric.ts +++ b/modules/benchpress/src/metric/perflog_metric.ts @@ -7,7 +7,6 @@ */ import {OpaqueToken} from '@angular/core/src/di'; -import {PromiseWrapper, TimerWrapper} from '@angular/facade/src/async'; import {ListWrapper, StringMapWrapper} from '@angular/facade/src/collection'; import {BaseException, WrappedException} from '@angular/facade/src/exceptions'; import {Math, NumberWrapper, StringWrapper, isBlank, isPresent} from '@angular/facade/src/lang'; @@ -110,7 +109,7 @@ export class PerflogMetric extends Metric { } beginMeasure(): Promise { - var resultPromise = PromiseWrapper.resolve(null); + var resultPromise = Promise.resolve(null); if (this._forceGc) { resultPromise = resultPromise.then((_) => this._driverExtension.gc()); } @@ -167,10 +166,10 @@ export class PerflogMetric extends Metric { this._remainingEvents = events; return result; } - var completer = PromiseWrapper.completer(); - this._setTimeout( - () => completer.resolve(this._readUntilEndMark(markName, loopCount + 1)), 100); - return completer.promise; + var resolve: (result: any) => void; + var promise = new Promise(res => { resolve = res; }); + this._setTimeout(() => resolve(this._readUntilEndMark(markName, loopCount + 1)), 100); + return promise; }); } @@ -402,5 +401,5 @@ var _PROVIDERS = [ Options.CAPTURE_FRAMES, Options.RECEIVED_DATA, Options.REQUEST_COUNT ] }, - {provide: _SET_TIMEOUT, useValue: (fn, millis) => TimerWrapper.setTimeout(fn, millis)} + {provide: _SET_TIMEOUT, useValue: (fn, millis) => setTimeout(fn, millis)} ]; diff --git a/modules/benchpress/src/metric/user_metric.ts b/modules/benchpress/src/metric/user_metric.ts index 541f901279..4ad9732712 100644 --- a/modules/benchpress/src/metric/user_metric.ts +++ b/modules/benchpress/src/metric/user_metric.ts @@ -7,7 +7,6 @@ */ import {OpaqueToken, Provider, bind} from '@angular/core'; -import {PromiseWrapper, TimerWrapper} from '@angular/facade/src/async'; import {StringMapWrapper} from '@angular/facade/src/collection'; import {isNumber} from '@angular/facade/src/lang'; @@ -26,35 +25,40 @@ export class UserMetric extends Metric { /** * Starts measuring */ - beginMeasure(): Promise { return PromiseWrapper.resolve(true); } + beginMeasure(): Promise { return Promise.resolve(true); } /** * Ends measuring. */ endMeasure(restart: boolean): Promise<{[key: string]: any}> { - let completer = PromiseWrapper.completer<{[key: string]: any}>(); + let resolve: (result: any) => void; + let reject: (error: any) => void; + let promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); let adapter = this._wdAdapter; let names = StringMapWrapper.keys(this._userMetrics); function getAndClearValues() { - PromiseWrapper.all(names.map(name => adapter.executeScript(`return window.${name}`))) + Promise.all(names.map(name => adapter.executeScript(`return window.${name}`))) .then((values: any[]) => { if (values.every(isNumber)) { - PromiseWrapper.all(names.map(name => adapter.executeScript(`delete window.${name}`))) + Promise.all(names.map(name => adapter.executeScript(`delete window.${name}`))) .then((_: any[]) => { let map = StringMapWrapper.create(); for (let i = 0, n = names.length; i < n; i++) { StringMapWrapper.set(map, names[i], values[i]); } - completer.resolve(map); - }, completer.reject); + resolve(map); + }, reject); } else { - TimerWrapper.setTimeout(getAndClearValues, 100); + setTimeout(getAndClearValues, 100); } - }, completer.reject); + }, reject); } getAndClearValues(); - return completer.promise; + return promise; } /** diff --git a/modules/benchpress/src/reporter/console_reporter.ts b/modules/benchpress/src/reporter/console_reporter.ts index e21fd66c34..ae057b240f 100644 --- a/modules/benchpress/src/reporter/console_reporter.ts +++ b/modules/benchpress/src/reporter/console_reporter.ts @@ -7,7 +7,6 @@ */ import {OpaqueToken} from '@angular/core/src/di'; -import {PromiseWrapper} from '@angular/facade/src/async'; import {ListWrapper, StringMapWrapper} from '@angular/facade/src/collection'; import {NumberWrapper, isBlank, isPresent, print} from '@angular/facade/src/lang'; import {Math} from '@angular/facade/src/math'; @@ -80,7 +79,7 @@ export class ConsoleReporter extends Reporter { return ConsoleReporter._formatNum(value); }); this._printStringRow(formattedValues); - return PromiseWrapper.resolve(null); + return Promise.resolve(null); } reportSample(completeSample: MeasureValues[], validSamples: MeasureValues[]): Promise { @@ -94,7 +93,7 @@ export class ConsoleReporter extends Reporter { // hickups for consoles... return NumberWrapper.isNaN(cv) ? formattedMean : `${formattedMean}+-${Math.floor(cv)}%`; })); - return PromiseWrapper.resolve(null); + return Promise.resolve(null); } /** @internal */ diff --git a/modules/benchpress/src/reporter/json_file_reporter.ts b/modules/benchpress/src/reporter/json_file_reporter.ts index e06c78df30..30c877a4c8 100644 --- a/modules/benchpress/src/reporter/json_file_reporter.ts +++ b/modules/benchpress/src/reporter/json_file_reporter.ts @@ -7,7 +7,6 @@ */ import {OpaqueToken} from '@angular/core/src/di'; -import {PromiseWrapper} from '@angular/facade/src/async'; import {DateWrapper, Json, isBlank, isPresent} from '@angular/facade/src/lang'; import {Options} from '../common_options'; @@ -42,9 +41,7 @@ export class JsonFileReporter extends Reporter { this._now = now; } - reportMeasureValues(measureValues: MeasureValues): Promise { - return PromiseWrapper.resolve(null); - } + reportMeasureValues(measureValues: MeasureValues): Promise { return Promise.resolve(null); } reportSample(completeSample: MeasureValues[], validSample: MeasureValues[]): Promise { var content = Json.stringify({ diff --git a/modules/benchpress/src/reporter/multi_reporter.ts b/modules/benchpress/src/reporter/multi_reporter.ts index 26216a380d..49f24eef02 100644 --- a/modules/benchpress/src/reporter/multi_reporter.ts +++ b/modules/benchpress/src/reporter/multi_reporter.ts @@ -7,7 +7,6 @@ */ import {Injector, OpaqueToken} from '@angular/core/src/di'; -import {PromiseWrapper} from '@angular/facade/src/async'; import {MeasureValues} from '../measure_values'; import {Reporter} from '../reporter'; @@ -37,12 +36,11 @@ export class MultiReporter extends Reporter { } reportMeasureValues(values: MeasureValues): Promise { - return PromiseWrapper.all( - this._reporters.map(reporter => reporter.reportMeasureValues(values))); + return Promise.all(this._reporters.map(reporter => reporter.reportMeasureValues(values))); } reportSample(completeSample: MeasureValues[], validSample: MeasureValues[]): Promise { - return PromiseWrapper.all( + return Promise.all( this._reporters.map(reporter => reporter.reportSample(completeSample, validSample))); } } diff --git a/modules/benchpress/src/runner.ts b/modules/benchpress/src/runner.ts index c9c2486162..3b88472135 100644 --- a/modules/benchpress/src/runner.ts +++ b/modules/benchpress/src/runner.ts @@ -7,7 +7,6 @@ */ import {ReflectiveInjector} from '@angular/core'; -import {PromiseWrapper} from '@angular/facade/src/async'; import {isBlank, isPresent} from '@angular/facade/src/lang'; import {Options} from './common_options'; @@ -71,7 +70,7 @@ export class Runner { var inj = ReflectiveInjector.resolveAndCreate(sampleProviders); var adapter = inj.get(WebDriverAdapter); - return PromiseWrapper + return Promise .all([adapter.capabilities(), adapter.executeScript('return window.navigator.userAgent;')]) .then((args) => { var capabilities = args[0]; diff --git a/modules/benchpress/src/sampler.ts b/modules/benchpress/src/sampler.ts index d9707919b1..4dd9716161 100644 --- a/modules/benchpress/src/sampler.ts +++ b/modules/benchpress/src/sampler.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import {PromiseWrapper} from '@angular/facade/src/async'; import {Date, DateWrapper, isBlank, isPresent} from '@angular/facade/src/lang'; import {Options} from './common_options'; @@ -82,7 +81,7 @@ export class Sampler { if (isPresent(this._prepare)) { resultPromise = this._driver.waitFor(this._prepare); } else { - resultPromise = PromiseWrapper.resolve(null); + resultPromise = Promise.resolve(null); } if (isPresent(this._prepare) || lastState.completeSample.length === 0) { resultPromise = resultPromise.then((_) => this._metric.beginMeasure()); diff --git a/modules/benchpress/src/webdriver/selenium_webdriver_adapter.ts b/modules/benchpress/src/webdriver/selenium_webdriver_adapter.ts index b1939730b2..acab3bc104 100644 --- a/modules/benchpress/src/webdriver/selenium_webdriver_adapter.ts +++ b/modules/benchpress/src/webdriver/selenium_webdriver_adapter.ts @@ -6,12 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ -import {PromiseWrapper} from '@angular/facade/src/async'; import * as webdriver from 'selenium-webdriver'; import {WebDriverAdapter} from '../web_driver_adapter'; + /** * Adapter for the selenium-webdriver. */ @@ -22,13 +22,18 @@ export class SeleniumWebDriverAdapter extends WebDriverAdapter { /** @internal */ private _convertPromise(thenable) { - var completer = PromiseWrapper.completer(); + var resolve: (result: any) => void; + var reject: (error: any) => void; + var promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); thenable.then( // selenium-webdriver uses an own Node.js context, // so we need to convert data into objects of this context. // Previously needed for rtts_asserts. - (data) => completer.resolve(convertToLocalProcess(data)), completer.reject); - return completer.promise; + (data) => resolve(convertToLocalProcess(data)), reject); + return promise; } waitFor(callback): Promise { diff --git a/modules/benchpress/test/metric/perflog_metric_spec.ts b/modules/benchpress/test/metric/perflog_metric_spec.ts index 1f4577003e..f5a487c710 100644 --- a/modules/benchpress/test/metric/perflog_metric_spec.ts +++ b/modules/benchpress/test/metric/perflog_metric_spec.ts @@ -7,7 +7,6 @@ */ import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; -import {PromiseWrapper} from '@angular/facade/src/async'; import {StringMapWrapper} from '@angular/facade/src/collection'; import {isBlank, isPresent} from '@angular/facade/src/lang'; import {Metric, Options, PerfLogFeatures, PerflogMetric, ReflectiveInjector, WebDriverExtension} from 'benchpress/common'; @@ -320,11 +319,11 @@ export function main() { })); it('should throw if no start event', inject([AsyncTestCompleter], (async) => { - PromiseWrapper.catchError( - aggregate( - [eventFactory.instant('frame', 4), eventFactory.markEnd('frameCapture', 5)], - {captureFrames: true}), - (err): any => { + + aggregate( + [eventFactory.instant('frame', 4), eventFactory.markEnd('frameCapture', 5)], + {captureFrames: true}) + .catch((err): any => { expect(() => { throw err; }).toThrowError('missing start event for frame capture'); @@ -333,25 +332,25 @@ export function main() { })); it('should throw if no end event', inject([AsyncTestCompleter], (async) => { - PromiseWrapper.catchError( - aggregate( - [eventFactory.markStart('frameCapture', 3), eventFactory.instant('frame', 4)], - {captureFrames: true}), - (err): any => { + + aggregate( + [eventFactory.markStart('frameCapture', 3), eventFactory.instant('frame', 4)], + {captureFrames: true}) + .catch((err): any => { expect(() => { throw err; }).toThrowError('missing end event for frame capture'); async.done(); }); })); it('should throw if trying to capture twice', inject([AsyncTestCompleter], (async) => { - PromiseWrapper.catchError( - aggregate( - [ - eventFactory.markStart('frameCapture', 3), - eventFactory.markStart('frameCapture', 4) - ], - {captureFrames: true}), - (err): any => { + + aggregate( + [ + eventFactory.markStart('frameCapture', 3), + eventFactory.markStart('frameCapture', 4) + ], + {captureFrames: true}) + .catch((err): any => { expect(() => { throw err; }).toThrowError('can capture frames only once per benchmark run'); @@ -361,7 +360,7 @@ export function main() { it('should throw if trying to capture when frame capture is disabled', inject([AsyncTestCompleter], (async) => { - PromiseWrapper.catchError(aggregate([eventFactory.markStart('frameCapture', 3)]), (err) => { + aggregate([eventFactory.markStart('frameCapture', 3)]).catch((err) => { expect(() => { throw err; }) .toThrowError( 'found start event for frame capture, but frame capture was not requested in benchpress'); @@ -372,7 +371,7 @@ export function main() { it('should throw if frame capture is enabled, but nothing is captured', inject([AsyncTestCompleter], (async) => { - PromiseWrapper.catchError(aggregate([], {captureFrames: true}), (err): any => { + aggregate([], {captureFrames: true}).catch((err): any => { expect(() => { throw err; }) .toThrowError( 'frame capture requested in benchpress, but no start event was found'); @@ -638,12 +637,12 @@ class MockDriverExtension extends WebDriverExtension { timeBegin(name): Promise { this._commandLog.push(['timeBegin', name]); - return PromiseWrapper.resolve(null); + return Promise.resolve(null); } timeEnd(name, restartName): Promise { this._commandLog.push(['timeEnd', name, restartName]); - return PromiseWrapper.resolve(null); + return Promise.resolve(null); } perfLogFeatures(): PerfLogFeatures { return this._perfLogFeatures; } @@ -653,14 +652,14 @@ class MockDriverExtension extends WebDriverExtension { if (this._perfLogs.length > 0) { var next = this._perfLogs[0]; this._perfLogs.shift(); - return PromiseWrapper.resolve(next); + return Promise.resolve(next); } else { - return PromiseWrapper.resolve([]); + return Promise.resolve([]); } } gc(): Promise { this._commandLog.push(['gc']); - return PromiseWrapper.resolve(null); + return Promise.resolve(null); } } diff --git a/modules/benchpress/test/metric/user_metric_spec.ts b/modules/benchpress/test/metric/user_metric_spec.ts index 86a1000a07..1e50f376b9 100644 --- a/modules/benchpress/test/metric/user_metric_spec.ts +++ b/modules/benchpress/test/metric/user_metric_spec.ts @@ -8,7 +8,6 @@ import {ReflectiveInjector} from '@angular/core'; import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; -import {PromiseWrapper, TimerWrapper} from '@angular/facade/src/async'; import {StringMapWrapper} from '@angular/facade/src/collection'; import {Json, isBlank, isPresent} from '@angular/facade/src/lang'; import {Injector, Metric, MultiMetric, Options, PerfLogFeatures, PerflogMetric, UserMetric, WebDriverAdapter, WebDriverExtension, bind, provide} from 'benchpress/common'; @@ -60,7 +59,7 @@ export function main() { wdAdapter.data['loadTime'] = 25; // Wait before setting 2nd property. - TimerWrapper.setTimeout(() => { wdAdapter.data['content'] = 250; }, 50); + setTimeout(() => { wdAdapter.data['content'] = 250; }, 50); }), 600); }); @@ -74,11 +73,11 @@ class MockDriverAdapter extends WebDriverAdapter { // Just handles `return window.propName` ignores `delete window.propName`. if (script.indexOf('return window.') == 0) { let metricName = script.substring('return window.'.length); - return PromiseWrapper.resolve(this.data[metricName]); + return Promise.resolve(this.data[metricName]); } else if (script.indexOf('delete window.') == 0) { - return PromiseWrapper.resolve(null); + return Promise.resolve(null); } else { - return PromiseWrapper.reject(`Unexpected syntax: ${script}`, null); + return Promise.reject(`Unexpected syntax: ${script}`); } } } diff --git a/modules/benchpress/test/reporter/json_file_reporter_spec.ts b/modules/benchpress/test/reporter/json_file_reporter_spec.ts index 62c2d96fd5..b3266dab4b 100644 --- a/modules/benchpress/test/reporter/json_file_reporter_spec.ts +++ b/modules/benchpress/test/reporter/json_file_reporter_spec.ts @@ -7,7 +7,6 @@ */ import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; -import {PromiseWrapper} from '@angular/facade/src/async'; import {DateWrapper, Json, isPresent} from '@angular/facade/src/lang'; import {MeasureValues, Options, ReflectiveInjector, SampleDescription} from 'benchpress/common'; import {JsonFileReporter} from 'benchpress/src/reporter/json_file_reporter'; @@ -27,7 +26,7 @@ export function main() { provide: Options.WRITE_FILE, useValue: (filename, content) => { loggedFile = {'filename': filename, 'content': content}; - return PromiseWrapper.resolve(null); + return Promise.resolve(null); } } ]; diff --git a/modules/benchpress/test/reporter/multi_reporter_spec.ts b/modules/benchpress/test/reporter/multi_reporter_spec.ts index 021e298d37..829448a1e2 100644 --- a/modules/benchpress/test/reporter/multi_reporter_spec.ts +++ b/modules/benchpress/test/reporter/multi_reporter_spec.ts @@ -7,7 +7,6 @@ */ import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; -import {PromiseWrapper} from '@angular/facade/src/async'; import {DateWrapper} from '@angular/facade/src/lang'; import {MeasureValues, MultiReporter, ReflectiveInjector, Reporter} from 'benchpress/common'; @@ -19,7 +18,7 @@ export function main() { MultiReporter.createBindings(ids) ]) .get(MultiReporter); - return PromiseWrapper.resolve(r); + return Promise.resolve(r); } describe('multi reporter', () => { @@ -58,12 +57,12 @@ class MockReporter extends Reporter { constructor(private _id: string) { super(); } reportMeasureValues(values: MeasureValues): Promise<{[key: string]: any}> { - return PromiseWrapper.resolve({'id': this._id, 'values': values}); + return Promise.resolve({'id': this._id, 'values': values}); } reportSample(completeSample: MeasureValues[], validSample: MeasureValues[]): Promise<{[key: string]: any}> { - return PromiseWrapper.resolve( + return Promise.resolve( {'id': this._id, 'completeSample': completeSample, 'validSample': validSample}); } } diff --git a/modules/benchpress/test/runner_spec.ts b/modules/benchpress/test/runner_spec.ts index a812c51807..42f6a733d3 100644 --- a/modules/benchpress/test/runner_spec.ts +++ b/modules/benchpress/test/runner_spec.ts @@ -7,7 +7,6 @@ */ import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; -import {PromiseWrapper} from '@angular/facade/src/async'; import {isBlank} from '@angular/facade/src/lang'; import {Injector, Metric, Options, ReflectiveInjector, Runner, SampleDescription, SampleState, Sampler, Validator, WebDriverAdapter} from 'benchpress/common'; @@ -115,7 +114,7 @@ export function main() { } class MockWebDriverAdapter extends WebDriverAdapter { - executeScript(script): Promise { return PromiseWrapper.resolve('someUserAgent'); } + executeScript(script): Promise { return Promise.resolve('someUserAgent'); } capabilities() { return null; } } @@ -131,5 +130,5 @@ class MockMetric extends Metric { class MockSampler extends Sampler { constructor() { super(); } - sample(): Promise { return PromiseWrapper.resolve(new SampleState([], [])); } + sample(): Promise { return Promise.resolve(new SampleState([], [])); } } diff --git a/modules/benchpress/test/sampler_spec.ts b/modules/benchpress/test/sampler_spec.ts index 0f818021b2..04750ffdb4 100644 --- a/modules/benchpress/test/sampler_spec.ts +++ b/modules/benchpress/test/sampler_spec.ts @@ -7,7 +7,6 @@ */ import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; -import {PromiseWrapper} from '@angular/facade/src/async'; import {Date, DateWrapper, isBlank, isPresent, stringify} from '@angular/facade/src/lang'; import {MeasureValues, Metric, Options, ReflectiveInjector, Reporter, Sampler, Validator, WebDriverAdapter} from 'benchpress/common'; @@ -55,7 +54,7 @@ export function main() { var driver = new MockDriverAdapter([], (callback) => { var result = callback(); log.push(result); - return PromiseWrapper.resolve(result); + return Promise.resolve(result); }); createSampler({ driver: driver, @@ -127,7 +126,7 @@ export function main() { metric: new MockMetric( [], () => { - var result = PromiseWrapper.resolve({'script': scriptTime}); + var result = Promise.resolve({'script': scriptTime}); scriptTime = 0; return result; }), @@ -238,7 +237,7 @@ class MockDriverAdapter extends WebDriverAdapter { if (isPresent(this._waitFor)) { return this._waitFor(callback); } else { - return PromiseWrapper.resolve(callback()); + return Promise.resolve(callback()); } } } @@ -273,12 +272,12 @@ class MockMetric extends Metric { } beginMeasure() { this._log.push(['beginMeasure']); - return PromiseWrapper.resolve(null); + return Promise.resolve(null); } endMeasure(restart) { var measureValues = isPresent(this._endMeasure) ? this._endMeasure() : {}; this._log.push(['endMeasure', restart, measureValues]); - return PromiseWrapper.resolve(measureValues); + return Promise.resolve(measureValues); } } @@ -294,10 +293,10 @@ class MockReporter extends Reporter { } reportMeasureValues(values): Promise { this._log.push(['reportMeasureValues', values]); - return PromiseWrapper.resolve(null); + return Promise.resolve(null); } reportSample(completeSample, validSample): Promise { this._log.push(['reportSample', completeSample, validSample]); - return PromiseWrapper.resolve(null); + return Promise.resolve(null); } } diff --git a/modules/benchpress/test/web_driver_extension_spec.ts b/modules/benchpress/test/web_driver_extension_spec.ts index d16961b4fb..21f41432eb 100644 --- a/modules/benchpress/test/web_driver_extension_spec.ts +++ b/modules/benchpress/test/web_driver_extension_spec.ts @@ -7,19 +7,22 @@ */ import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; -import {PromiseWrapper} from '@angular/facade/src/async'; import {StringWrapper, isPresent} from '@angular/facade/src/lang'; import {Options, ReflectiveInjector, WebDriverExtension} from 'benchpress/common'; export function main() { function createExtension(ids: any[], caps) { - return PromiseWrapper.wrap(() => { - return ReflectiveInjector - .resolveAndCreate([ - ids.map((id) => { return {provide: id, useValue: new MockExtension(id)}; }), - {provide: Options.CAPABILITIES, useValue: caps}, WebDriverExtension.bindTo(ids) - ]) - .get(WebDriverExtension); + return new Promise((res, rej) => { + try { + res(ReflectiveInjector + .resolveAndCreate([ + ids.map((id) => { return {provide: id, useValue: new MockExtension(id)}; }), + {provide: Options.CAPABILITIES, useValue: caps}, WebDriverExtension.bindTo(ids) + ]) + .get(WebDriverExtension)); + } catch (e) { + rej(e); + } }); } @@ -34,7 +37,7 @@ export function main() { })); it('should throw if there is no match', inject([AsyncTestCompleter], (async) => { - PromiseWrapper.catchError(createExtension(['m1'], {'browser': 'm2'}), (err) => { + createExtension(['m1'], {'browser': 'm2'}).catch((err) => { expect(isPresent(err)).toBe(true); async.done(); }); diff --git a/modules/benchpress/test/webdriver/chrome_driver_extension_spec.ts b/modules/benchpress/test/webdriver/chrome_driver_extension_spec.ts index d782992e03..d3e9236ad7 100644 --- a/modules/benchpress/test/webdriver/chrome_driver_extension_spec.ts +++ b/modules/benchpress/test/webdriver/chrome_driver_extension_spec.ts @@ -7,7 +7,6 @@ */ import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; -import {PromiseWrapper} from '@angular/facade/src/async'; import {Json, isBlank} from '@angular/facade/src/lang'; import {ChromeDriverExtension, Options, ReflectiveInjector, WebDriverAdapter, WebDriverExtension} from 'benchpress/common'; @@ -433,13 +432,12 @@ export function main() { it('should throw when ImplThreadRenderingStats contains more than one frame', inject([AsyncTestCompleter], (async) => { - PromiseWrapper.catchError( - createExtension([ - benchmarkEvents.instant( - 'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100, - {'data': {'frame_count': 2}}) - ]).readPerfLog(), - (err): any => { + + createExtension([benchmarkEvents.instant( + 'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100, + {'data': {'frame_count': 2}})]) + .readPerfLog() + .catch((err): any => { expect(() => { throw err; }).toThrowError('multi-frame render stats not supported'); @@ -468,14 +466,14 @@ export function main() { })); it('should throw an error on buffer overflow', inject([AsyncTestCompleter], (async) => { - PromiseWrapper.catchError( - createExtension( - [ - chromeTimelineEvents.start('FunctionCall', 1234), - ], - CHROME45_USER_AGENT, 'Tracing.bufferUsage') - .readPerfLog(), - (err): any => { + + createExtension( + [ + chromeTimelineEvents.start('FunctionCall', 1234), + ], + CHROME45_USER_AGENT, 'Tracing.bufferUsage') + .readPerfLog() + .catch((err): any => { expect(() => { throw err; }).toThrowError('The DevTools trace buffer filled during the test!'); @@ -501,13 +499,13 @@ class MockDriverAdapter extends WebDriverAdapter { executeScript(script) { this._log.push(['executeScript', script]); - return PromiseWrapper.resolve(null); + return Promise.resolve(null); } logs(type) { this._log.push(['logs', type]); if (type === 'performance') { - return PromiseWrapper.resolve(this._events.map((event) => { + return Promise.resolve(this._events.map((event) => { return { 'message': Json.stringify({'message': {'method': this._messageMethod, 'params': event}}) }; diff --git a/modules/benchpress/test/webdriver/ios_driver_extension_spec.ts b/modules/benchpress/test/webdriver/ios_driver_extension_spec.ts index 5d929ca12c..407728a7ab 100644 --- a/modules/benchpress/test/webdriver/ios_driver_extension_spec.ts +++ b/modules/benchpress/test/webdriver/ios_driver_extension_spec.ts @@ -7,10 +7,8 @@ */ import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; -import {PromiseWrapper} from '@angular/facade/src/async'; import {Json, isBlank, isPresent} from '@angular/facade/src/lang'; - -import {WebDriverExtension, IOsDriverExtension, WebDriverAdapter, ReflectiveInjector,} from 'benchpress/common'; +import {IOsDriverExtension, ReflectiveInjector, WebDriverAdapter, WebDriverExtension} from 'benchpress/common'; import {TraceEventFactory} from '../trace_event_factory'; @@ -172,13 +170,13 @@ class MockDriverAdapter extends WebDriverAdapter { executeScript(script) { this._log.push(['executeScript', script]); - return PromiseWrapper.resolve(null); + return Promise.resolve(null); } logs(type) { this._log.push(['logs', type]); if (type === 'performance') { - return PromiseWrapper.resolve(this._perfRecords.map(function(record) { + return Promise.resolve(this._perfRecords.map(function(record) { return { 'message': Json.stringify( {'message': {'method': 'Timeline.eventRecorded', 'params': {'record': record}}}) diff --git a/modules/playground/src/async/index.ts b/modules/playground/src/async/index.ts index cd9684e923..0b677c399f 100644 --- a/modules/playground/src/async/index.ts +++ b/modules/playground/src/async/index.ts @@ -8,7 +8,6 @@ import {NgIf} from '@angular/common'; import {Component} from '@angular/core'; -import {TimerWrapper} from '@angular/core/src/facade/async'; import {bootstrap} from '@angular/platform-browser-dynamic'; @Component({ @@ -49,7 +48,7 @@ class AsyncApplication { delayedIncrement(): void { this.cancelDelayedIncrement(); - this.timeoutId = TimerWrapper.setTimeout(() => { + this.timeoutId = setTimeout(() => { this.val2++; this.timeoutId = null; }, 2000); @@ -65,7 +64,7 @@ class AsyncApplication { return; } - self.multiTimeoutId = TimerWrapper.setTimeout(() => { + self.multiTimeoutId = setTimeout(() => { self.val3++; helper(_i - 1); }, 500); @@ -75,26 +74,26 @@ class AsyncApplication { periodicIncrement(): void { this.cancelPeriodicIncrement(); - this.intervalId = TimerWrapper.setInterval(() => { this.val4++; }, 2000) + this.intervalId = setInterval(() => { this.val4++; }, 2000) }; cancelDelayedIncrement(): void { if (this.timeoutId != null) { - TimerWrapper.clearTimeout(this.timeoutId); + clearTimeout(this.timeoutId); this.timeoutId = null; } }; cancelMultiDelayedIncrements(): void { if (this.multiTimeoutId != null) { - TimerWrapper.clearTimeout(this.multiTimeoutId); + clearTimeout(this.multiTimeoutId); this.multiTimeoutId = null; } }; cancelPeriodicIncrement(): void { if (this.intervalId != null) { - TimerWrapper.clearInterval(this.intervalId); + clearInterval(this.intervalId); this.intervalId = null; } }; diff --git a/modules/playground/src/routing/app/inbox-app.ts b/modules/playground/src/routing/app/inbox-app.ts index b90c4615f7..9bf9c37ca6 100644 --- a/modules/playground/src/routing/app/inbox-app.ts +++ b/modules/playground/src/routing/app/inbox-app.ts @@ -8,7 +8,6 @@ import {Location} from '@angular/common'; import {Component, Injectable} from '@angular/core'; -import {PromiseCompleter, PromiseWrapper} from '@angular/core/src/facade/async'; import {DateWrapper, isPresent} from '@angular/core/src/facade/lang'; import {ActivatedRoute, Router} from '@angular/router'; @@ -60,11 +59,7 @@ export class InboxRecord { @Injectable() export class DbService { - getData(): Promise { - var p = new PromiseCompleter(); - p.resolve(db.data); - return p.promise; - } + getData(): Promise { return Promise.resolve(db.data); } drafts(): Promise { return this.getData().then( @@ -78,7 +73,7 @@ export class DbService { } email(id: any /** TODO #9100 */): Promise { - return PromiseWrapper.then(this.getData(), (data: any[]) => { + return this.getData().then((data: any[]) => { for (var i = 0; i < data.length; i++) { var entry = data[i]; if (entry['id'] == id) { @@ -100,7 +95,7 @@ export class InboxCmp { const sortType = p['sort']; const sortEmailsByDate = isPresent(sortType) && sortType == 'date'; - PromiseWrapper.then(db.emails(), (emails: any[]) => { + db.emails().then((emails: any[]) => { this.ready = true; this.items = emails.map(data => new InboxRecord(data)); @@ -124,7 +119,7 @@ export class DraftsCmp { private ready: boolean = false; constructor(private router: Router, db: DbService) { - PromiseWrapper.then(db.drafts(), (drafts: any[]) => { + db.drafts().then((drafts: any[]) => { this.ready = true; this.items = drafts.map(data => new InboxRecord(data)); }); diff --git a/modules/playground/src/routing/app/inbox-detail.ts b/modules/playground/src/routing/app/inbox-detail.ts index ab8df84905..f0d85c1f6a 100644 --- a/modules/playground/src/routing/app/inbox-detail.ts +++ b/modules/playground/src/routing/app/inbox-detail.ts @@ -7,7 +7,6 @@ */ import {Component, NgModule} from '@angular/core'; -import {PromiseWrapper} from '@angular/core/src/facade/async'; import {ActivatedRoute, RouterModule} from '@angular/router'; import {DbService, InboxRecord} from './inbox-app'; @@ -19,7 +18,7 @@ export class InboxDetailCmp { constructor(db: DbService, route: ActivatedRoute) { route.params.forEach( - p => { PromiseWrapper.then(db.email(p['id']), (data) => { this.record.setData(data); }); }); + p => { db.email(p['id']).then((data) => { this.record.setData(data); }); }); } } diff --git a/modules/playground/src/routing_deprecated/app/inbox-app.ts b/modules/playground/src/routing_deprecated/app/inbox-app.ts index c3bd7aaa64..003abee516 100644 --- a/modules/playground/src/routing_deprecated/app/inbox-app.ts +++ b/modules/playground/src/routing_deprecated/app/inbox-app.ts @@ -8,7 +8,6 @@ import {Location} from '@angular/common'; import {Component, Injectable} from '@angular/core'; -import {PromiseCompleter, PromiseWrapper} from '@angular/core/src/facade/async'; import {DateWrapper, isPresent} from '@angular/core/src/facade/lang'; import {Route, RouteConfig, RouteParams, Router, RouterLink, RouterOutlet} from '@angular/router-deprecated'; @@ -60,11 +59,7 @@ class InboxRecord { @Injectable() class DbService { - getData(): Promise { - var p = new PromiseCompleter(); - p.resolve(db.data); - return p.promise; - } + getData(): Promise { return Promise.resolve(db.data); } drafts(): Promise { return this.getData().then( @@ -78,7 +73,7 @@ class DbService { } email(id: any /** TODO #9100 */): Promise { - return PromiseWrapper.then(this.getData(), (data: any[]) => { + return this.getData().then((data: any[]) => { for (var i = 0; i < data.length; i++) { var entry = data[i]; if (entry['id'] == id) { @@ -98,7 +93,7 @@ class InboxDetailCmp { constructor(db: DbService, params: RouteParams) { var id = params.get('id'); - PromiseWrapper.then(db.email(id), (data) => { this.record.setData(data); }); + db.email(id).then((data) => { this.record.setData(data); }); } } @@ -111,7 +106,7 @@ class InboxCmp { var sortType = params.get('sort'); var sortEmailsByDate = isPresent(sortType) && sortType == 'date'; - PromiseWrapper.then(db.emails(), (emails: any[]) => { + db.emails().then((emails: any[]) => { this.ready = true; this.items = emails.map(data => new InboxRecord(data)); @@ -134,7 +129,7 @@ class DraftsCmp { ready: boolean = false; constructor(public router: Router, db: DbService) { - PromiseWrapper.then(db.drafts(), (drafts: any[]) => { + db.drafts().then((drafts: any[]) => { this.ready = true; this.items = drafts.map(data => new InboxRecord(data)); }); diff --git a/modules/playground/src/web_workers/images/index_common.ts b/modules/playground/src/web_workers/images/index_common.ts index 992df58065..0689f694ba 100644 --- a/modules/playground/src/web_workers/images/index_common.ts +++ b/modules/playground/src/web_workers/images/index_common.ts @@ -7,7 +7,6 @@ */ import {Component} from '@angular/core'; -import {TimerWrapper} from '@angular/core/src/facade/async'; import {EventListener} from '@angular/core/src/facade/browser'; import {FileReader, Uint8ArrayWrapper} from './file_api'; @@ -44,7 +43,7 @@ export class ImageDemo { for (var i = 0; i < this.images.length; i++) { this.images[i].filtering = true; - TimerWrapper.setTimeout(this._filter(i), 0); + setTimeout(this._filter(i), 0); } } diff --git a/modules/playground/src/web_workers/message_broker/index_common.ts b/modules/playground/src/web_workers/message_broker/index_common.ts index 5027f0b14b..d726a24f32 100644 --- a/modules/playground/src/web_workers/message_broker/index_common.ts +++ b/modules/playground/src/web_workers/message_broker/index_common.ts @@ -7,7 +7,6 @@ */ import {Component} from '@angular/core'; -import {PromiseWrapper} from '@angular/core/src/facade/async'; import {PRIMITIVE, ServiceMessageBrokerFactory} from '@angular/platform-browser'; const ECHO_CHANNEL = 'ECHO'; @@ -20,6 +19,12 @@ export class App { } private _echo(val: string) { - return PromiseWrapper.wrap(() => { return val; }); + return new Promise((res, rej) => { + try { + res(val); + } catch (e) { + rej(e); + } + }); } } diff --git a/modules/playground/src/zippy_component/app/zippy.ts b/modules/playground/src/zippy_component/app/zippy.ts index 5d570270b7..dd738bae1d 100644 --- a/modules/playground/src/zippy_component/app/zippy.ts +++ b/modules/playground/src/zippy_component/app/zippy.ts @@ -7,7 +7,6 @@ */ import {Component, EventEmitter, Input, Output} from '@angular/core'; -import {ObservableWrapper} from '@angular/core/src/facade/async'; @Component({selector: 'zippy', templateUrl: 'app/zippy.html'}) export class Zippy { @@ -19,9 +18,9 @@ export class Zippy { toggle() { this.visible = !this.visible; if (this.visible) { - ObservableWrapper.callEmit(this.open, null); + this.open.emit(null); } else { - ObservableWrapper.callEmit(this.close, null); + this.close.emit(null); } } }