chore(typing): extract abstract superclasses to replace @private constructors

This commit is contained in:
Alex Eagle
2015-10-06 06:53:39 -07:00
committed by vsavkin
parent ee32b1bc37
commit 6075509f26
65 changed files with 994 additions and 797 deletions

View File

@ -14,30 +14,36 @@ import {Injectable} from "angular2/src/core/di";
import {Type, StringWrapper} from "angular2/src/core/facade/lang";
export {Type} from "angular2/src/core/facade/lang";
@Injectable()
export class ClientMessageBrokerFactory {
export abstract class ClientMessageBrokerFactory {
/**
* @internal
* Initializes the given channel and attaches a new {@link ClientMessageBroker} to it.
*/
constructor(private _messageBus: MessageBus, public _serializer: Serializer) {}
abstract createMessageBroker(channel: string, runInZone?: boolean): ClientMessageBroker;
}
@Injectable()
export class ClientMessageBrokerFactory_ extends ClientMessageBrokerFactory {
constructor(private _messageBus: MessageBus, public _serializer: Serializer) { super(); }
/**
* Initializes the given channel and attaches a new {@link ClientMessageBroker} to it.
*/
createMessageBroker(channel: string, runInZone: boolean = true): ClientMessageBroker {
this._messageBus.initChannel(channel, runInZone);
return new ClientMessageBroker(this._messageBus, this._serializer, channel);
return new ClientMessageBroker_(this._messageBus, this._serializer, channel);
}
}
export class ClientMessageBroker {
export abstract class ClientMessageBroker {
abstract runOnService(args: UiArguments, returnType: Type): Promise<any>;
}
export class ClientMessageBroker_ extends ClientMessageBroker {
private _pending: Map<string, PromiseCompleter<any>> = new Map<string, PromiseCompleter<any>>();
private _sink: EventEmitter;
/**
* @internal
*/
constructor(messageBus: MessageBus, public _serializer: Serializer, public channel) {
super();
this._sink = messageBus.to(channel);
var source = messageBus.from(channel);
ObservableWrapper.subscribe(source,

View File

@ -8,6 +8,7 @@ import {EventEmitter} from 'angular2/src/core/facade/async';
import {StringMapWrapper} from 'angular2/src/core/facade/collection';
import {Injectable} from "angular2/src/core/di";
import {NgZone} from 'angular2/src/core/zone/ng_zone';
import {NgZone_} from "../../core/zone/ng_zone";
/**
* A TypeScript implementation of {@link MessageBus} for communicating via JavaScript's
@ -41,7 +42,7 @@ export class PostMessageBusSink implements MessageBusSink {
attachToZone(zone: NgZone): void {
this._zone = zone;
this._zone.overrideOnEventDone(() => this._handleOnEventDone(), false);
(<NgZone_>this._zone).overrideOnEventDone(() => this._handleOnEventDone(), false);
}
initChannel(channel: string, runInZone: boolean = true): void {

View File

@ -10,36 +10,40 @@ import {
ObservableWrapper
} from 'angular2/src/core/facade/async';
@Injectable()
export class ServiceMessageBrokerFactory {
/**
* @internal
*/
constructor(private _messageBus: MessageBus, public _serializer: Serializer) {}
export abstract class ServiceMessageBrokerFactory {
/**
* Initializes the given channel and attaches a new {@link ServiceMessageBroker} to it.
*/
abstract createMessageBroker(channel: string, runInZone?: boolean): ServiceMessageBroker;
}
@Injectable()
export class ServiceMessageBrokerFactory_ extends ServiceMessageBrokerFactory {
constructor(private _messageBus: MessageBus, public _serializer: Serializer) { super(); }
createMessageBroker(channel: string, runInZone: boolean = true): ServiceMessageBroker {
this._messageBus.initChannel(channel, runInZone);
return new ServiceMessageBroker(this._messageBus, this._serializer, channel);
return new ServiceMessageBroker_(this._messageBus, this._serializer, channel);
}
}
export abstract class ServiceMessageBroker {
abstract registerMethod(methodName: string, signature: Type[], method: Function,
returnType?: Type): void;
}
/**
* Helper class for UIComponents that allows components to register methods.
* If a registered method message is received from the broker on the worker,
* the UIMessageBroker deserializes its arguments and calls the registered method.
* If that method returns a promise, the UIMessageBroker returns the result to the worker.
*/
export class ServiceMessageBroker {
export class ServiceMessageBroker_ extends ServiceMessageBroker {
private _sink: EventEmitter;
private _methods: Map<string, Function> = new Map<string, Function>();
/**
* @internal
*/
constructor(messageBus: MessageBus, private _serializer: Serializer, public channel) {
super();
this._sink = messageBus.to(channel);
var source = messageBus.from(channel);
ObservableWrapper.subscribe(source, (message) => this._handleMessage(message));