refactor: misc cleanup (#11654)
This commit is contained in:

committed by
Alex Eagle

parent
51d73d3e4e
commit
671f73448c
@ -156,15 +156,11 @@ class MessageData {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value from the StringMap if present. Otherwise returns null
|
||||
* Returns the value if present, otherwise returns null
|
||||
* @internal
|
||||
*/
|
||||
_getValueIfPresent(data: {[key: string]: any}, key: string) {
|
||||
if (StringMapWrapper.contains(data, key)) {
|
||||
return StringMapWrapper.get(data, key);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return data.hasOwnProperty(key) ? data[key] : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
import {Injectable, NgZone} from '@angular/core';
|
||||
|
||||
import {EventEmitter} from '../../facade/async';
|
||||
import {StringMapWrapper} from '../../facade/collection';
|
||||
|
||||
import {MessageBus, MessageBusSink, MessageBusSource} from './message_bus';
|
||||
|
||||
@ -22,7 +21,7 @@ export interface PostMessageTarget {
|
||||
|
||||
export class PostMessageBusSink implements MessageBusSink {
|
||||
private _zone: NgZone;
|
||||
private _channels: {[key: string]: _Channel} = StringMapWrapper.create();
|
||||
private _channels: {[key: string]: _Channel} = {};
|
||||
private _messageBuffer: Array<Object> = [];
|
||||
|
||||
constructor(private _postMessageTarget: PostMessageTarget) {}
|
||||
@ -34,7 +33,7 @@ export class PostMessageBusSink implements MessageBusSink {
|
||||
}
|
||||
|
||||
initChannel(channel: string, runInZone: boolean = true): void {
|
||||
if (StringMapWrapper.contains(this._channels, channel)) {
|
||||
if (this._channels.hasOwnProperty(channel)) {
|
||||
throw new Error(`${channel} has already been initialized`);
|
||||
}
|
||||
|
||||
@ -52,7 +51,7 @@ export class PostMessageBusSink implements MessageBusSink {
|
||||
}
|
||||
|
||||
to(channel: string): EventEmitter<any> {
|
||||
if (StringMapWrapper.contains(this._channels, channel)) {
|
||||
if (this._channels.hasOwnProperty(channel)) {
|
||||
return this._channels[channel].emitter;
|
||||
} else {
|
||||
throw new Error(`${channel} is not set up. Did you forget to call initChannel?`);
|
||||
@ -71,7 +70,7 @@ export class PostMessageBusSink implements MessageBusSink {
|
||||
|
||||
export class PostMessageBusSource implements MessageBusSource {
|
||||
private _zone: NgZone;
|
||||
private _channels: {[key: string]: _Channel} = StringMapWrapper.create();
|
||||
private _channels: {[key: string]: _Channel} = {};
|
||||
|
||||
constructor(eventTarget?: EventTarget) {
|
||||
if (eventTarget) {
|
||||
@ -86,7 +85,7 @@ export class PostMessageBusSource implements MessageBusSource {
|
||||
attachToZone(zone: NgZone) { this._zone = zone; }
|
||||
|
||||
initChannel(channel: string, runInZone: boolean = true) {
|
||||
if (StringMapWrapper.contains(this._channels, channel)) {
|
||||
if (this._channels.hasOwnProperty(channel)) {
|
||||
throw new Error(`${channel} has already been initialized`);
|
||||
}
|
||||
|
||||
@ -96,7 +95,7 @@ export class PostMessageBusSource implements MessageBusSource {
|
||||
}
|
||||
|
||||
from(channel: string): EventEmitter<any> {
|
||||
if (StringMapWrapper.contains(this._channels, channel)) {
|
||||
if (this._channels.hasOwnProperty(channel)) {
|
||||
return this._channels[channel].emitter;
|
||||
} else {
|
||||
throw new Error(`${channel} is not set up. Did you forget to call initChannel?`);
|
||||
@ -112,7 +111,7 @@ export class PostMessageBusSource implements MessageBusSource {
|
||||
|
||||
private _handleMessage(data: any): void {
|
||||
var channel = data.channel;
|
||||
if (StringMapWrapper.contains(this._channels, channel)) {
|
||||
if (this._channels.hasOwnProperty(channel)) {
|
||||
var channelInfo = this._channels[channel];
|
||||
if (channelInfo.runInZone) {
|
||||
this._zone.run(() => { channelInfo.emitter.emit(data.message); });
|
||||
|
@ -9,7 +9,6 @@
|
||||
import {Injectable, Type} from '@angular/core';
|
||||
|
||||
import {EventEmitter} from '../../facade/async';
|
||||
import {ListWrapper, Map} from '../../facade/collection';
|
||||
import {FunctionWrapper, isPresent} from '../../facade/lang';
|
||||
import {MessageBus} from '../shared/message_bus';
|
||||
import {Serializer} from '../shared/serializer';
|
||||
@ -72,7 +71,7 @@ export class ServiceMessageBroker_ extends ServiceMessageBroker {
|
||||
this._methods.set(methodName, (message: ReceivedMessage) => {
|
||||
var serializedArgs = message.args;
|
||||
let numArgs = signature === null ? 0 : signature.length;
|
||||
var deserializedArgs: any[] = ListWrapper.createFixedSize(numArgs);
|
||||
var deserializedArgs: any[] = new Array(numArgs);
|
||||
for (var i = 0; i < numArgs; i++) {
|
||||
var serializedArg = serializedArgs[i];
|
||||
deserializedArgs[i] = this._serializer.deserialize(serializedArg, signature[i]);
|
||||
|
@ -6,9 +6,6 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Set} from '../../facade/collection';
|
||||
import {isPresent} from '../../facade/lang';
|
||||
|
||||
const MOUSE_EVENT_PROPERTIES = [
|
||||
'altKey', 'button', 'clientX', 'clientY', 'metaKey', 'movementX', 'movementY', 'offsetX',
|
||||
'offsetY', 'region', 'screenX', 'screenY', 'shiftKey'
|
||||
@ -56,7 +53,7 @@ function addTarget(e: Event, serializedEvent: {[key: string]: any}): {[key: stri
|
||||
if (NODES_WITH_VALUE.has((<HTMLElement>e.target).tagName.toLowerCase())) {
|
||||
var target = <HTMLInputElement>e.target;
|
||||
serializedEvent['target'] = {'value': target.value};
|
||||
if (isPresent(target.files)) {
|
||||
if (target.files) {
|
||||
serializedEvent['target']['files'] = target.files;
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import {LocationChangeListener, PlatformLocation} from '@angular/common';
|
||||
import {Injectable} from '@angular/core';
|
||||
|
||||
import {EventEmitter} from '../../facade/async';
|
||||
import {StringMapWrapper} from '../../facade/collection';
|
||||
import {StringWrapper} from '../../facade/lang';
|
||||
import {ClientMessageBroker, ClientMessageBrokerFactory, FnArg, UiArguments} from '../shared/client_message_broker';
|
||||
import {MessageBus} from '../shared/message_bus';
|
||||
@ -37,7 +36,7 @@ export class WebWorkerPlatformLocation extends PlatformLocation {
|
||||
this._channelSource.subscribe({
|
||||
next: (msg: {[key: string]: any}) => {
|
||||
var listeners: Array<Function> = null;
|
||||
if (StringMapWrapper.contains(msg, 'event')) {
|
||||
if (msg.hasOwnProperty('event')) {
|
||||
let type: string = msg['event']['type'];
|
||||
if (StringWrapper.equals(type, 'popstate')) {
|
||||
listeners = this._popStateListeners;
|
||||
|
@ -16,8 +16,6 @@ import {SpyMessageBroker} from '../worker/spies';
|
||||
|
||||
import {MockEventEmitter} from './mock_event_emitter';
|
||||
|
||||
var __unused: Promise<any>; // avoid unused import when Promise union types are erased
|
||||
|
||||
/**
|
||||
* Returns two MessageBus instances that are attached to each other.
|
||||
* Such that whatever goes into one's sink comes out the others source.
|
||||
@ -49,9 +47,9 @@ export function expectBrokerCall(
|
||||
expect(args.method).toEqual(methodName);
|
||||
if (isPresent(vals)) {
|
||||
expect(args.args.length).toEqual(vals.length);
|
||||
ListWrapper.forEachWithIndex(vals, (v, i) => { expect(v).toEqual(args.args[i].value); });
|
||||
vals.forEach((v, i) => { expect(v).toEqual(args.args[i].value); });
|
||||
}
|
||||
var promise: any /** TODO #9100 */ = null;
|
||||
var promise: Promise<any>|void = null;
|
||||
if (isPresent(handler)) {
|
||||
let givenValues = args.args.map((arg) => arg.value);
|
||||
if (givenValues.length > 0) {
|
||||
@ -81,13 +79,13 @@ export class MockMessageBusSource implements MessageBusSource {
|
||||
constructor(private _channels: {[key: string]: MockEventEmitter<any>}) {}
|
||||
|
||||
initChannel(channel: string, runInZone = true) {
|
||||
if (!StringMapWrapper.contains(this._channels, channel)) {
|
||||
if (!this._channels.hasOwnProperty(channel)) {
|
||||
this._channels[channel] = new MockEventEmitter();
|
||||
}
|
||||
}
|
||||
|
||||
from(channel: string): MockEventEmitter<any> {
|
||||
if (!StringMapWrapper.contains(this._channels, channel)) {
|
||||
if (!this._channels.hasOwnProperty(channel)) {
|
||||
throw new Error(`${channel} is not set up. Did you forget to call initChannel?`);
|
||||
}
|
||||
return this._channels[channel];
|
||||
@ -100,13 +98,13 @@ export class MockMessageBusSink implements MessageBusSink {
|
||||
constructor(private _channels: {[key: string]: MockEventEmitter<any>}) {}
|
||||
|
||||
initChannel(channel: string, runInZone = true) {
|
||||
if (!StringMapWrapper.contains(this._channels, channel)) {
|
||||
if (!this._channels.hasOwnProperty(channel)) {
|
||||
this._channels[channel] = new MockEventEmitter();
|
||||
}
|
||||
}
|
||||
|
||||
to(channel: string): MockEventEmitter<any> {
|
||||
if (!StringMapWrapper.contains(this._channels, channel)) {
|
||||
if (!this._channels.hasOwnProperty(channel)) {
|
||||
this._channels[channel] = new MockEventEmitter();
|
||||
}
|
||||
return this._channels[channel];
|
||||
|
Reference in New Issue
Block a user