Make sure Sandy plugis can be initialized
Summary:
This diff makes sure sandy plugins are initialized.
Sandy plugins are stored directly in the client for two reasons
1. we want to decouple any plugin state updates from our central redux store, as redux is particularly bad in handling high frequency updates.
2. The lifecycle of a plugin is now bound to the lifecycle of a client. This means that we don't need 'persistedStore' to make sure state is preserved; that is now the default. Switching plugins will no longer reinitialize them (but only run specific hooks, see later diffs).
3. PersistedState will be introduced for sandy plugins as well later, but primarily for import / export / debug reasons.
A significant difference with the current persistent state, is that if a client crashes and reconnects, plugins will loose their state. We can prevent this (again, since state persisting will be reintroduced), but I'm not sure we need that for the specific reconnect scenario. Because
1. we should fix reconnecting clients anyway, and from stats it looks to happen less already
2. reconnects are usually caused by plugins that aggregate a lot of data and get slower over time. Restoring old state also restores those unstabilites.
For the overview bringing back the archi picture of earlier diff:
{F241508042}
Also fixed a bug where enabling background plugins didn't enable them on all devices with that app.
Reviewed By: jknoxville
Differential Revision: D22186276
fbshipit-source-id: 3fd42b577f86920e5280aa8cce1a0bc4d5564ed9
This commit is contained in:
committed by
Facebook GitHub Bot
parent
bf79c9472e
commit
1dc9e899b8
@@ -29,33 +29,28 @@ import Client, {ClientQuery} from '../Client';
|
||||
|
||||
import {buildClientId} from '../utils/clientUtils';
|
||||
import {Logger} from '../fb-interfaces/Logger';
|
||||
import {FlipperPlugin} from '../plugin';
|
||||
import {FlipperPlugin, PluginDefinition} from '../plugin';
|
||||
import {registerPlugins} from '../reducers/plugins';
|
||||
import PluginContainer from '../PluginContainer';
|
||||
|
||||
export function createStubLogger(): Logger {
|
||||
return {
|
||||
...console,
|
||||
track: console.info,
|
||||
trackTimeSince: console.info,
|
||||
};
|
||||
}
|
||||
import {getPluginKey} from '../utils/pluginUtils';
|
||||
import {getInstance} from '../fb-stubs/Logger';
|
||||
|
||||
type MockFlipperResult = {
|
||||
client: Client;
|
||||
device: BaseDevice;
|
||||
store: Store;
|
||||
sendMessage(method: string, params: any): void;
|
||||
pluginKey: string;
|
||||
sendMessage(method: string, params: any, client?: Client): void;
|
||||
createDevice(serial: string): BaseDevice;
|
||||
createClient(device: BaseDevice, name: string): Client;
|
||||
createClient(device: BaseDevice, name: string): Promise<Client>;
|
||||
logger: Logger;
|
||||
};
|
||||
|
||||
export async function createMockFlipperWithPlugin(
|
||||
pluginClazz: typeof FlipperPlugin,
|
||||
pluginClazz: PluginDefinition,
|
||||
): Promise<MockFlipperResult> {
|
||||
const store = createStore(reducers);
|
||||
const logger = createStubLogger();
|
||||
const logger = getInstance();
|
||||
store.dispatch(registerPlugins([pluginClazz]));
|
||||
|
||||
function createDevice(serial: string): BaseDevice {
|
||||
@@ -72,7 +67,10 @@ export async function createMockFlipperWithPlugin(
|
||||
return device;
|
||||
}
|
||||
|
||||
function createClient(device: BaseDevice, name: string): Client {
|
||||
async function createClient(
|
||||
device: BaseDevice,
|
||||
name: string,
|
||||
): Promise<Client> {
|
||||
const query: ClientQuery = {
|
||||
app: name,
|
||||
os: 'Android',
|
||||
@@ -102,6 +100,38 @@ export async function createMockFlipperWithPlugin(
|
||||
return device;
|
||||
},
|
||||
} as any;
|
||||
client.rawCall = async (method, _fromPlugin, _params): Promise<any> => {
|
||||
// TODO: could use an interceptor here
|
||||
switch (method) {
|
||||
case 'getPlugins':
|
||||
// assuming this plugin supports all plugins for now
|
||||
return {
|
||||
plugins: [
|
||||
...store.getState().plugins.clientPlugins.keys(),
|
||||
...store.getState().plugins.devicePlugins.keys(),
|
||||
],
|
||||
};
|
||||
default:
|
||||
throw new Error(`Test client doesn't supoprt rawCall to ${method}`);
|
||||
}
|
||||
};
|
||||
|
||||
// enable the plugin
|
||||
if (
|
||||
!store
|
||||
.getState()
|
||||
.connections.userStarredPlugins[client.query.app]?.includes(
|
||||
pluginClazz.id,
|
||||
)
|
||||
) {
|
||||
store.dispatch(
|
||||
starPlugin({
|
||||
plugin: pluginClazz,
|
||||
selectedApp: client.query.app,
|
||||
}),
|
||||
);
|
||||
}
|
||||
await client.init();
|
||||
|
||||
// As convenience, by default we select the new client, star the plugin, and select it
|
||||
store.dispatch({
|
||||
@@ -112,18 +142,11 @@ export async function createMockFlipperWithPlugin(
|
||||
}
|
||||
|
||||
const device = createDevice('serial');
|
||||
const client = createClient(device, 'TestApp');
|
||||
const client = await createClient(device, 'TestApp');
|
||||
|
||||
store.dispatch(selectDevice(device));
|
||||
store.dispatch(selectClient(client.id));
|
||||
|
||||
store.dispatch(
|
||||
starPlugin({
|
||||
selectedPlugin: pluginClazz.id,
|
||||
selectedApp: client.query.app,
|
||||
}),
|
||||
);
|
||||
|
||||
store.dispatch(
|
||||
selectPlugin({
|
||||
selectedPlugin: pluginClazz.id,
|
||||
@@ -137,8 +160,8 @@ export async function createMockFlipperWithPlugin(
|
||||
client,
|
||||
device: device as any,
|
||||
store,
|
||||
sendMessage(method, params) {
|
||||
client.onMessage(
|
||||
sendMessage(method, params, actualClient = client) {
|
||||
actualClient.onMessage(
|
||||
JSON.stringify({
|
||||
method: 'execute',
|
||||
params: {
|
||||
@@ -152,6 +175,7 @@ export async function createMockFlipperWithPlugin(
|
||||
createDevice,
|
||||
createClient,
|
||||
logger,
|
||||
pluginKey: getPluginKey(client.id, device, pluginClazz.id),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user