Refactor CrashReporter plugin

Summary: This diff refactors CrashReporter Plugin. The business logic of crash reporter plugin was placed in the `iOSDevice.js` as it gets the hook to the initialisation of iOSDevice. This diff moves the business logic to the Crash Reporter plugin files under the plugins folder. To get the hook, so that we can add our watcher, I have added a static function over `FlipperBasePlugin`, which if exists, will be called once `REGISTER_PLUGIN` event is dispatched

Reviewed By: danielbuechele

Differential Revision: D13529035

fbshipit-source-id: 28216b273b4032727859107d8a6751c6465af9ac
This commit is contained in:
Pritesh Nandgaonkar
2018-12-21 06:58:31 -08:00
committed by Facebook Github Bot
parent 780ac863b8
commit 9d4bb45dbc
8 changed files with 282 additions and 192 deletions

43
src/utils/pluginUtils.js Normal file
View File

@@ -0,0 +1,43 @@
/**
* 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 BaseDevice from '../devices/BaseDevice.js';
import {FlipperDevicePlugin, FlipperPlugin} from '../plugin.js';
import type {State as PluginStatesState} from '../reducers/pluginStates.js';
export function getPluginKey(
selectedApp: ?string,
baseDevice: ?BaseDevice,
pluginID: string,
): string {
if (selectedApp) {
return `${selectedApp}#${pluginID}`;
}
if (baseDevice) {
// If selected App is not defined, then the plugin is a device plugin
return `${baseDevice.serial}#${pluginID}`;
}
return `unknown#${pluginID}`;
}
export function getPersistedState<PersistedState>(
pluginKey: string,
persistingPlugin: ?Class<
| FlipperPlugin<*, *, PersistedState>
| FlipperDevicePlugin<*, *, PersistedState>,
>,
pluginStates: PluginStatesState,
): ?PersistedState {
if (!persistingPlugin) {
return null;
}
const persistedState: PersistedState = {
...persistingPlugin.defaultPersistedState,
...pluginStates[pluginKey],
};
return persistedState;
}