Summary: *Stack summary*: this stack refactors plugin management actions to perform them in a dispatcher rather than in the root reducer (store.tsx) as all of these actions has side effects. To do that, we store requested plugin management actions (install/update/uninstall, star/unstar) in a queue which is then handled by pluginManager dispatcher. This dispatcher then dispatches all required state updates. *Diff summary*: refactored Flipper mocking helpers to allow testing of plugin commands, and wrote some tests for pluginManager. Reviewed By: mweststrate Differential Revision: D26450344 fbshipit-source-id: 0e8414517cc1ad353781dffd7ffb4a5f9a815d38
65 lines
1.2 KiB
TypeScript
65 lines
1.2 KiB
TypeScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
import * as React from 'react';
|
|
import {
|
|
DevicePluginClient,
|
|
Device,
|
|
usePlugin,
|
|
createState,
|
|
useValue,
|
|
} from 'flipper-plugin';
|
|
|
|
export function supportsDevice(_device: Device) {
|
|
return true;
|
|
}
|
|
|
|
export function devicePlugin(client: DevicePluginClient) {
|
|
const logStub = jest.fn();
|
|
const activateStub = jest.fn();
|
|
const deactivateStub = jest.fn();
|
|
const destroyStub = jest.fn();
|
|
const state = createState(
|
|
{
|
|
count: 0,
|
|
},
|
|
{
|
|
persist: 'counter',
|
|
},
|
|
);
|
|
|
|
client.device.onLogEntry((entry) => {
|
|
state.update((d) => {
|
|
d.count++;
|
|
});
|
|
logStub(entry);
|
|
});
|
|
client.onActivate(activateStub);
|
|
client.onDeactivate(deactivateStub);
|
|
client.onDestroy(destroyStub);
|
|
|
|
return {
|
|
logStub,
|
|
activateStub,
|
|
deactivateStub,
|
|
destroyStub,
|
|
state,
|
|
};
|
|
}
|
|
|
|
export function Component() {
|
|
const api = usePlugin(devicePlugin);
|
|
const count = useValue(api.state).count;
|
|
|
|
// @ts-expect-error
|
|
api.bla;
|
|
|
|
return <h1>Hi from test plugin {count}</h1>;
|
|
}
|