diff --git a/src/plugin.tsx b/src/plugin.tsx index 3fa9c0e37..fc512223b 100644 --- a/src/plugin.tsx +++ b/src/plugin.tsx @@ -14,22 +14,24 @@ import {MetricType} from './utils/exportMetrics'; import {ReactNode, Component} from 'react'; import BaseDevice from './devices/BaseDevice'; +type Parameters = any; + // This function is intended to be called from outside of the plugin. // If you want to `call` from the plugin use, this.client.call export function callClient( client: Client, id: string, -): (string, params: Object | null) => Promise { +): (method: string, params: Parameters) => Promise { return (method, params) => client.call(id, method, false, params); } export interface PluginClient { // eslint-disable-next-line - send(method: string, params?: Object): void; + send(method: string, params?: Parameters): void; // eslint-disable-next-line - call(method: string, params?: Object): Promise; + call(method: string, params?: Parameters): Promise; // eslint-disable-next-line - subscribe(method: string, callback: (params: any) => void): void; + subscribe(method: string, callback: (params: Parameters) => void): void; // eslint-disable-next-line supportsMethod(method: string): Promise; } @@ -61,6 +63,8 @@ export type BaseAction = { type: string; }; +type StaticPersistedState = any; + export abstract class FlipperBasePlugin< State, Actions extends BaseAction, @@ -82,26 +86,32 @@ export abstract class FlipperBasePlugin< static screenshot: string | null; static defaultPersistedState: any; static persistedStateReducer: - | ((persistedState: U, method: string, data: Object) => Partial) + | (( + persistedState: StaticPersistedState, + method: string, + data: any, + ) => StaticPersistedState) + | null; + static metricsReducer: + | ((persistedState: StaticPersistedState) => Promise) | null; - static metricsReducer: ((persistedState: U) => Promise) | null; static exportPersistedState: - | (( - callClient: (string, params: Object | null) => Promise, - persistedState: U | null, - store: MiddlewareAPI | null, - ) => Promise) + | (( + callClient: (method: string, params?: any) => Promise, + persistedState: StaticPersistedState | undefined, + store: MiddlewareAPI | undefined, + ) => Promise) | null; static getActiveNotifications: - | ((persistedState: U) => Array) + | ((persistedState: StaticPersistedState) => Array) | null; static onRegisterDevice: - | (( + | (( store: Store, baseDevice: BaseDevice, setPersistedState: ( pluginKey: string, - newPluginState: U | null, + newPluginState: StaticPersistedState | null, ) => void, ) => void) | null; @@ -114,7 +124,7 @@ export abstract class FlipperBasePlugin< screenshot: never; reducers: { - [actionName: string]: (state: State, actionData: Object) => Partial; + [actionName: string]: (state: State, actionData: any) => Partial; } = {}; app: App; onKeyboardAction: ((action: string) => void) | null;