Migrate onRegisterDevice
Summary: _typescript_ Reviewed By: danielbuechele Differential Revision: D16764866 fbshipit-source-id: bdf532dea1c3019f0cb7728b3a0a07a3602cf04b
This commit is contained in:
committed by
Facebook Github Bot
parent
2a34125413
commit
573655c2f6
44
src/utils/onRegisterDevice.tsx
Normal file
44
src/utils/onRegisterDevice.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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} 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 => {
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user