Skip to content

Commit 7cbaf10

Browse files
committed
refactor(Async): Unify TS and Dart PromiseCompleter naming
Also add explicit typing wherever we use PromiseCompleter
1 parent a8b5725 commit 7cbaf10

File tree

10 files changed

+41
-27
lines changed

10 files changed

+41
-27
lines changed

modules/angular2/src/core/application_common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {StyleInliner} from 'angular2/src/render/dom/compiler/style_inliner';
3030
import {ViewResolver} from './compiler/view_resolver';
3131
import {DirectiveResolver} from './compiler/directive_resolver';
3232
import {List, ListWrapper} from 'angular2/src/facade/collection';
33-
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
33+
import {Promise, PromiseWrapper, PromiseCompleter} from 'angular2/src/facade/async';
3434
import {NgZone} from 'angular2/src/core/zone/ng_zone';
3535
import {LifeCycle} from 'angular2/src/core/life_cycle/life_cycle';
3636
import {ShadowDomStrategy} from 'angular2/src/render/dom/shadow_dom/shadow_dom_strategy';
@@ -280,7 +280,7 @@ export function commonBootstrap(
280280
appComponentType: /*Type*/ any,
281281
componentInjectableBindings: List<Type | Binding | List<any>> = null): Promise<ApplicationRef> {
282282
BrowserDomAdapter.makeCurrent();
283-
var bootstrapProcess = PromiseWrapper.completer();
283+
var bootstrapProcess: PromiseCompleter<any> = PromiseWrapper.completer();
284284
var zone = createNgZone(new ExceptionHandler(DOM));
285285
zone.run(() => {
286286
// TODO(rado): prepopulate template cache, so applications with only

modules/angular2/src/facade/async.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class PromiseWrapper {
2929
return promise.catchError(onError);
3030
}
3131

32-
static CompleterWrapper completer() => new CompleterWrapper(new Completer());
32+
static PromiseCompleter<dynamic> completer() => new PromiseCompleter(new Completer());
3333
}
3434

3535
class TimerWrapper {
@@ -104,10 +104,10 @@ class EventEmitter extends Stream {
104104
}
105105
}
106106

107-
class CompleterWrapper {
108-
final Completer c;
107+
class PromiseCompleter<T> {
108+
final Completer<T> c;
109109

110-
CompleterWrapper(this.c);
110+
PromiseCompleter(this.c);
111111

112112
Future get promise => c.future;
113113

modules/angular2/src/forms/directives/ng_form.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import {PromiseWrapper, ObservableWrapper, EventEmitter} from 'angular2/src/facade/async';
1+
import {
2+
PromiseWrapper,
3+
ObservableWrapper,
4+
EventEmitter,
5+
PromiseCompleter
6+
} from 'angular2/src/facade/async';
27
import {StringMapWrapper, List, ListWrapper} from 'angular2/src/facade/collection';
38
import {isPresent, isBlank, CONST_EXPR} from 'angular2/src/facade/lang';
49
import {Directive} from 'angular2/annotations';
@@ -134,7 +139,7 @@ export class NgForm extends ControlContainer implements Form {
134139
}
135140

136141
_later(fn) {
137-
var c = PromiseWrapper.completer();
142+
var c: PromiseCompleter<any> = PromiseWrapper.completer();
138143
PromiseWrapper.then(c.promise, fn, (_) => {});
139144
c.resolve(null);
140145
}

modules/angular2/src/render/xhr_impl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {Injectable} from 'angular2/di';
2-
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
2+
import {Promise, PromiseWrapper, PromiseCompleter} from 'angular2/src/facade/async';
33
import {XHR} from './xhr';
44

55
@Injectable()
66
export class XHRImpl extends XHR {
77
get(url: string): Promise<string> {
8-
var completer = PromiseWrapper.completer();
8+
var completer: PromiseCompleter < string >= PromiseWrapper.completer();
99
var xhr = new XMLHttpRequest();
1010
xhr.open('GET', url, true);
1111
xhr.responseType = 'text';

modules/angular2/src/render/xhr_mock.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {XHR} from 'angular2/src/render/xhr';
22
import {List, ListWrapper, Map, MapWrapper} from 'angular2/src/facade/collection';
33
import {isBlank, isPresent, normalizeBlank, BaseException} from 'angular2/src/facade/lang';
4-
import {PromiseWrapper, Promise} from 'angular2/src/facade/async';
4+
import {PromiseCompleter, PromiseWrapper, Promise} from 'angular2/src/facade/async';
55

66
export class MockXHR extends XHR {
77
private _expectations: List<_Expectation>;
@@ -77,7 +77,7 @@ export class MockXHR extends XHR {
7777

7878
class _PendingRequest {
7979
url: string;
80-
completer;
80+
completer: PromiseCompleter<string>;
8181

8282
constructor(url) {
8383
this.url = url;

modules/angular2/src/web-workers/worker/application_common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {ExceptionHandler} from 'angular2/src/core/exception_handler';
2626
import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';
2727
import {ViewResolver} from 'angular2/src/core/compiler/view_resolver';
2828
import {List, ListWrapper} from 'angular2/src/facade/collection';
29-
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
29+
import {Promise, PromiseWrapper, PromiseCompleter} from 'angular2/src/facade/async';
3030
import {NgZone} from 'angular2/src/core/zone/ng_zone';
3131
import {LifeCycle} from 'angular2/src/core/life_cycle/life_cycle';
3232
import {XHR} from 'angular2/src/render/xhr';
@@ -137,7 +137,7 @@ function _injectorBindings(appComponentType, bus: WorkerMessageBus,
137137
export function bootstrapWebworkerCommon(
138138
appComponentType: Type, bus: WorkerMessageBus,
139139
componentInjectableBindings: List<Type | Binding | List<any>> = null): Promise<ApplicationRef> {
140-
var bootstrapProcess = PromiseWrapper.completer();
140+
var bootstrapProcess: PromiseCompleter<any> = PromiseWrapper.completer();
141141

142142
var zone = createNgZone(new ExceptionHandler(new PrintLogger()));
143143
zone.run(() => {

modules/angular2/src/web-workers/worker/broker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class MessageBroker {
4141
var promise: Promise<any>;
4242
var id: string = null;
4343
if (returnType != null) {
44-
var completer = PromiseWrapper.completer();
44+
var completer: PromiseCompleter<any> = PromiseWrapper.completer();
4545
id = this._generateMessageId(args.type + args.method);
4646
this._pending.set(id, completer.resolve);
4747
PromiseWrapper.catchError(completer.promise, (err, stack?) => {

modules/angular2/test/core/compiler/compiler_spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616

1717
import {List, ListWrapper, Map, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
1818
import {IMPLEMENTS, Type, isBlank, stringify, isPresent, isArray} from 'angular2/src/facade/lang';
19-
import {PromiseWrapper, Promise} from 'angular2/src/facade/async';
19+
import {PromiseCompleter, PromiseWrapper, Promise} from 'angular2/src/facade/async';
2020

2121
import {Compiler, CompilerCache} from 'angular2/src/core/compiler/compiler';
2222
import {AppProtoView} from 'angular2/src/core/compiler/view';
@@ -442,7 +442,8 @@ export function main() {
442442

443443
it('should re-use components being compiled', inject([AsyncTestCompleter], (async) => {
444444
tplResolver.setView(MainComponent, new viewAnn.View({template: '<div></div>'}));
445-
var renderProtoViewCompleter = PromiseWrapper.completer();
445+
var renderProtoViewCompleter: PromiseCompleter<renderApi.ProtoViewDto> =
446+
PromiseWrapper.completer();
446447
var expectedProtoView = createProtoView();
447448
var compiler = createCompiler([renderProtoViewCompleter.promise],
448449
[rootProtoView, rootProtoView, expectedProtoView]);

modules/angular2/test/core/zone/ng_zone_spec.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
isInInnerZone
1414
} from 'angular2/test_lib';
1515

16-
import {PromiseWrapper, TimerWrapper} from 'angular2/src/facade/async';
16+
import {PromiseCompleter, PromiseWrapper, TimerWrapper} from 'angular2/src/facade/async';
1717
import {BaseException} from 'angular2/src/facade/lang';
1818
import {DOM} from 'angular2/src/dom/dom_adapter';
1919

@@ -65,7 +65,7 @@ export function main() {
6565
it('should produce long stack traces', inject([AsyncTestCompleter], (async) => {
6666
macroTask(() => {
6767
_zone.overrideOnErrorHandler(logError);
68-
var c = PromiseWrapper.completer();
68+
var c: PromiseCompleter<any> = PromiseWrapper.completer();
6969

7070
_zone.run(() => {
7171
TimerWrapper.setTimeout(() => {
@@ -88,7 +88,7 @@ export function main() {
8888
inject([AsyncTestCompleter], (async) => {
8989
macroTask(() => {
9090
_zone.overrideOnErrorHandler(logError);
91-
var c = PromiseWrapper.completer();
91+
var c: PromiseCompleter<any> = PromiseWrapper.completer();
9292

9393
_zone.run(() => {
9494
microTask(() => {
@@ -116,7 +116,7 @@ export function main() {
116116
it('should disable long stack traces', inject([AsyncTestCompleter], (async) => {
117117
macroTask(() => {
118118
_zone.overrideOnErrorHandler(logError);
119-
var c = PromiseWrapper.completer();
119+
var c: PromiseCompleter<any> = PromiseWrapper.completer();
120120

121121
_zone.run(() => {
122122
TimerWrapper.setTimeout(() => {
@@ -304,8 +304,8 @@ function commonTests() {
304304

305305
it('should call onTurnStart and onTurnDone before and after each turn',
306306
inject([AsyncTestCompleter], (async) => {
307-
var a;
308-
var b;
307+
var a: PromiseCompleter<string>;
308+
var b: PromiseCompleter<string>;
309309

310310
macroTask(() => {
311311
_zone.run(() => {
@@ -345,7 +345,7 @@ function commonTests() {
345345

346346
it('should call onTurnStart and onTurnDone when an inner microtask is scheduled from outside angular',
347347
inject([AsyncTestCompleter], (async) => {
348-
var completer;
348+
var completer: PromiseCompleter<any>;
349349

350350
macroTask(
351351
() => { _zone.runOutsideAngular(() => { completer = PromiseWrapper.completer(); }); });
@@ -495,7 +495,8 @@ function commonTests() {
495495

496496
it('should call onTurnStart and onTurnDone before and after each turn, respectively',
497497
inject([AsyncTestCompleter], (async) => {
498-
var completerA, completerB;
498+
var completerA: PromiseCompleter<any>;
499+
var completerB: PromiseCompleter<any>;
499500

500501
macroTask(() => {
501502
_zone.run(() => {

modules/angular2/test/router/outlet_spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ import {Injector, bind} from 'angular2/di';
1919
import {Component, View} from 'angular2/src/core/annotations/decorators';
2020
import * as annotations from 'angular2/src/core/annotations_impl/view';
2121
import {CONST, NumberWrapper, isPresent} from 'angular2/src/facade/lang';
22-
import {Promise, PromiseWrapper, EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
22+
import {
23+
Promise,
24+
PromiseWrapper,
25+
PromiseCompleter,
26+
EventEmitter,
27+
ObservableWrapper
28+
} from 'angular2/src/facade/async';
2329

2430
import {RootRouter} from 'angular2/src/router/router';
2531
import {Pipeline} from 'angular2/src/router/pipeline';
@@ -42,7 +48,8 @@ import {CanActivate} from 'angular2/src/router/lifecycle_annotations';
4248
import {Instruction} from 'angular2/src/router/instruction';
4349
import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';
4450

45-
var cmpInstanceCount, log, eventBus, completer;
51+
var cmpInstanceCount, log, eventBus;
52+
var completer: PromiseCompleter<any>;
4653

4754
export function main() {
4855
describe('Outlet Directive', () => {

0 commit comments

Comments
 (0)