Skip to content
This repository has been archived by the owner on May 22, 2020. It is now read-only.

Commit

Permalink
RUN-3830 fixed .createFromManifest regression (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
whyn07m3 authored and HarsimranSingh committed Feb 16, 2018
1 parent 27c9bca commit 9d937f4
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/browser/remote_subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Identity } from '../shapes';
import route from '../common/route';
import * as coreState from './core_state';
import { PortInfo } from './port_discovery';
import { EventEmitter } from 'events';

// id count to generate IDs for subscriptions
let subscriptionIdCount = 0;
Expand Down Expand Up @@ -69,7 +70,7 @@ const systemEventsToIgnore: {[index: string]: boolean} = {
*/
export function addRemoteSubscription(subscriptionProps: RemoteSubscriptionProps|RemoteSubscription): Promise<() => void> {
return new Promise(resolve => {
const clonedProps = Object.create(subscriptionProps);
const clonedProps = JSON.parse(JSON.stringify(subscriptionProps));
const subscription: RemoteSubscription = Object.assign(clonedProps, {isCleaned: false});

// Only generate an ID for new subscriptions
Expand Down Expand Up @@ -109,8 +110,8 @@ export function addRemoteSubscription(subscriptionProps: RemoteSubscriptionProps
/**
* Subscribe to an event in a remote runtime
*/
function applyRemoteSubscription(subscription: RemoteSubscription, runtime: PeerRuntime) {
const classEventEmitter = getClassEventEmitter(subscription, runtime);
async function applyRemoteSubscription(subscription: RemoteSubscription, runtime: PeerRuntime) {
const classEventEmitter = await getClassEventEmitter(subscription, runtime);
const runtimeKey = keyFromPortInfo(runtime.portInfo);
const { uuid, name, className, eventName, listenType, unSubscriptions } = subscription;
const fullEventName = (typeof name === 'string')
Expand Down Expand Up @@ -232,7 +233,7 @@ export function subscribeToAllRuntimes(subscriptionProps: RemoteSubscriptionProp
resolve();
}

const clonedProps = Object.create(subscriptionProps);
const clonedProps = JSON.parse(JSON.stringify(subscriptionProps));
const subscription: RemoteSubscription = Object.assign(clonedProps, {isSystemEvent: true});

// Generate a subscription ID for pending subscriptions
Expand Down Expand Up @@ -308,16 +309,16 @@ function applySystemSubscription(subscription: RemoteSubscription, runtime: Peer
/**
* Get event emitter of the class
*/
function getClassEventEmitter(subscription: RemoteSubscription, runtime: PeerRuntime) {
async function getClassEventEmitter(subscription: RemoteSubscription, runtime: PeerRuntime): Promise<EventEmitter> {
let classEventEmitter;
const { uuid, name, className } = subscription;

switch (className) {
case 'application':
classEventEmitter = runtime.fin.Application.wrap({uuid});
classEventEmitter = await runtime.fin.Application.wrap({uuid});
break;
case 'window':
classEventEmitter = runtime.fin.Window.wrap({uuid, name});
classEventEmitter = await runtime.fin.Window.wrap({uuid, name});
break;
}

Expand Down

0 comments on commit 9d937f4

Please sign in to comment.