Summary: Added option to bootstrap device plugin in "flipper-pkg". Changelog: "flipper-pkg init" can now be used to bootstrap device plugins Reviewed By: mweststrate Differential Revision: D26389429 fbshipit-source-id: 90773011bd50289004cd747111e1787402840922
47 lines
1.1 KiB
Plaintext
47 lines
1.1 KiB
Plaintext
import React from 'react';
|
|
import {
|
|
DevicePluginClient,
|
|
usePlugin,
|
|
createState,
|
|
useValue,
|
|
Layout,
|
|
} from 'flipper-plugin';
|
|
|
|
// Read more: https://fbflipper.com/docs/tutorial/js-custom#creating-a-first-plugin
|
|
// API: https://fbflipper.com/docs/extending/flipper-plugin#pluginclient
|
|
export function devicePlugin(client: DevicePluginClient) {
|
|
const data = createState<string[]>([]);
|
|
|
|
client.device.onLogEntry((entry) => {
|
|
data.update((draft) => {
|
|
draft.push(entry.message);
|
|
});
|
|
});
|
|
|
|
client.addMenuEntry({
|
|
action: 'clear',
|
|
handler: async () => {
|
|
data.set([]);
|
|
},
|
|
});
|
|
|
|
return {data};
|
|
}
|
|
|
|
// Read more: https://fbflipper.com/docs/tutorial/js-custom#building-a-user-interface-for-the-plugin
|
|
// API: https://fbflipper.com/docs/extending/flipper-plugin#react-hooks
|
|
export function Component() {
|
|
const instance = usePlugin(devicePlugin);
|
|
const data = useValue(instance.data);
|
|
|
|
return (
|
|
<Layout.ScrollContainer>
|
|
{Object.entries(data).map(([id, d]) => (
|
|
<pre key={id} data-testid={id}>
|
|
{JSON.stringify(d)}
|
|
</pre>
|
|
))}
|
|
</Layout.ScrollContainer>
|
|
);
|
|
}
|