Skip to content

Commit 6075509

Browse files
alexeaglevsavkin
authored andcommitted
chore(typing): extract abstract superclasses to replace @Private constructors
1 parent ee32b1b commit 6075509

65 files changed

Lines changed: 968 additions & 771 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/angular2/src/core/application_ref.ts

Lines changed: 66 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {NgZone} from 'angular2/src/core/zone/ng_zone';
1+
import {NgZone, NgZone_} from 'angular2/src/core/zone/ng_zone';
22
import {Type, isBlank, isPresent, assertionsEnabled} from 'angular2/src/core/facade/lang';
33
import {bind, Binding, Injector, OpaqueToken} from 'angular2/src/core/di';
44
import {
@@ -17,11 +17,12 @@ import {
1717
import {
1818
BaseException,
1919
WrappedException,
20-
ExceptionHandler
20+
ExceptionHandler,
21+
unimplemented
2122
} from 'angular2/src/core/facade/exceptions';
2223
import {DOM} from 'angular2/src/core/dom/dom_adapter';
2324
import {internalView} from 'angular2/src/core/linker/view_ref';
24-
import {LifeCycle} from 'angular2/src/core/life_cycle/life_cycle';
25+
import {LifeCycle, LifeCycle_} from 'angular2/src/core/life_cycle/life_cycle';
2526
import {
2627
IterableDiffers,
2728
defaultIterableDiffers,
@@ -98,7 +99,7 @@ export function applicationCommonBindings(): Array<Type | Binding | any[]> {
9899
DirectiveResolver,
99100
PipeResolver,
100101
DynamicComponentLoader,
101-
bind(LifeCycle).toFactory((exceptionHandler) => new LifeCycle(null, assertionsEnabled()),
102+
bind(LifeCycle).toFactory((exceptionHandler) => new LifeCycle_(null, assertionsEnabled()),
102103
[ExceptionHandler]),
103104
];
104105
}
@@ -107,7 +108,7 @@ export function applicationCommonBindings(): Array<Type | Binding | any[]> {
107108
* Create an Angular zone.
108109
*/
109110
export function createNgZone(): NgZone {
110-
return new NgZone({enableLongStackTrace: assertionsEnabled()});
111+
return new NgZone_({enableLongStackTrace: assertionsEnabled()});
111112
}
112113

113114
var _platform: PlatformRef;
@@ -131,7 +132,7 @@ export function platformCommon(bindings?: Array<Type | Binding | any[]>, initial
131132
if (isBlank(bindings)) {
132133
bindings = platformBindings();
133134
}
134-
_platform = new PlatformRef(Injector.resolveAndCreate(bindings), () => { _platform = null; });
135+
_platform = new PlatformRef_(Injector.resolveAndCreate(bindings), () => { _platform = null; });
135136
return _platform;
136137
}
137138

@@ -143,22 +144,12 @@ export function platformCommon(bindings?: Array<Type | Binding | any[]>, initial
143144
* A page's platform is initialized implicitly when {@link bootstrap}() is called, or
144145
* explicitly by calling {@link platform}().
145146
*/
146-
export class PlatformRef {
147-
/**
148-
* @internal
149-
*/
150-
_applications: ApplicationRef[] = [];
151-
152-
/**
153-
* @internal
154-
*/
155-
constructor(private _injector: Injector, private _dispose: () => void) {}
156-
147+
export abstract class PlatformRef {
157148
/**
158149
* Retrieve the platform {@link Injector}, which is the parent injector for
159150
* every Angular application on the page and provides singleton bindings.
160151
*/
161-
get injector(): Injector { return this._injector; }
152+
get injector(): Injector { return unimplemented(); };
162153

163154
/**
164155
* Instantiate a new Angular application on the page.
@@ -188,10 +179,7 @@ export class PlatformRef {
188179
*
189180
* See the {@link bootstrap} documentation for more details.
190181
*/
191-
application(bindings: Array<Type | Binding | any[]>): ApplicationRef {
192-
var app = this._initApp(createNgZone(), bindings);
193-
return app;
194-
}
182+
abstract application(bindings: Array<Type | Binding | any[]>): ApplicationRef;
195183

196184
/**
197185
* Instantiate a new Angular application on the page, using bindings which
@@ -205,6 +193,27 @@ export class PlatformRef {
205193
* new application. Once this promise resolves, the application will be
206194
* constructed in the same manner as a normal `application()`.
207195
*/
196+
abstract asyncApplication(bindingFn: (zone: NgZone) => Promise<Array<Type | Binding | any[]>>):
197+
Promise<ApplicationRef>;
198+
199+
/**
200+
* Destroy the Angular platform and all Angular applications on the page.
201+
*/
202+
abstract dispose(): void;
203+
}
204+
205+
export class PlatformRef_ extends PlatformRef {
206+
_applications: ApplicationRef[] = [];
207+
208+
constructor(private _injector: Injector, private _dispose: () => void) { super(); }
209+
210+
get injector(): Injector { return this._injector; }
211+
212+
application(bindings: Array<Type | Binding | any[]>): ApplicationRef {
213+
var app = this._initApp(createNgZone(), bindings);
214+
return app;
215+
}
216+
208217
asyncApplication(bindingFn: (zone: NgZone) =>
209218
Promise<Array<Type | Binding | any[]>>): Promise<ApplicationRef> {
210219
var zone = createNgZone();
@@ -227,7 +236,7 @@ export class PlatformRef {
227236
try {
228237
injector = this.injector.resolveAndCreateChild(bindings);
229238
exceptionHandler = injector.get(ExceptionHandler);
230-
zone.overrideOnErrorHandler((e, s) => exceptionHandler.call(e, s));
239+
(<NgZone_>zone).overrideOnErrorHandler((e, s) => exceptionHandler.call(e, s));
231240
} catch (e) {
232241
if (isPresent(exceptionHandler)) {
233242
exceptionHandler.call(e, e.stack);
@@ -236,23 +245,16 @@ export class PlatformRef {
236245
}
237246
}
238247
});
239-
var app = new ApplicationRef(this, zone, injector);
248+
var app = new ApplicationRef_(this, zone, injector);
240249
this._applications.push(app);
241250
return app;
242251
}
243252

244-
245-
/**
246-
* Destroy the Angular platform and all Angular applications on the page.
247-
*/
248253
dispose(): void {
249254
this._applications.forEach((app) => app.dispose());
250255
this._dispose();
251256
}
252257

253-
/**
254-
* @internal
255-
*/
256258
_applicationDisposed(app: ApplicationRef): void { ListWrapper.remove(this._applications, app); }
257259
}
258260

@@ -261,22 +263,12 @@ export class PlatformRef {
261263
*
262264
* For more about Angular applications, see the documentation for {@link bootstrap}.
263265
*/
264-
export class ApplicationRef {
265-
private _bootstrapListeners: Function[] = [];
266-
private _rootComponents: ComponentRef[] = [];
267-
268-
/**
269-
* @internal
270-
*/
271-
constructor(private _platform: PlatformRef, private _zone: NgZone, private _injector: Injector) {}
272-
266+
export abstract class ApplicationRef {
273267
/**
274268
* Register a listener to be called each time `bootstrap()` is called to bootstrap
275269
* a new root component.
276270
*/
277-
registerBootstrapListener(listener: (ref: ComponentRef) => void): void {
278-
this._bootstrapListeners.push(listener);
279-
}
271+
abstract registerBootstrapListener(listener: (ref: ComponentRef) => void): void;
280272

281273
/**
282274
* Bootstrap a new component at the root level of the application.
@@ -300,6 +292,37 @@ export class ApplicationRef {
300292
* app.bootstrap(SecondRootComponent, [bind(OverrideBinding).toClass(OverriddenBinding)]);
301293
* ```
302294
*/
295+
abstract bootstrap(componentType: Type, bindings?: Array<Type | Binding | any[]>):
296+
Promise<ComponentRef>;
297+
298+
/**
299+
* Retrieve the application {@link Injector}.
300+
*/
301+
get injector(): Injector { return unimplemented(); };
302+
303+
/**
304+
* Retrieve the application {@link NgZone}.
305+
*/
306+
get zone(): NgZone { return unimplemented(); };
307+
308+
/**
309+
* Dispose of this application and all of its components.
310+
*/
311+
abstract dispose(): void;
312+
}
313+
314+
export class ApplicationRef_ extends ApplicationRef {
315+
private _bootstrapListeners: Function[] = [];
316+
private _rootComponents: ComponentRef[] = [];
317+
318+
constructor(private _platform: PlatformRef_, private _zone: NgZone, private _injector: Injector) {
319+
super();
320+
}
321+
322+
registerBootstrapListener(listener: (ref: ComponentRef) => void): void {
323+
this._bootstrapListeners.push(listener);
324+
}
325+
303326
bootstrap(componentType: Type, bindings?: Array<Type | Binding | any[]>): Promise<ComponentRef> {
304327
var completer = PromiseWrapper.completer();
305328
this._zone.run(() => {
@@ -334,19 +357,10 @@ export class ApplicationRef {
334357
return completer.promise;
335358
}
336359

337-
/**
338-
* Retrieve the application {@link Injector}.
339-
*/
340360
get injector(): Injector { return this._injector; }
341361

342-
/**
343-
* Retrieve the application {@link NgZone}.
344-
*/
345362
get zone(): NgZone { return this._zone; }
346363

347-
/**
348-
* Dispose of this application and all of its components.
349-
*/
350364
dispose(): void {
351365
// TODO(alxhub): Dispose of the NgZone.
352366
this._rootComponents.forEach((ref) => ref.dispose());

modules/angular2/src/core/change_detection/abstract_change_detector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {isPresent, isBlank, StringWrapper} from 'angular2/src/core/facade/lang';
22
import {BaseException} from 'angular2/src/core/facade/exceptions';
33
import {ListWrapper} from 'angular2/src/core/facade/collection';
44
import {ChangeDetectionUtil} from './change_detection_util';
5-
import {ChangeDetectorRef} from './change_detector_ref';
5+
import {ChangeDetectorRef, ChangeDetectorRef_} from './change_detector_ref';
66
import {DirectiveIndex} from './directive_record';
77
import {ChangeDetector, ChangeDispatcher} from './interfaces';
88
import {Pipes} from './pipes';
@@ -47,7 +47,7 @@ export class AbstractChangeDetector<T> implements ChangeDetector {
4747
constructor(public id: string, public dispatcher: ChangeDispatcher,
4848
public numberOfPropertyProtoRecords: number, public bindingTargets: BindingTarget[],
4949
public directiveIndices: DirectiveIndex[], public strategy: ChangeDetectionStrategy) {
50-
this.ref = new ChangeDetectorRef(this);
50+
this.ref = new ChangeDetectorRef_(this);
5151
}
5252

5353
addChild(cd: ChangeDetector): void {

modules/angular2/src/core/change_detection/change_detector_ref.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
import {ChangeDetector} from './interfaces';
22
import {ChangeDetectionStrategy} from './constants';
33

4-
/**
5-
* Reference to a component's change detection object.
6-
*/
7-
export class ChangeDetectorRef {
8-
/**
9-
* @internal
10-
*/
11-
constructor(private _cd: ChangeDetector) {}
12-
4+
export abstract class ChangeDetectorRef {
135
/**
146
* Marks all {@link OnPush} ancestors as to be checked.
157
*
@@ -48,7 +40,7 @@ export class ChangeDetectorRef {
4840
* bootstrap(App);
4941
* ```
5042
*/
51-
markForCheck(): void { this._cd.markPathToRootAsCheckOnce(); }
43+
abstract markForCheck(): void;
5244

5345
/**
5446
* Detaches the change detector from the change detector tree.
@@ -107,7 +99,7 @@ export class ChangeDetectorRef {
10799
* bootstrap(App);
108100
* ```
109101
*/
110-
detach(): void { this._cd.mode = ChangeDetectionStrategy.Detached; }
102+
abstract detach(): void;
111103

112104
/**
113105
* Checks the change detector and its children.
@@ -130,7 +122,7 @@ export class ChangeDetectorRef {
130122
*
131123
* See {@link detach} for more information.
132124
*/
133-
detectChanges(): void { this._cd.detectChanges(); }
125+
abstract detectChanges(): void;
134126

135127
/**
136128
* Reattach the change detector to the change detector tree.
@@ -190,6 +182,15 @@ export class ChangeDetectorRef {
190182
* bootstrap(App);
191183
* ```
192184
*/
185+
abstract reattach(): void;
186+
}
187+
188+
export class ChangeDetectorRef_ extends ChangeDetectorRef {
189+
constructor(private _cd: ChangeDetector) { super(); }
190+
191+
markForCheck(): void { this._cd.markPathToRootAsCheckOnce(); }
192+
detach(): void { this._cd.mode = ChangeDetectionStrategy.Detached; }
193+
detectChanges(): void { this._cd.detectChanges(); }
193194
reattach(): void {
194195
this._cd.mode = ChangeDetectionStrategy.CheckAlways;
195196
this.markForCheck();

modules/angular2/src/core/compiler/runtime_compiler.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Compiler, internalCreateProtoView} from 'angular2/src/core/linker/compiler';
1+
import {Compiler, Compiler_, internalCreateProtoView} from 'angular2/src/core/linker/compiler';
22
import {ProtoViewRef} from 'angular2/src/core/linker/view_ref';
33
import {ProtoViewFactory} from 'angular2/src/core/linker/proto_view_factory';
44
import {TemplateCompiler} from './template_compiler';
@@ -7,11 +7,10 @@ import {Injectable} from 'angular2/src/core/di';
77
import {Type} from 'angular2/src/core/facade/lang';
88
import {Promise, PromiseWrapper} from 'angular2/src/core/facade/async';
99

10+
export abstract class RuntimeCompiler extends Compiler {}
11+
1012
@Injectable()
11-
export class RuntimeCompiler extends Compiler {
12-
/**
13-
* @internal
14-
*/
13+
export class RuntimeCompiler_ extends Compiler_ {
1514
constructor(_protoViewFactory: ProtoViewFactory, private _templateCompiler: TemplateCompiler) {
1615
super(_protoViewFactory);
1716
}

0 commit comments

Comments
 (0)