Summary: * Deletes plugin.js * Adds plugin.tsx * Adds plugin flow-typed module that has the old flow types Reviewed By: passy Differential Revision: D16668067 fbshipit-source-id: b2f0ce47c4cf7125b4e352821e921b97675d12a9
45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
/**
|
|
* Copyright 2018-present Facebook.
|
|
* 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.tsx';
|
|
import {FlipperPlugin, FlipperDevicePlugin} from '../plugin.tsx';
|
|
import type BaseDevice from '../devices/BaseDevice.js';
|
|
import {setPluginState} from '../reducers/pluginStates.tsx';
|
|
import {getPersistedState} from '../utils/pluginUtils.js';
|
|
|
|
export function registerDeviceCallbackOnPlugins(
|
|
store: Store,
|
|
devicePlugins: Map<string, Class<FlipperDevicePlugin<>>>,
|
|
clientPlugins: Map<string, Class<FlipperPlugin<>>>,
|
|
device: BaseDevice,
|
|
) {
|
|
const callRegisterDeviceHook = plugin => {
|
|
if (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);
|
|
}
|