From 9d0d900b05c44acf7e5360e2467a91f11969fd68 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Thu, 23 Apr 2020 04:29:24 -0700 Subject: [PATCH] Pass supportsMethod as an argument to the exportPersistedState Summary: This diff adds supportsMethod as a closure which can be used to verify a method is implemented on the client side. It will be used in the next diff Reviewed By: jknoxville Differential Revision: D21176415 fbshipit-source-id: fe16d966c58d36558034ce4ade8f58f8031aab18 --- desktop/app/src/plugin.tsx | 10 ++++++++++ desktop/app/src/utils/__tests__/pluginUtils.node.js | 1 + desktop/app/src/utils/exportData.tsx | 2 ++ 3 files changed, 13 insertions(+) diff --git a/desktop/app/src/plugin.tsx b/desktop/app/src/plugin.tsx index d3ede3b63..1cb12ea0a 100644 --- a/desktop/app/src/plugin.tsx +++ b/desktop/app/src/plugin.tsx @@ -31,6 +31,15 @@ export function callClient( return (method, params) => client.call(id, method, false, params); } +// This function is intended to be called from outside of the plugin. +// If you want to `supportsMethod` from the plugin use, this.client.supportsMethod +export function supportsMethod( + client: Client, + id: string, +): (method: string) => Promise { + return (method) => client.supportsMethod(id, method); +} + export interface PluginClient { // eslint-disable-next-line send(method: string, params?: Parameters): void; @@ -109,6 +118,7 @@ export abstract class FlipperBasePlugin< store: ReduxState | undefined, idler?: Idler, statusUpdate?: (msg: string) => void, + supportsMethod?: (method: string) => Promise, ) => Promise) | null; static getActiveNotifications: diff --git a/desktop/app/src/utils/__tests__/pluginUtils.node.js b/desktop/app/src/utils/__tests__/pluginUtils.node.js index 366448398..8b4eca5b7 100644 --- a/desktop/app/src/utils/__tests__/pluginUtils.node.js +++ b/desktop/app/src/utils/__tests__/pluginUtils.node.js @@ -40,6 +40,7 @@ function createMockFlipperPluginWithExportPersistedState(id: string) { callClient: (string, ?Object) => Promise, persistedState: ?{msg: string}, store: ?ReduxState, + supportsMethod?: (string) => Promise, ): Promise => { return Promise.resolve({ msg: 'MockFlipperPluginWithExportPersistedState', diff --git a/desktop/app/src/utils/exportData.tsx b/desktop/app/src/utils/exportData.tsx index 82955a002..7deeef387 100644 --- a/desktop/app/src/utils/exportData.tsx +++ b/desktop/app/src/utils/exportData.tsx @@ -22,6 +22,7 @@ import { FlipperDevicePlugin, FlipperPlugin, callClient, + supportsMethod, FlipperBasePlugin, } from '../plugin'; import {default as BaseDevice} from '../devices/BaseDevice'; @@ -472,6 +473,7 @@ export async function fetchMetadata( state, idler, statusUpdate, + supportsMethod(client, pluginId), ), `Timed out while collecting data for ${pluginName}`, );