/** * 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>>, clientPlugins: Map>>, 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); }