From 6a30899803195764cf9492521d829b093412864f Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Tue, 16 Mar 2021 14:54:53 -0700 Subject: [PATCH] Kill `onRegisterDevice` Summary: `onRegisterDevice` device abstraction was only used by the CrashReporterPlugin, and since with Sandy plugin lifecycles every plugin can do 'on-load' logic, we don't need it anymore. Reviewed By: priteshrnandgaonkar Differential Revision: D27046711 fbshipit-source-id: 16c567c60ed29a50017d525a2b707ee696a99e62 --- desktop/app/src/dispatcher/androidDevice.tsx | 8 --- desktop/app/src/dispatcher/iOSDevice.tsx | 7 --- desktop/app/src/dispatcher/metroDevice.tsx | 8 --- desktop/app/src/plugin.tsx | 10 ---- desktop/app/src/utils/onRegisterDevice.tsx | 52 -------------------- 5 files changed, 85 deletions(-) delete mode 100644 desktop/app/src/utils/onRegisterDevice.tsx diff --git a/desktop/app/src/dispatcher/androidDevice.tsx b/desktop/app/src/dispatcher/androidDevice.tsx index f70a0085f83..718aab77c50 100644 --- a/desktop/app/src/dispatcher/androidDevice.tsx +++ b/desktop/app/src/dispatcher/androidDevice.tsx @@ -13,7 +13,6 @@ import child_process from 'child_process'; import {Store} from '../reducers/index'; import BaseDevice from '../devices/BaseDevice'; import {Logger} from '../fb-interfaces/Logger'; -import {registerDeviceCallbackOnPlugins} from '../utils/onRegisterDevice'; import {getAdbClient} from '../utils/adbClient'; import which from 'which'; import {promisify} from 'util'; @@ -248,13 +247,6 @@ export default (store: Store, logger: Logger) => { type: 'REGISTER_DEVICE', payload: androidDevice, }); - - registerDeviceCallbackOnPlugins( - store, - store.getState().plugins.devicePlugins, - store.getState().plugins.clientPlugins, - androidDevice, - ); } async function unregisterDevices(deviceIds: Array) { diff --git a/desktop/app/src/dispatcher/iOSDevice.tsx b/desktop/app/src/dispatcher/iOSDevice.tsx index fdc0e2fa01a..b66b6d6a7c3 100644 --- a/desktop/app/src/dispatcher/iOSDevice.tsx +++ b/desktop/app/src/dispatcher/iOSDevice.tsx @@ -18,7 +18,6 @@ import child_process from 'child_process'; const execFile = child_process.execFile; import iosUtil from '../utils/iOSContainerUtility'; import IOSDevice from '../devices/IOSDevice'; -import {registerDeviceCallbackOnPlugins} from '../utils/onRegisterDevice'; import {addErrorNotification} from '../reducers/notifications'; import {getStaticPath} from '../utils/pathUtils'; import {destroyDevice} from '../reducers/connections'; @@ -176,12 +175,6 @@ function processDevices( type: 'REGISTER_DEVICE', payload: iOSDevice, }); - registerDeviceCallbackOnPlugins( - store, - store.getState().plugins.devicePlugins, - store.getState().plugins.clientPlugins, - iOSDevice, - ); } } diff --git a/desktop/app/src/dispatcher/metroDevice.tsx b/desktop/app/src/dispatcher/metroDevice.tsx index 8036a119bfe..189da42e3d7 100644 --- a/desktop/app/src/dispatcher/metroDevice.tsx +++ b/desktop/app/src/dispatcher/metroDevice.tsx @@ -9,7 +9,6 @@ import {Store} from '../reducers/index'; import {Logger} from '../fb-interfaces/Logger'; -import {registerDeviceCallbackOnPlugins} from '../utils/onRegisterDevice'; import MetroDevice from '../devices/MetroDevice'; import http from 'http'; import {addErrorNotification} from '../reducers/notifications'; @@ -67,13 +66,6 @@ export async function registerMetroDevice( payload: metroDevice, serial: METRO_URL, }); - - registerDeviceCallbackOnPlugins( - store, - store.getState().plugins.devicePlugins, - store.getState().plugins.clientPlugins, - metroDevice, - ); } export default (store: Store, logger: Logger) => { diff --git a/desktop/app/src/plugin.tsx b/desktop/app/src/plugin.tsx index 8086c0dd93b..d3cd0d1fc82 100644 --- a/desktop/app/src/plugin.tsx +++ b/desktop/app/src/plugin.tsx @@ -128,16 +128,6 @@ export abstract class FlipperBasePlugin< static getActiveNotifications: | ((persistedState: StaticPersistedState) => Array) | undefined; - static onRegisterDevice: - | (( - store: Store, - baseDevice: BaseDevice, - setPersistedState: ( - pluginKey: string, - newPluginState: StaticPersistedState | null, - ) => void, - ) => void) - | null; reducers: { [actionName: string]: (state: State, actionData: any) => Partial; diff --git a/desktop/app/src/utils/onRegisterDevice.tsx b/desktop/app/src/utils/onRegisterDevice.tsx deleted file mode 100644 index 2ac2ba1a42a..00000000000 --- a/desktop/app/src/utils/onRegisterDevice.tsx +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - */ - -import type {Store} from '../reducers/index'; -import type { - ClientPluginMap, - DevicePluginMap, - PluginDefinition, -} from '../plugin'; -import {setPluginState} from '../reducers/pluginStates'; -import type BaseDevice from '../devices/BaseDevice'; -import {getPersistedState, isSandyPlugin} from '../utils/pluginUtils'; - -export function registerDeviceCallbackOnPlugins( - store: Store, - devicePlugins: DevicePluginMap, - clientPlugins: ClientPluginMap, - device: BaseDevice, -) { - const callRegisterDeviceHook = (plugin: PluginDefinition) => { - // This hook is not registered for Sandy plugins, let's see in the future if it is needed - if (!isSandyPlugin(plugin) && plugin.onRegisterDevice) { - plugin.onRegisterDevice( - store, - device, - (pluginKey: string, newPluginState: any) => { - const persistedState = getPersistedState( - pluginKey, - plugin, - store.getState().pluginStates, - ); - if (newPluginState && newPluginState !== persistedState) { - store.dispatch( - setPluginState({ - pluginKey, - state: newPluginState, - }), - ); - } - }, - ); - } - }; - devicePlugins.forEach(callRegisterDeviceHook); - clientPlugins.forEach(callRegisterDeviceHook); -}