chore(facade): remove most facade/async functions
This commit is contained in:

committed by
Alex Rickabaugh

parent
6baf3baedd
commit
99989f5d3f
@ -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 = {
|
||||
|
@ -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';
|
||||
|
||||
|
||||
|
@ -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<any>;
|
||||
}
|
||||
|
||||
interface PromiseCompleter {
|
||||
resolve: (result: any) => void;
|
||||
reject: (err: any) => void;
|
||||
}
|
||||
|
||||
export class ClientMessageBroker_ extends ClientMessageBroker {
|
||||
private _pending: Map<string, PromiseCompleter<any>> = new Map<string, PromiseCompleter<any>>();
|
||||
private _pending: Map<string, PromiseCompleter> = new Map<string, PromiseCompleter>();
|
||||
private _sink: EventEmitter<any>;
|
||||
/** @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<any>;
|
||||
var id: string = null;
|
||||
if (returnType != null) {
|
||||
var completer: PromiseCompleter<any> = 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);
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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<any>, 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});
|
||||
});
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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<Location> {
|
||||
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; }
|
||||
|
@ -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<Function> = 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<Function> = 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<LocationType> = 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); });
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user