refactor: remove some facades (#12335)
This commit is contained in:

committed by
Alex Rickabaugh

parent
0ecd9b2df0
commit
76dd026447
@ -8,7 +8,7 @@
|
||||
|
||||
import {Injectable, RenderComponentType, Type, ViewEncapsulation} from '@angular/core';
|
||||
|
||||
import {isArray, isPresent} from '../../facade/lang';
|
||||
import {isPresent} from '../../facade/lang';
|
||||
|
||||
import {RenderStore} from './render_store';
|
||||
import {LocationType} from './serialized_types';
|
||||
@ -30,7 +30,7 @@ export class Serializer {
|
||||
if (!isPresent(obj)) {
|
||||
return null;
|
||||
}
|
||||
if (isArray(obj)) {
|
||||
if (Array.isArray(obj)) {
|
||||
return (<any[]>obj).map(v => this.serialize(v, type));
|
||||
}
|
||||
if (type == PRIMITIVE) {
|
||||
@ -38,15 +38,17 @@ export class Serializer {
|
||||
}
|
||||
if (type == RenderStoreObject) {
|
||||
return this._renderStore.serialize(obj);
|
||||
} else if (type === RenderComponentType) {
|
||||
return this._serializeRenderComponentType(obj);
|
||||
} else if (type === ViewEncapsulation) {
|
||||
return obj;
|
||||
} else if (type === LocationType) {
|
||||
return this._serializeLocation(obj);
|
||||
} else {
|
||||
throw new Error('No serializer for ' + type.toString());
|
||||
}
|
||||
if (type === RenderComponentType) {
|
||||
return this._serializeRenderComponentType(obj);
|
||||
}
|
||||
if (type === ViewEncapsulation) {
|
||||
return obj;
|
||||
}
|
||||
if (type === LocationType) {
|
||||
return this._serializeLocation(obj);
|
||||
}
|
||||
throw new Error('No serializer for ' + type.toString());
|
||||
}
|
||||
|
||||
deserialize(map: any, type: any, data?: any): any {
|
||||
|
@ -9,7 +9,7 @@
|
||||
import {Injectable, Type} from '@angular/core';
|
||||
|
||||
import {EventEmitter} from '../../facade/async';
|
||||
import {FunctionWrapper, isPresent} from '../../facade/lang';
|
||||
import {isPresent} from '../../facade/lang';
|
||||
import {MessageBus} from '../shared/message_bus';
|
||||
import {Serializer} from '../shared/serializer';
|
||||
|
||||
@ -69,16 +69,16 @@ export class ServiceMessageBroker_ extends ServiceMessageBroker {
|
||||
methodName: string, signature: Type<any>[], method: (..._: any[]) => Promise<any>| void,
|
||||
returnType?: Type<any>): void {
|
||||
this._methods.set(methodName, (message: ReceivedMessage) => {
|
||||
var serializedArgs = message.args;
|
||||
const serializedArgs = message.args;
|
||||
let numArgs = signature === null ? 0 : signature.length;
|
||||
var deserializedArgs: any[] = new Array(numArgs);
|
||||
for (var i = 0; i < numArgs; i++) {
|
||||
var serializedArg = serializedArgs[i];
|
||||
const deserializedArgs: any[] = new Array(numArgs);
|
||||
for (let i = 0; i < numArgs; i++) {
|
||||
const serializedArg = serializedArgs[i];
|
||||
deserializedArgs[i] = this._serializer.deserialize(serializedArg, signature[i]);
|
||||
}
|
||||
|
||||
var promise = FunctionWrapper.apply(method, deserializedArgs);
|
||||
if (isPresent(returnType) && isPresent(promise)) {
|
||||
const promise = method(...deserializedArgs);
|
||||
if (isPresent(returnType) && promise) {
|
||||
this._wrapWebWorkerPromise(message.id, promise, returnType);
|
||||
}
|
||||
});
|
||||
|
@ -10,7 +10,6 @@ import {LocationChangeListener} from '@angular/common';
|
||||
import {Injectable} from '@angular/core';
|
||||
|
||||
import {EventEmitter} from '../../facade/async';
|
||||
import {FunctionWrapper} from '../../facade/lang';
|
||||
import {BrowserPlatformLocation} from '../../private_import_platform-browser';
|
||||
import {MessageBus} from '../shared/message_bus';
|
||||
import {ROUTER_CHANNEL} from '../shared/messaging_api';
|
||||
@ -27,30 +26,26 @@ export class MessageBasedPlatformLocation {
|
||||
private _brokerFactory: ServiceMessageBrokerFactory,
|
||||
private _platformLocation: BrowserPlatformLocation, bus: MessageBus,
|
||||
private _serializer: Serializer) {
|
||||
this._platformLocation.onPopState(
|
||||
<LocationChangeListener>FunctionWrapper.bind(this._sendUrlChangeEvent, this));
|
||||
this._platformLocation.onPopState(<LocationChangeListener>this._sendUrlChangeEvent.bind(this));
|
||||
this._platformLocation.onHashChange(
|
||||
<LocationChangeListener>FunctionWrapper.bind(this._sendUrlChangeEvent, this));
|
||||
<LocationChangeListener>this._sendUrlChangeEvent.bind(this));
|
||||
this._broker = this._brokerFactory.createMessageBroker(ROUTER_CHANNEL);
|
||||
this._channelSink = bus.to(ROUTER_CHANNEL);
|
||||
}
|
||||
|
||||
start(): void {
|
||||
this._broker.registerMethod(
|
||||
'getLocation', null, FunctionWrapper.bind(this._getLocation, this), LocationType);
|
||||
this._broker.registerMethod(
|
||||
'setPathname', [PRIMITIVE], FunctionWrapper.bind(this._setPathname, this));
|
||||
this._broker.registerMethod('getLocation', null, this._getLocation.bind(this), LocationType);
|
||||
this._broker.registerMethod('setPathname', [PRIMITIVE], this._setPathname.bind(this));
|
||||
this._broker.registerMethod(
|
||||
'pushState', [PRIMITIVE, PRIMITIVE, PRIMITIVE],
|
||||
FunctionWrapper.bind(this._platformLocation.pushState, this._platformLocation));
|
||||
this._platformLocation.pushState.bind(this._platformLocation));
|
||||
this._broker.registerMethod(
|
||||
'replaceState', [PRIMITIVE, PRIMITIVE, PRIMITIVE],
|
||||
FunctionWrapper.bind(this._platformLocation.replaceState, this._platformLocation));
|
||||
this._platformLocation.replaceState.bind(this._platformLocation));
|
||||
this._broker.registerMethod(
|
||||
'forward', null,
|
||||
FunctionWrapper.bind(this._platformLocation.forward, this._platformLocation));
|
||||
'forward', null, this._platformLocation.forward.bind(this._platformLocation));
|
||||
this._broker.registerMethod(
|
||||
'back', null, FunctionWrapper.bind(this._platformLocation.back, this._platformLocation));
|
||||
'back', null, this._platformLocation.back.bind(this._platformLocation));
|
||||
}
|
||||
|
||||
private _getLocation(): Promise<Location> {
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
import {Injectable, RenderComponentType, Renderer, RootRenderer} from '@angular/core';
|
||||
|
||||
import {FunctionWrapper} from '../../facade/lang';
|
||||
import {MessageBus} from '../shared/message_bus';
|
||||
import {EVENT_CHANNEL, RENDERER_CHANNEL} from '../shared/messaging_api';
|
||||
import {RenderStore} from '../shared/render_store';
|
||||
@ -31,70 +30,66 @@ export class MessageBasedRenderer {
|
||||
this._eventDispatcher = new EventDispatcher(this._bus.to(EVENT_CHANNEL), this._serializer);
|
||||
|
||||
broker.registerMethod(
|
||||
'renderComponent', [RenderComponentType, PRIMITIVE],
|
||||
FunctionWrapper.bind(this._renderComponent, this));
|
||||
'renderComponent', [RenderComponentType, PRIMITIVE], this._renderComponent.bind(this));
|
||||
|
||||
broker.registerMethod(
|
||||
'selectRootElement', [RenderStoreObject, PRIMITIVE, PRIMITIVE],
|
||||
FunctionWrapper.bind(this._selectRootElement, this));
|
||||
this._selectRootElement.bind(this));
|
||||
broker.registerMethod(
|
||||
'createElement', [RenderStoreObject, RenderStoreObject, PRIMITIVE, PRIMITIVE],
|
||||
FunctionWrapper.bind(this._createElement, this));
|
||||
this._createElement.bind(this));
|
||||
broker.registerMethod(
|
||||
'createViewRoot', [RenderStoreObject, RenderStoreObject, PRIMITIVE],
|
||||
FunctionWrapper.bind(this._createViewRoot, this));
|
||||
this._createViewRoot.bind(this));
|
||||
broker.registerMethod(
|
||||
'createTemplateAnchor', [RenderStoreObject, RenderStoreObject, PRIMITIVE],
|
||||
FunctionWrapper.bind(this._createTemplateAnchor, this));
|
||||
this._createTemplateAnchor.bind(this));
|
||||
broker.registerMethod(
|
||||
'createText', [RenderStoreObject, RenderStoreObject, PRIMITIVE, PRIMITIVE],
|
||||
FunctionWrapper.bind(this._createText, this));
|
||||
this._createText.bind(this));
|
||||
broker.registerMethod(
|
||||
'projectNodes', [RenderStoreObject, RenderStoreObject, RenderStoreObject],
|
||||
FunctionWrapper.bind(this._projectNodes, this));
|
||||
this._projectNodes.bind(this));
|
||||
broker.registerMethod(
|
||||
'attachViewAfter', [RenderStoreObject, RenderStoreObject, RenderStoreObject],
|
||||
FunctionWrapper.bind(this._attachViewAfter, this));
|
||||
this._attachViewAfter.bind(this));
|
||||
broker.registerMethod(
|
||||
'detachView', [RenderStoreObject, RenderStoreObject],
|
||||
FunctionWrapper.bind(this._detachView, this));
|
||||
'detachView', [RenderStoreObject, RenderStoreObject], this._detachView.bind(this));
|
||||
broker.registerMethod(
|
||||
'destroyView', [RenderStoreObject, RenderStoreObject, RenderStoreObject],
|
||||
FunctionWrapper.bind(this._destroyView, this));
|
||||
this._destroyView.bind(this));
|
||||
broker.registerMethod(
|
||||
'setElementProperty', [RenderStoreObject, RenderStoreObject, PRIMITIVE, PRIMITIVE],
|
||||
FunctionWrapper.bind(this._setElementProperty, this));
|
||||
this._setElementProperty.bind(this));
|
||||
broker.registerMethod(
|
||||
'setElementAttribute', [RenderStoreObject, RenderStoreObject, PRIMITIVE, PRIMITIVE],
|
||||
FunctionWrapper.bind(this._setElementAttribute, this));
|
||||
this._setElementAttribute.bind(this));
|
||||
broker.registerMethod(
|
||||
'setBindingDebugInfo', [RenderStoreObject, RenderStoreObject, PRIMITIVE, PRIMITIVE],
|
||||
FunctionWrapper.bind(this._setBindingDebugInfo, this));
|
||||
this._setBindingDebugInfo.bind(this));
|
||||
broker.registerMethod(
|
||||
'setElementClass', [RenderStoreObject, RenderStoreObject, PRIMITIVE, PRIMITIVE],
|
||||
FunctionWrapper.bind(this._setElementClass, this));
|
||||
this._setElementClass.bind(this));
|
||||
broker.registerMethod(
|
||||
'setElementStyle', [RenderStoreObject, RenderStoreObject, PRIMITIVE, PRIMITIVE],
|
||||
FunctionWrapper.bind(this._setElementStyle, this));
|
||||
this._setElementStyle.bind(this));
|
||||
broker.registerMethod(
|
||||
'invokeElementMethod', [RenderStoreObject, RenderStoreObject, PRIMITIVE, PRIMITIVE],
|
||||
FunctionWrapper.bind(this._invokeElementMethod, this));
|
||||
this._invokeElementMethod.bind(this));
|
||||
broker.registerMethod(
|
||||
'setText', [RenderStoreObject, RenderStoreObject, PRIMITIVE],
|
||||
FunctionWrapper.bind(this._setText, this));
|
||||
'setText', [RenderStoreObject, RenderStoreObject, PRIMITIVE], this._setText.bind(this));
|
||||
broker.registerMethod(
|
||||
'listen', [RenderStoreObject, RenderStoreObject, PRIMITIVE, PRIMITIVE],
|
||||
FunctionWrapper.bind(this._listen, this));
|
||||
this._listen.bind(this));
|
||||
broker.registerMethod(
|
||||
'listenGlobal', [RenderStoreObject, PRIMITIVE, PRIMITIVE, PRIMITIVE],
|
||||
FunctionWrapper.bind(this._listenGlobal, this));
|
||||
this._listenGlobal.bind(this));
|
||||
broker.registerMethod(
|
||||
'listenDone', [RenderStoreObject, RenderStoreObject],
|
||||
FunctionWrapper.bind(this._listenDone, this));
|
||||
'listenDone', [RenderStoreObject, RenderStoreObject], this._listenDone.bind(this));
|
||||
}
|
||||
|
||||
private _renderComponent(renderComponentType: RenderComponentType, rendererId: number) {
|
||||
var renderer = this._rootRenderer.renderComponent(renderComponentType);
|
||||
const renderer = this._rootRenderer.renderComponent(renderComponentType);
|
||||
this._renderStore.store(renderer, rendererId);
|
||||
}
|
||||
|
||||
@ -107,7 +102,7 @@ export class MessageBasedRenderer {
|
||||
}
|
||||
|
||||
private _createViewRoot(renderer: Renderer, hostElement: any, elId: number) {
|
||||
var viewRoot = renderer.createViewRoot(hostElement);
|
||||
const viewRoot = renderer.createViewRoot(hostElement);
|
||||
if (this._renderStore.serialize(hostElement) !== elId) {
|
||||
this._renderStore.store(viewRoot, elId);
|
||||
}
|
||||
@ -135,7 +130,7 @@ export class MessageBasedRenderer {
|
||||
|
||||
private _destroyView(renderer: Renderer, hostElement: any, viewAllNodes: any[]) {
|
||||
renderer.destroyView(hostElement, viewAllNodes);
|
||||
for (var i = 0; i < viewAllNodes.length; i++) {
|
||||
for (let i = 0; i < viewAllNodes.length; i++) {
|
||||
this._renderStore.remove(viewAllNodes[i]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user