Summary: Needed relaxing some types in pluginUtils, but it's actually fine. Reviewed By: danielbuechele Differential Revision: D17072974 fbshipit-source-id: c3d3923ed70f71964aa10cf35f1b9ea2f30a8fa1
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
/**
|
|
* 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 {Store} from '../reducers/index';
|
|
import {FlipperPlugin, FlipperDevicePlugin, FlipperBasePlugin} from '../plugin';
|
|
import {setPluginState} from '../reducers/pluginStates';
|
|
import BaseDevice from '../devices/BaseDevice';
|
|
import {getPersistedState} from '../utils/pluginUtils';
|
|
|
|
export function registerDeviceCallbackOnPlugins(
|
|
store: Store,
|
|
devicePlugins: Map<string, typeof FlipperDevicePlugin>,
|
|
clientPlugins: Map<string, typeof FlipperPlugin>,
|
|
device: BaseDevice,
|
|
) {
|
|
const callRegisterDeviceHook = (plugin: typeof FlipperBasePlugin) => {
|
|
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);
|
|
}
|