Make sure device plugins show up even when loaded after creating devices

Summary: The device.devicePlugins collection was not updated if new plugins were registered after creating a device. This diff fixes that.

Reviewed By: jknoxville

Differential Revision: D19536777

fbshipit-source-id: 11ed3c3383ae692ce74fd7a21704332fb319b9c4
This commit is contained in:
Michel Weststrate
2020-01-23 08:36:15 -08:00
committed by Facebook Github Bot
parent 032b594221
commit dc60d33b3a
3 changed files with 56 additions and 8 deletions

View File

@@ -27,6 +27,8 @@ import SupportRequestFormV2 from '../fb-stubs/SupportRequestFormV2';
import SupportRequestDetails from '../fb-stubs/SupportRequestDetails';
import {getPluginKey} from '../utils/pluginUtils';
import {deconstructClientId} from '../utils/clientUtils';
import {FlipperDevicePlugin} from '../plugin';
import {RegisterPluginAction} from './plugins';
export type StaticView =
| null
@@ -141,7 +143,8 @@ export type Action =
| {
type: 'SELECT_CLIENT';
payload: string;
};
}
| RegisterPluginAction;
const DEFAULT_PLUGIN = 'DeviceLogs';
const DEFAULT_DEVICE_BLACKLIST = [MacDevice];
@@ -367,6 +370,26 @@ const reducer = (state: State = INITAL_STATE, action: Actions): State => {
};
}
case 'REGISTER_PLUGINS': {
// plugins are registered after creating the base devices, so update them
const plugins = action.payload;
plugins.forEach(plugin => {
if (plugin.prototype instanceof FlipperDevicePlugin) {
// smell: devices are mutable
state.devices.forEach(device => {
// @ts-ignore
if (plugin.supportsDevice(device)) {
device.devicePlugins = [
...(device.devicePlugins || []),
plugin.id,
];
}
});
}
});
return state;
}
default:
return state;
}