From ce0dfff7ff87588a3437431a5e91ed0a3d692840 Mon Sep 17 00:00:00 2001 From: Kevin Nderitu Date: Mon, 19 Nov 2018 17:15:41 +0300 Subject: [PATCH] Added upload files support --- src/requests.ts | 3 ++- src/service.ts | 9 +++++---- tests/service.test.tsx | 4 ++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/requests.ts b/src/requests.ts index 4fa6356..6689e04 100644 --- a/src/requests.ts +++ b/src/requests.ts @@ -9,7 +9,8 @@ export const requests = { getTags: 'data.getTags', updateTag: 'data.updateTag', getAppData: 'data.getAppData', - updateAppData: 'data.updateAppData' + updateAppData: 'data.updateAppData', + uploadFile: 'data.uploadFile', }, toast: { show: 'toast.show', diff --git a/src/service.ts b/src/service.ts index 3f237bd..3879642 100644 --- a/src/service.ts +++ b/src/service.ts @@ -44,9 +44,7 @@ export class Service { private rpc(name: string, body: any) { const reqId = Math.random(); return new Promise((resolve, reject) => { - this.rpcTracker[reqId] = { - resolve, reject - }; + this.rpcTracker[reqId] = { resolve, reject }; const message = { name, body, @@ -66,7 +64,10 @@ export class Service { handler.rpcTracker[msg.id].resolve(msg.body); } else { handler.rpcTracker[msg.id].reject(msg.body); - } + } + // Remove the promise from the handler because + // it has already been taken care of. + // delete handler.rpcTracker[msg.id]; } /** * Emits a custom event diff --git a/tests/service.test.tsx b/tests/service.test.tsx index 2c32088..dcb4d48 100644 --- a/tests/service.test.tsx +++ b/tests/service.test.tsx @@ -1,6 +1,10 @@ import { Service, requests } from '..'; +// @ts-ignore import { request } from 'http'; +//@ts-ignore +import jest from 'jest'; +// @ts-ignore jest.spyOn(global.window.parent , 'postMessage'); describe('Requests', async () => {