Skip to content

Commit

Permalink
fix(AppBridge): Packet should only inherit value when sending to parent
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Kimball authored and Brian Kimball committed Feb 16, 2018
1 parent fa1adf8 commit 95735cb
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/AppBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,6 @@ export class AppBridge {
* @param packet any - packet of data to send with the open event
*/
public openList(packet: Partial<IAppBridgeOpenListEvent>): Promise<boolean> {
let openListPacket = {};
Object.assign(openListPacket, { type: 'List', entityType: packet.type, keywords: packet.keywords, criteria: packet.criteria });
return new Promise<boolean>((resolve, reject) => {
if (this._handlers[AppBridgeHandler.OPEN_LIST]) {
this._handlers[AppBridgeHandler.OPEN_LIST](packet, (success: boolean) => {
Expand All @@ -267,6 +265,8 @@ export class AppBridge {
}
});
} else {
let openListPacket = {};
Object.assign(openListPacket, { type: 'List', entityType: packet.type, keywords: packet.keywords, criteria: packet.criteria });
postRobot.sendToParent(MESSAGE_TYPES.OPEN_LIST, packet).then((event) => {
this._trace(`${MESSAGE_TYPES.OPEN_LIST} (callback)`, event);
if (event.data) {
Expand All @@ -287,7 +287,6 @@ export class AppBridge {
* @param packet any - packet of data to send with the close event
*/
public update(packet: Partial<{ entityType: string, entityId: string, title: string, titleKey: string, color: string }>): Promise<boolean> {
Object.assign(packet, { id: this.id, windowName: this.windowName });
return new Promise<boolean>((resolve, reject) => {
if (this._handlers[AppBridgeHandler.UPDATE]) {
this._handlers[AppBridgeHandler.UPDATE](packet, (success: boolean) => {
Expand All @@ -298,6 +297,7 @@ export class AppBridge {
}
});
} else {
Object.assign(packet, { id: this.id, windowName: this.windowName });
postRobot.sendToParent(MESSAGE_TYPES.UPDATE, packet).then((event) => {
this._trace(`${MESSAGE_TYPES.UPDATE} (callback)`, event);
if (event.data) {
Expand All @@ -316,20 +316,20 @@ export class AppBridge {
* Fires or responds to an close event
*/
public close(packet?: object): Promise<boolean> {
if (packet) {
console.info('[AppBridge] - close(packet) is deprecated! Please just use close()!'); // tslint:disable-line
}
let realPacket = { id: this.id, windowName: this.windowName };
return new Promise<boolean>((resolve, reject) => {
if (this._handlers[AppBridgeHandler.CLOSE]) {
this._handlers[AppBridgeHandler.CLOSE](realPacket, (success: boolean) => {
this._handlers[AppBridgeHandler.CLOSE](packet, (success: boolean) => {
if (success) {
resolve(true);
} else {
reject(false);
}
});
} else {
if (packet) {
console.info('[AppBridge] - close(packet) is deprecated! Please just use close()!'); // tslint:disable-line
}
let realPacket = { id: this.id, windowName: this.windowName };
postRobot.sendToParent(MESSAGE_TYPES.CLOSE, realPacket).then((event) => {
this._trace(`${MESSAGE_TYPES.CLOSE} (callback)`, event);
if (event.data) {
Expand All @@ -348,20 +348,20 @@ export class AppBridge {
* Fires or responds to an close event
*/
public refresh(packet?: object): Promise<boolean> {
if (packet) {
console.info('[AppBridge] - refresh(packet) is deprecated! Please just use refresh()!'); // tslint:disable-line
}
let realPacket = { id: this.id, windowName: this.windowName };
return new Promise<boolean>((resolve, reject) => {
if (this._handlers[AppBridgeHandler.REFRESH]) {
this._handlers[AppBridgeHandler.REFRESH](realPacket, (success: boolean) => {
this._handlers[AppBridgeHandler.REFRESH](packet, (success: boolean) => {
if (success) {
resolve(true);
} else {
reject(false);
}
});
} else {
if (packet) {
console.info('[AppBridge] - refresh(packet) is deprecated! Please just use refresh()!'); // tslint:disable-line
}
let realPacket = { id: this.id, windowName: this.windowName };
postRobot.sendToParent(MESSAGE_TYPES.REFRESH, realPacket).then((event) => {
this._trace(`${MESSAGE_TYPES.REFRESH} (callback)`, event);
if (event.data) {
Expand All @@ -380,20 +380,20 @@ export class AppBridge {
* Fires or responds to a pin event
*/
public pin(packet?: object): Promise<boolean> {
if (packet) {
console.info('[AppBridge] - pin(packet) is deprecated! Please just use pin()!'); // tslint:disable-line
}
let realPacket = { id: this.id, windowName: this.windowName };
return new Promise<boolean>((resolve, reject) => {
if (this._handlers[AppBridgeHandler.PIN]) {
this._handlers[AppBridgeHandler.PIN](realPacket, (success: boolean) => {
this._handlers[AppBridgeHandler.PIN](packet, (success: boolean) => {
if (success) {
resolve(true);
} else {
reject(false);
}
});
} else {
if (packet) {
console.info('[AppBridge] - pin(packet) is deprecated! Please just use pin()!'); // tslint:disable-line
}
let realPacket = { id: this.id, windowName: this.windowName };
postRobot.sendToParent(MESSAGE_TYPES.PIN, realPacket).then((event) => {
this._trace(`${MESSAGE_TYPES.PIN} (callback)`, event);
if (event.data) {
Expand Down

0 comments on commit 95735cb

Please sign in to comment.